Claude Code Cheat Sheet — Every Command, Shortcut, and Hidden Trick (2026)
[01]The Most-Used Commands at a Glance
If you bookmark only one block on this page, make it this one:
| Action | How |
|---|---|
| Initialize project (create CLAUDE.md) | /init |
| Compact conversation context | /compact |
| Clear current session | /clear |
| List custom slash commands | /help |
| Switch model | /model |
| List active MCP servers | /mcp |
| Edit CLAUDE.md from inside session | /memory |
| Run a shell command without leaving Claude | !ls -la |
| Reference a file in the prompt | @src/auth.ts |
| Add a fact to project memory | # API rate limit is 60/min |
| Switch to plan mode | Shift+Tab twice |
| Cancel current operation | Esc |
| Edit a previous message | Esc once |
| Jump to any earlier message | Esc twice |
| Exit Claude Code | /exit or Ctrl+D |
The rest of this guide covers the long tail. For deep dives on specific subsystems see our .claude/ folder guide, hooks guide, and Top 10 MCP servers ranking.
[02]Built-in Slash Commands (Complete List)
Type / in any session to get autocomplete for all of these. Versions ship updates frequently; if a command is missing in yours, run /help to see your version's exact list.
Core Workflow
| Command | Effect |
|---|---|
/help | List all available commands (built-in + custom) |
/clear | Clear current session, start fresh |
/compact [instruction] | Summarize old context to free token budget. Optional instruction guides what to keep. |
/init | Generate a starter CLAUDE.md by scanning the project |
/memory | Open CLAUDE.md (or .claude/CLAUDE.md) in your editor |
/exit | Quit the session |
Configuration
| Command | Effect |
|---|---|
/config | Open the settings UI (theme, model, keybindings) |
/model | Switch model mid-session (Opus / Sonnet / Haiku) |
/permissions | Edit allow/deny lists for tools |
/agents | List, edit, or create custom subagents |
/mcp | List active MCP server connections + their tools |
/hooks | Inspect configured hooks for the current session |
/login / /logout | Switch Anthropic accounts or re-auth |
Session Management
| Command | Effect |
|---|---|
/resume | Pick a previous session to continue |
/cost | Show token usage and estimated cost for current session |
/status | Show current model, mode, working directory |
/doctor | Diagnostics for installation issues |
[03]Keyboard Shortcuts
Most are universal across CLI and IDE extensions. Mac uses Cmd where Ctrl is shown; system shortcuts may override on Windows/Linux.
| Shortcut | Effect |
|---|---|
Esc | Cancel current operation; if input is empty, jump to previous message to edit |
Esc Esc (double-tap) | Open message picker — jump to any earlier message in the conversation |
Tab | Autocomplete file path, command name, or option |
Shift+Tab | Cycle through modes: default → plan → auto-accept → default |
↑ / ↓ | Cycle through prompt history |
Ctrl+R | Toggle verbose output (show full tool input/output) |
Ctrl+C | Cancel currently-running tool; press twice to exit session |
Ctrl+D | Exit session (when input is empty) |
Ctrl+L | Clear screen (terminal only; doesn't clear conversation) |
Ctrl+J | Insert literal newline (vs Enter which submits) |
Alt+Enter / Opt+Enter | Same as Ctrl+J — newline without submit |
Modes explained:
- Default: Claude asks before each tool call that isn't already allowed
- Plan: Claude only reads, never edits. Useful for "let's discuss the approach first"
- Auto-accept: Claude executes everything in
permissions.allowwithout prompting. Use carefully on production code
[04]Special Input Prefixes — !, #, @
Three single-character prefixes change how Claude treats your input. Mostly missed by new users; deeply useful once you know them.
! — Run a shell command
Anything after ! at the start of a prompt runs as a shell command, with the output included in the conversation:
!git log --oneline -5
!find . -name "*.test.ts" | head
The output gets summarized into the conversation context, which Claude can then reason over. Saves the "let me run a command, paste the output, then ask Claude" dance.
# — Add to project memory
Anything after # gets appended to CLAUDE.md as a remembered fact:
# API rate limit is 60 requests per minute
# Production database is read-replica only, writes go to primary at db-writer.internal
Useful for capturing facts in the moment instead of remembering to update CLAUDE.md later.
@ — Reference a file or symbol
@ with autocomplete points Claude at a specific file or symbol:
Refactor @src/auth/login.ts to use the new session API.
What does @validateUser do, and where is it called?
Claude reads the referenced file before responding. Faster than asking "look at src/auth/login.ts" because the path is verified at autocomplete time.
[05]CLI Flags & Launch Options
Run claude --help for the canonical list. The flags worth memorizing:
| Flag | Effect |
|---|---|
claude | Start interactive session in current directory |
claude -p "<prompt>" | Print mode: run prompt non-interactively, output to stdout, exit. Pipe-friendly. |
claude --resume | Pick a previous session from a list |
claude --continue | Continue the most recent session in this directory |
claude --add-dir <path> | Add another directory to Claude's working set (without changing cwd) |
claude --model <name> | Override default model (e.g. claude-opus-4-5) |
claude --permission-mode <mode> | Set permission mode at startup: default, plan, acceptEdits, bypassPermissions |
claude --output-format json | (Print mode) emit JSON instead of plain text. Good for scripting. |
claude --include-partial-messages | (Print mode) include intermediate tool calls in output |
claude mcp add <name> -- <cmd> | Register a new MCP server |
claude mcp list / get / remove | Manage MCP servers without an editor |
claude doctor | Diagnose installation, IDE integration, and connectivity |
claude config get/set/list | Manage settings.json from CLI |
Print mode pipeline trick
cat error.log | claude -p "summarize the most common error patterns" --output-format json | jq
Pipe-friendly print mode turns Claude into a proper Unix tool. Combine with find, grep, jq, awk for serious power.
[06]Configuration File Locations
Where everything lives. Hierarchy goes from most-global to most-specific; later files override earlier:
| Path | Purpose |
|---|---|
~/.claude/settings.json | Global user settings (apply to all projects) |
~/.claude/CLAUDE.md | Global standing instructions |
~/.claude.json | Account state, MCP server registrations, oauth tokens |
~/.claude/agents/ | Global subagents (available to all projects) |
~/.claude/commands/ | Global slash commands |
./CLAUDE.md | Project standing instructions (committed to Git) |
./.claude/settings.json | Project settings (committed) |
./.claude/settings.local.json | Personal overrides (gitignored) |
./.claude/agents/ | Project subagents (committed) |
./.claude/commands/ | Project slash commands (committed) |
./.mcp.json | Project-scoped MCP servers (committed via --scope project) |
[07]Power User Tips
Eight tricks that separate confident users from beginners.
1. Compact with intent
/compact alone summarizes generically. /compact keep the file paths and the failed test names tells the summarizer what matters. Massive context recovery for long sessions.
2. Use Esc-Esc to fork the conversation
Realized 20 messages ago you should have asked differently? Esc Esc opens a message picker; pick the message, edit it, and Claude continues from that branch. The original branch is preserved.
3. Symlink CLAUDE.md to share across siblings
If you have multiple repos that should share standing instructions:
ln -s /shared/CLAUDE.md ~/work/repo-a/CLAUDE.md
ln -s /shared/CLAUDE.md ~/work/repo-b/CLAUDE.md
Edit once, applies everywhere.
4. Pipe Claude's output to another command
Print mode + --output-format json + jq = serious automation:
claude -p "list all TODO comments in src/" --output-format json | jq -r '.text'
5. Background long tasks with run_in_background
Inside a session, ask Claude to run a long-running task with run_in_background. Useful for builds and tests that would otherwise block the conversation.
6. Use --add-dir for monorepo workflows
If you need Claude to also see ~/code/shared-lib while working in ~/code/main-app, launch with claude --add-dir ~/code/shared-lib. Or run /add-dir mid-session.
7. Status line for git branch
Add to settings.json:
{
"statusLine": {
"type": "command",
"command": "echo $(git branch --show-current 2>/dev/null) | tr -d '\n'"
}
}
Now the bottom of Claude Code always shows your branch. Catches "I'm committing on main" before it happens.
8. Keep a global ~/.claude/CLAUDE.md for personal preferences
Things like "be concise", "don't add comments unless I ask", "use TypeScript strict mode" belong in your global CLAUDE.md. Project CLAUDE.md adds project-specific stuff on top.
[08]Frequently Asked Questions
How do I see which keybindings are bound?
Run /config and navigate to the keybindings section. You can also check ~/.claude/keybindings.json directly.
What's the fastest way to undo a wrong edit Claude made?
Three options: (1) git checkout -- <file> if the change isn't committed; (2) git reset HEAD~1 if it's committed but not pushed; (3) Esc Esc to fork the conversation before the bad edit and try a different approach.
Can I run Claude Code in a sandbox?
Yes. Use --permission-mode plan for strict read-only, or run inside a Docker container with limited filesystem access. Claude Code respects permissions.deny patterns even with broad allow lists.
How do I share a slash command with someone outside my repo?
The slash command file is just Markdown. Send them .claude/commands/foo.md and ask them to drop it in their ~/.claude/commands/ (global) or their project's .claude/commands/.
Why doesn't /init generate everything I need in CLAUDE.md?
It generates a starter based on what it finds. Treat the output as a draft — review and trim. The good CLAUDE.md is what you keep after deleting half of what /init wrote.
How do I use Claude Code in CI without an interactive prompt?
Print mode: claude -p "<prompt>". Combined with --output-format json and --max-turns N, it's scriptable. Set ANTHROPIC_API_KEY in your CI environment.
Where do I report a bug or request a feature?
github.com/anthropics/claude-code/issues is the canonical issue tracker. Search before filing — many issues are duplicates.
Related: .claude/ folder complete guide · Hooks practical guide · Top 10 MCP servers