Cheat Sheet: Keyboard Shortcuts & CLI Flags
The keys and flags you'll use every day
- Recall the core in-session shortcuts — mode cycling, interrupt, rewind, transcript, history search, task list, background, paste-image, and the model/thinking toggles — and what each does
- Insert a newline correctly in any terminal, and run /terminal-setup when Shift+Enter isn't native
- Configure macOS Option-as-Meta in iTerm2, Terminal.app, and the VS Code terminal so Alt/Option shortcuts actually fire
- Use the ! shell-mode prefix and the # auto-memory prefix from the prompt
- Look up the core and scripting CLI flags (-p, -c, -r, --model, --effort, --permission-mode, --max-budget-usd, --json-schema, and more) with exact syntax
A scannable, bookmark-it reference of every Claude Code keyboard shortcut and the CLI flags you'll reach for most — grouped for fast lookup, with the macOS Option-as-Meta setup that trips everyone up spelled out.
- 1The mental model: two keyboards, two surfaces
- 2Keyboard shortcuts (in-session)
- 3Newlines & the prompt prefixes
- 4macOS Option-as-Meta setup (the gotcha)
- 5Core CLI flags (launching & resuming)
- 6Scripting & headless flags
The mental model: two keyboards, two surfaces
Claude Code is driven from two places, and this whole cheat sheet splits along that line.
- Keyboard shortcuts live inside a running session. They change how you steer Claude mid-flight: switch permission modes, interrupt, rewind to a checkpoint, search history, peek at the transcript. You press them at the prompt.
- CLI flags live outside a session — on the
claudecommand you type in your shell to start one. They decide what kind of session you get: which model, which permission mode, headless or interactive, scripted with a budget, or resumed from before.
So there are really two questions this page answers fast: "I'm in a session — what key does the thing?" and "I'm launching — what flag sets it up?" Skim to the right table and copy the exact form.
One setup detail gates a chunk of the shortcuts on macOS: many of them use Alt/Option as a Meta key, and macOS terminals don't treat Option that way out of the box. If your Option+P or Option+T does nothing, you haven't broken anything — you just need the Option-as-Meta setup below. Do that once and the whole Alt/Option row lights up.
The content here is the verbatim reference from the official interactive-mode and CLI docs. Bookmark it; you'll come back.
Key insight
In-session = keys, launch-time = flags
Keyboard shortcuts act on a session that's already running. CLI flags act on the claude command before a session exists. When you're stuck, ask which side you're on — that tells you which half of this sheet to scan.
Keyboard shortcuts (in-session)
These work at the prompt inside a running session. The ones in the Alt/Option family need the macOS Option-as-Meta setup first.
| Shortcut | Action |
|---|---|
| Shift+Tab | Cycle permission modes (default → acceptEdits → plan; auto/bypass if enabled). Alt+M on some configs |
| Esc | Interrupt Claude immediately — preserves the work done so far |
| Esc Esc (on an empty prompt) | Open the rewind menu: restore code/conversation to a checkpoint, or summarize |
| Ctrl+G (or Ctrl+X Ctrl+E) | Open the prompt/plan in your external text editor — edit the plan before approving it |
| Ctrl+O | Toggle the transcript viewer (detailed tool/MCP calls) |
| Ctrl+R | Reverse-search command history (Ctrl+S changes scope session/project/all; Tab accepts and edits; Enter runs) |
| Ctrl+T | Toggle the multi-step task list (persists across compactions) |
| Ctrl+B | Background the current bash command / session |
| Ctrl+V (Win/Linux), Cmd+V (macOS/iTerm2), Alt+V (WSL) | Paste an image as [Image #N] |
| Option+P (macOS) / Alt+P (Win/Linux) | Switch model mid-session without clearing your prompt |
| Option+T (macOS) / Alt+T | Toggle extended thinking (v2.1.132+) |
The two you'll wear out first are Esc and Esc Esc. Esc is your steering wheel — interrupt the moment Claude heads the wrong way, type a correction, and it picks up from there without a restart. Esc Esc is your undo — every user prompt and every file edit is checkpointed, so you can rewind code, conversation, or both.
Tip
Esc to steer, Esc Esc to rewind
Don't wait for Claude to finish a wrong turn. Press Esc to interrupt (it keeps the work already done), type your correction, and continue. If you need to go further back, Esc Esc on an empty prompt opens the rewind menu — Restore reverts file state to a checkpoint, Summarize compresses without touching files.
Note
Ctrl+G edits the plan before you approve it
In plan mode, Claude drafts a plan and waits. Ctrl+G (or Ctrl+X Ctrl+E) opens that plan in your $EDITOR so you can tighten it — add a constraint, delete a step — before you hand control back and let Claude implement.
Newlines & the prompt prefixes
Inserting a newline (a multi-line prompt without submitting) depends on your terminal. Pick the row that works for you:
| Keys | When to use |
|---|---|
| Shift+Enter | Native on iTerm2, WezTerm, Ghostty, Kitty, Warp, Terminal.app, Windows Terminal |
Backslash + Enter (\ then Enter) | Works in any terminal — the universal fallback |
| Option+Enter / Ctrl+J | macOS, once the Meta key is configured |
If Shift+Enter doesn't make a newline in your terminal, run /terminal-setup inside Claude Code — it configures the terminal so the native binding works.
Two prompt prefixes change how a line is interpreted, and they only fire at the start of the line:
| Prefix | What it does |
|---|---|
! (shell mode) | Run the command directly in your shell. The output is added to context, but Claude does not interpret or act on it — no agentic loop, no verification trigger |
# (memory) | Add the note to auto memory (MEMORY.md) so it persists across sessions |
Use ! when you want a fact in front of Claude without asking it to do anything — !git status, !ls -la, !cat package.json. The output lands in context for the next thing you ask. Use # to jot a durable note — # we deploy from the release branch, never main — which gets written to your project's auto-memory file.
Tip
Backslash+Enter always works
If you're on an unfamiliar machine or a terminal you can't configure, type \ then Enter to get a newline. It needs zero setup. Save /terminal-setup for your own daily terminal where you want native Shift+Enter.
Watch out
`!` adds output but doesn't trigger action
Shell mode just runs the command and drops the output into context — Claude won't analyze it or react. If you want Claude to do something with the result, follow up with an explicit ask ("given that test output, fix the failing case").
macOS Option-as-Meta setup (the gotcha)
On macOS, the Option key normally types special characters (Option+P gives π, not a Meta keystroke). Claude Code's Alt/Option shortcuts — Option+P (switch model), Option+T (thinking), Option+Enter (newline), and the readline keys Alt+B/Alt+F/Alt+Y/Alt+M — need Option to act as a Meta key. Until you flip this setting, those shortcuts silently do nothing. This is the single most common "why doesn't this shortcut work?" on macOS.
Configure it once per terminal:
| Terminal | Where to set it |
|---|---|
| iTerm2 | Settings → Profiles → Keys → set the Left/Right Option key to Esc+ (Meta) |
| Terminal.app | Settings → Profiles → Keyboard → enable Use Option as Meta key |
| VS Code integrated terminal | Set "terminal.integrated.macOptionIsMeta": true in settings.json |
That VS Code key, in your settings.json:
{
"terminal.integrated.macOptionIsMeta": true
}After setting it, restart the terminal (or open a new tab) and try Option+P — the model switcher should appear. If it still types a special character, you edited the wrong profile or the wrong settings scope.
Watch out
No setup → every Alt/Option shortcut fails
Without Option-as-Meta, Alt+B/F/Y/M/P and Option+P/Option+T simply don't register, and Option+Enter won't make a newline. People assume the feature is broken or missing. It isn't — flip the setting in your terminal's profile and the whole row comes alive.
Core CLI flags (launching & resuming)
These shape an everyday claude invocation — the session you start by hand.
| Flag | Syntax | Meaning |
|---|---|---|
-p / --print | claude -p "fix the login bug" | Headless: run non-interactively via the SDK, print the result, exit |
-c / --continue | claude -c | Resume the most recent conversation in this directory |
-r / --resume | claude -r "<id-or-name>" | Resume a specific session by ID or name; no arg opens a picker |
--fork-session | claude --resume abc123 --fork-session | On resume, start a new session ID instead of reusing the original |
-n / --name | claude -n "my-feature" | Set the session's display name |
--model | claude --model opus | Model for the session — opus, sonnet, or a full ID like claude-sonnet-4-6 (overrides settings) |
--effort | claude --effort high | Reasoning effort: low / medium / high / xhigh / max (availability varies by model) |
--permission-mode | claude --permission-mode plan | Start in a mode: default / acceptEdits / plan / auto / dontAsk / bypassPermissions |
--add-dir | claude --add-dir ../apps ../lib | Grant file access to extra directories (does not discover their .claude/) |
-w / --worktree | claude -w feature-auth | Run in an isolated git worktree at <repo>/.claude/worktrees/<name>; pass #<PR> to branch from a PR |
The trio you'll lean on daily: -p for one-shot headless answers (great in pipes — tail -200 app.log | claude -p "find anomalies"), -c to jump straight back into your last conversation here, and -r to pick a specific older one. Add --fork-session when you want to branch off an old session without disturbing it.
Tip
-c picks the latest, -r picks a specific one
claude -c (or --continue) silently resumes the most recent conversation in the current directory — fastest way back to where you were. claude -r (or --resume) takes an ID or name, or opens a picker if you give no argument. Combine -r with --fork-session to explore a branch off an old session while leaving the original intact.
Note
--add-dir grants access, not discovery
--add-dir ../lib lets Claude read and edit files in that directory, but it does not load that directory's .claude/ config or CLAUDE.md. For an isolated branch with its own working tree, reach for -w/--worktree instead.
Scripting & headless flags
These pair with -p to make Claude safe and predictable inside scripts, CI, and automation — bounded spend, structured output, and a controlled prompt.
| Flag | Syntax | Meaning |
|---|---|---|
--max-budget-usd | claude -p --max-budget-usd 5.00 "q" | Stop when spend reaches this USD amount (print mode) |
--max-turns | claude -p --max-turns 3 "q" | Cap the number of agentic turns; errors when the limit is hit |
--json-schema | claude -p --json-schema '{...}' "q" | Force output to validated JSON matching your schema (print mode) |
--output-format | --output-format json (or stream-json) | Choose a machine-parseable output format |
--allowedTools | claude --allowedTools "Bash(git log *)" "Read" | Tools that run without a prompt (permission-rule syntax) |
--append-system-prompt | claude --append-system-prompt "..." | Append to the default system prompt — safe, keeps tool guidance + guardrails |
--bare | claude --bare -p "q" | Minimal mode: skip hooks/skills/plugins/MCP/auto-memory/CLAUDE.md; only Bash/Read/Edit |
--verbose | claude --verbose | Full turn-by-turn output (overrides viewMode) |
--debug | claude --debug "api,hooks" | Debug with a category filter (! excludes, e.g. "!statsig") |
The golden rule for any unattended run is scope it three ways: cap spend with --max-budget-usd, cap iterations with --max-turns, and whitelist exactly what may run unprompted with --allowedTools. For structured pipelines, --json-schema plus --output-format json gives you output you can pipe into jq.
And for system-prompt edits, always prefer --append-system-prompt over replacing the whole prompt — appending keeps Claude's built-in tool knowledge and safety guidance, where a full replacement (--system-prompt) throws them away.
Watch out
Append, never replace, the system prompt
--append-system-prompt "..." adds your instructions on top of the default. The replacement variant --system-prompt wipes the default entirely — losing tool guidance and safety guardrails. Unless you have a very specific reason, append.
Example
A safely-bounded headless run
claude -p \
--max-budget-usd 2.00 \
--max-turns 4 \
--allowedTools "Read" "Bash(npm test *)" \
--output-format json \
"run the test suite and report which tests fail"Budget-capped, turn-capped, tool-whitelisted, and emitting JSON you can parse — the template for CI and cron jobs.
Try it: Wire up the keys and bound a headless run
Do this in any project directory. Goal: make every shortcut on this sheet actually work, then prove you can launch a safely-scoped session.
- Fix Option-as-Meta (macOS). Open your terminal's profile and enable Option-as-Meta — iTerm2 (Settings → Profiles → Keys → Option = Esc+), Terminal.app (Profiles → Keyboard → Use Option as Meta), or VS Code (
"terminal.integrated.macOptionIsMeta": true). Restart the terminal, then press Option+P in a session and confirm the model switcher appears. (On Windows/Linux, just confirmAlt+Pworks.) - Newlines. Try Shift+Enter — if it doesn't make a newline, run
/terminal-setupand try again. Then confirm the universal fallback Backslash+Enter works. - Steer and rewind. Ask Claude to make a small multi-step change. Halfway through, press Esc, type a correction, and watch it continue. Then on an empty prompt press Esc Esc and explore the rewind menu (Restore vs Summarize).
- The Ctrl row. Try Ctrl+O (transcript), Ctrl+R (history search — type a few letters,
Enterto run), and Ctrl+T (task list). Note what each reveals. - Prompt prefixes. Type
!git statusand confirm the output lands in context without Claude acting on it. Then type# this project deploys from the release branchand verify it via/memory. - Bound a headless run. From your shell, launch:
claude -p \
--max-budget-usd 1.00 \
--max-turns 3 \
--allowedTools "Read" "Bash(git log *)" \
--output-format json \
"summarize the last five commits"Confirm it returns JSON and respects the caps.
Deliverable: a short note recording which terminal you configured for Option-as-Meta, whether you needed /terminal-setup, and the JSON your bounded claude -p run produced.
Key takeaways
- 1Keyboard shortcuts steer a running session; CLI flags configure the session you launch. Two surfaces, two halves of this sheet.
- 2The everyday shortcuts: Shift+Tab cycles modes, Esc interrupts, Esc Esc rewinds, Ctrl+G edits the plan, Ctrl+O shows the transcript, Ctrl+R searches history, Ctrl+T toggles the task list, Ctrl+B backgrounds, Option+P switches model, Option+T toggles thinking.
- 3For a newline: Shift+Enter on native terminals, Backslash+Enter anywhere, Option+Enter/Ctrl+J with Meta; run /terminal-setup if Shift+Enter doesn't work.
- 4On macOS, Alt/Option shortcuts fail until you enable Option-as-Meta: iTerm2 Keys → Esc+, Terminal.app Keyboard → Use Option as Meta, VS Code terminal.integrated.macOptionIsMeta: true.
- 5Prompt prefixes: `!` runs a shell command and adds its output to context (no action); `#` saves a note to auto memory.
- 6Core flags -p/-c/-r/--fork-session/--model/--effort/--permission-mode launch and resume; scripting flags --max-budget-usd/--max-turns/--allowedTools/--json-schema/--append-system-prompt make headless runs safe and structured.
Quiz
Lock in what you learned
Check your understanding
0 / 4 answered
1.On a stock macOS install you press Option+P expecting the model switcher, but it just types a special character. What's the fix?
2.Claude is halfway through an edit and clearly heading the wrong direction. What's the recommended way to redirect it?
3.You're writing a cron job that runs `claude -p` unattended and you must keep it from burning budget or running dangerous commands. Which combination does that?
4.At the prompt you type `!npm test` (with the leading bang). What happens?
Go deeper
Hand-picked sources to keep learning
The authoritative shortcut table, newline bindings, the macOS Option-as-Meta setup, and /terminal-setup.
Every flag in this lesson with exact syntax — core, model/permission, scripting, workspace, and remote.
What --permission-mode and Shift+Tab cycle through: default, acceptEdits, plan, auto, dontAsk, bypassPermissions.
How Esc Esc / /rewind work — what's snapshotted, Restore vs Summarize, and the 30-day cleanup.
A community quick-reference covering shortcuts and flags — handy as a second printable.
Changelog and issues — confirm when a shortcut or flag was added or changed (e.g. Option+T thinking in v2.1.132+).