Skip to content

Instantly share code, notes, and snippets.

@alxn
Created March 7, 2026 20:11
Show Gist options
  • Select an option

  • Save alxn/d9fcc7781f4168d24b0ef4906ac955bc to your computer and use it in GitHub Desktop.

Select an option

Save alxn/d9fcc7781f4168d24b0ef4906ac955bc to your computer and use it in GitHub Desktop.

Claude Code Cheat Sheet

Everything you need in one place β€” Commands, Shortcuts, Features & Tips

2026 EDITION


⌨️ Keyboard Shortcuts

Essential

Key Action
Enter Send message / submit
Esc Interrupt / stop generation
Esc Esc Open rewind menu (go back in conversation or code)
Ctrl+C Cancel current operation (hard stop)
Ctrl+D Exit Claude Code
Shift+Tab Cycle modes: Normal β†’ Auto-Accept β†’ Plan

Navigation

Key Action
Ctrl+R Search command history
Ctrl+T Toggle task list
Ctrl+O Toggle verbose transcript
Ctrl+G Open external editor (write long prompts)
Ctrl+V Paste image (screenshots, diagrams)
Ctrl+S Stash current prompt (save for later)
Cmd+P / Meta+P Open model picker (switch models quick)
Cmd+T / Meta+T Toggle extended thinking

Editing (Bash-style)

Key Action
Ctrl+A / Ctrl+E Start / end of line
Opt+F / Opt+B Word forward / back
Ctrl+W Delete previous word
\ + Enter New line (without sending)

Background Tasks

Key Action
Ctrl+B Send running task to background

πŸ’‘ Tip: Run /terminal-setup to enable Shift+Enter for multi-line input in iTerm2 & VS Code. Run /keybindings to customize all shortcuts.


⚑ Slash Commands

Session Control

Command Action
/clear Reset conversation history (fresh start)
/compact [hint] Compress context to save tokens. Optional hint for what to keep.
/rewind Go back in conversation AND/OR code changes
/export [file] Export conversation to file or clipboard
/cost Show session cost & token usage
/usage Show plan usage & rate limits
/context Token consumption visualization

Configuration

Command Action
/config Open settings panel
/model Switch between Sonnet / Opus / Haiku
/permissions View & update tool permissions
/keybindings Open keyboard shortcuts config file
/vim Toggle vim mode for input
/terminal-setup Setup Shift+Enter for multi-line input

Development

Command Action
/init Create CLAUDE.md for your project β€” do this first!
/memory View & edit CLAUDE.md project memory
/review Code review analysis
/doctor Environment diagnostics & health check
/agents Manage sub-agents
/mcp Manage MCP servers

Advanced

Command Action
/insights Generate HTML usage report πŸ†•
/pr_comments View GitHub PR feedback
/install-github-app Setup automated PR reviews
/tasks Persistent task list management
/teleport Transfer session between web ↔ local

πŸš€ CLI Launch Flags

Starting Sessions

Flag Action
claude Start interactive session
claude "query" Start with an initial prompt
claude -p "query" Print mode β€” answer & exit (for scripting)
claude -c Continue last conversation
claude -r "name" Resume specific session by name or ID
claude -w name Start in isolated git worktree

Model & Behavior

Flag Action
--model sonnet Use Sonnet (fast, cheap)
--model opus Use Opus (smartest)
--agent my-agent Use a specific sub-agent
--permission-mode plan Start in plan mode
--max-turns N Limit conversation turns
--max-budget-usd N Set max spend limit

Context & Directories

Flag Action
--add-dir ../path Add extra directories to context
--chrome Enable browser integration
--verbose Show detailed logging

Permissions

Flag Action
--allowedTools Whitelist specific tools
--disallowedTools Block specific tools
--tools "Bash,Edit" Restrict to only these tools

Output Formats (for -p mode)

Flag Action
--output-format text Plain text (default)
--output-format json Structured JSON
--output-format stream-json Real-time streaming JSON

πŸ’‘ Tip: Pipe data in! git diff | claude -p "review this" or cat error.log | claude -p "explain"


🧩 The Big 5 β€” Claude Code Extension System

1. CLAUDE.md β€” Project Memory

What A markdown file Claude reads every session. Your project's "brain dump" β€” coding style, architecture, common commands, conventions.
Where .claude/CLAUDE.md (project) or ~/.claude/CLAUDE.md (global)
Create Run /init in your project β€” Claude generates it for you

2. Custom Slash Commands

What Your own /commands. Markdown files with prompts that YOU invoke. Like prompt templates.
Where .claude/commands/ (project) or ~/.claude/commands/ (global)
Use Filename = command name. review.md β†’ type /project:review

3. Skills β€” Auto-Invoked Knowledge

What Like commands, but Claude decides when to use them automatically. You DON'T invoke them β€” Claude detects when they're relevant.
Where .claude/skills/ with a SKILL.md inside each skill folder
Use Just work on your project β€” Claude picks up relevant skills from context

4. Sub-Agents β€” Specialized Helpers

What Separate Claude instances with their own context & role. Like team members: reviewer, debugger, architect, etc.
Where .claude/agents/ (markdown files with YAML metadata)
Invoke /agents to manage, or just say "Use the reviewer agent"
CLI --agent my-agent or --agents '{json}'

5. MCP Servers β€” External Tool Connections

What Connect Claude to external tools: GitHub, Notion, databases, APIs, browsers, etc.
Setup claude mcp add <name> <command>
List claude mcp list
Config --mcp-config ./mcp.json at launch

+ Plugins β€” Community Extensions

What Bundles of commands, skills, hooks & more from the community
Browse /plugin to browse, install, enable, disable
Dir --plugin-dir ./my-plugins for local plugins

How they differ:

Custom Commands β†’ YOU invoke them vs Skills β†’ CLAUDE invokes them vs Sub-Agents β†’ Separate AI instances vs MCP β†’ External tool connections


πŸ”„ Permission Modes

Mode Description
Normal Claude asks permission for every tool use (read, write, bash, etc.)
Auto-Accept Claude runs tools WITHOUT asking. Faster but less control. Good for trusted tasks.
Plan Mode Claude ONLY reads & plans. Won't write or run anything. Review first, then switch to Normal to execute.

Cycle: Shift+Tab β†’ Normal β†’ Auto-Accept β†’ Plan β†’ Normal...

πŸ’‘ Best workflow: Start in Plan Mode to explore & understand the problem. Review Claude's plan. Switch to Normal/Auto-Accept to implement.


πŸͺ Hooks β€” Event Automation

Hook Description
PreToolUse Runs BEFORE Claude uses a tool β€” validate, block, or modify
PostToolUse Runs AFTER a tool β€” check results, auto-format, lint
UserPromptSubmit Before your message is processed
Stop When Claude finishes its response
SessionStart When a session begins
SessionEnd When a session ends
PreCompact Before context compression
Notification When Claude sends a notification

πŸ’‘ Example: Auto-run prettier after every file edit, or block writes to .env files. Configure in your settings JSON.


✨ Input Superpowers

Feature Description
@ mention Type @ to reference files & folders. Claude reads them into context.
! prefix Type ! to run shell commands inline. E.g., ! git status
Paste images Ctrl+V to paste screenshots, diagrams, error images directly
Pipe input cat file.py | claude -p "explain" β€” feed data directly
Multi-dir claude --add-dir ../api ../web β€” work across multiple projects
Worktrees claude -w feature β€” isolated git branch + Claude session

⚠️ Pro tip: Use @ references instead of copy-pasting file contents. It's smarter with context and uses fewer tokens.


βš™οΈ Configuration

Settings Priority (highest β†’ lowest)

Level Location
Enterprise /etc/claude-code/managed-settings.json
Project Local .claude/settings.local.json (your personal project settings)
Project Shared .claude/settings.json (committed to git, shared with team)
User Global ~/.claude/settings.json (your defaults)

Config CLI

Command Action
claude config list Show all settings
claude config get key Check a value
claude config set key value Change a value
claude config add key value Add to array

πŸ’‘ Permissions example: Allow git commands without asking: add "Bash(git:*)" to your allowedTools in settings.


πŸ“ File Structure Map

Project Level (.claude/)

File/Dir Purpose
CLAUDE.md Project memory β€” conventions, architecture, commands
settings.json Shared project settings (committed to git)
settings.local.json Your personal settings (gitignored)
commands/ Project slash commands (*.md files)
skills/ Project skills (folders with SKILL.md)
agents/ Project sub-agents (*.md files)

Global Level (~/.claude/)

File/Dir Purpose
CLAUDE.md Global memory (applies to ALL projects)
settings.json Global settings
commands/ Personal global commands
skills/ Personal global skills
keybindings.json Custom keyboard shortcuts

βͺ Rewind & Checkpoints

Key/Command Action
Esc Esc Open rewind menu anywhere
/rewind Same but typed as command

Rewind Options

Option Description
Conversation Go back in chat only. Code stays as-is.
Code Restore files only. Conversation stays.
Full Rewind Restore both conversation AND code to a point.

⚠️ Note: Bash side-effects (database changes, API calls, deleted files via rm) can't be rewound. Checkpoints only track file edits by Claude. Use Git for permanent safety.


🎯 Pro Workflow β€” How to Get the Best Out of Claude Code

Starting a New Project

cd project && claude β†’ /init β†’ Edit CLAUDE.md β†’ Code!

The Plan β†’ Execute Pattern

Shift+Tab β†’ Plan Mode β†’ Describe what you want β†’ Review Claude's plan β†’ Shift+Tab β†’ Normal/Auto β†’ Execute

Saving Money

Strategy Why
Use /compact When context gets big, compress it. Saves tokens dramatically.
Use /clear Between unrelated tasks. Don't carry irrelevant context.
Use Sonnet For routine tasks. Save Opus for complex architecture decisions.
Use @ refs Instead of pasting code β€” smarter context management.

Debugging Like a Pro

Strategy Why
Paste errors Copy-paste the full error message. Claude parses stack traces brilliantly.
Paste screenshots Ctrl+V a screenshot of the bug. Claude sees it.
Pipe logs cat error.log | claude -p "what's wrong?"
/doctor If something feels broken, run this first.

Parallel Development

Strategy How
Worktrees claude -w feature-auth β€” isolated branch + session
Multiple dirs --add-dir ../api ../web β€” work across repos
Background Ctrl+B sends a task to background so you can start another
Agent Teams Multiple Claude instances collaborating (experimental) πŸ†•

πŸ› οΈ Create Custom Commands

Step Action
1. Create file .claude/commands/review.md
2. Write prompt The markdown content IS the prompt Claude will use
3. Use it Type /project:review in Claude Code

Optional YAML Frontmatter

Key Purpose
argument-hint Placeholder text for argument input
description Shows in /help listing
allowed-tools Restrict what tools the command can use
model Force a specific model for this command

Variable: $ARGUMENTS

Use $ARGUMENTS in your markdown β€” it gets replaced with whatever you type after the command.

πŸ’‘ Example: /project:review src/auth.ts β†’ $ARGUMENTS = "src/auth.ts"


πŸ“‹ Quick Reference β€” Most Used Combos

Daily Essentials

What How
Start project cd project && claude
Continue where I left off claude -c
Quick question, no session claude -p "how do I..."
Review my changes git diff | claude -p "review"
Explain error cat error.log | claude -p "explain"
Check cost Type /cost anytime
Undo mistake Esc Esc β†’ rewind

Power Moves

What How
Parallel sessions claude -w feature-a + claude -w feature-b
Custom reviewer agent Create .claude/agents/reviewer.md
Auto-format on edit PostToolUse hook β†’ run prettier
Web session claude --remote "fix the bug"
Transfer to local claude --teleport
Budget limit claude -p --max-budget-usd 2 "query"
Scripted automation claude -p --output-format json "query" | jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment