Claude Code Cheatsheet
Quick reference for Claude Code in the terminal: session flags, print mode for scripts, slash commands, keyboard shortcuts, permission rules, MCP servers, hooks, and config file locations.
Claude Code works as an interactive agent in your terminal, but much of what it can do sits behind flags, slash commands, and keyboard shortcuts that are easy to forget between sessions. This cheatsheet collects the ones you reach for daily, from resuming a conversation and scripting with print mode to permission rules, MCP servers, and the files where settings and project instructions live.
Start and Resume Sessions
Launch options for the interactive session. Flags and commands on this page match Claude Code 2.1.302.
| Command | Description |
|---|---|
claude | Start an interactive session in the current directory |
claude "explain this project" | Start a session with a first prompt |
claude -c | Continue the most recent conversation in this directory |
claude -r | Open the session picker |
claude -r SESSION_ID | Resume a specific conversation |
claude -c --fork-session | Continue under a new session ID, keeping the original intact |
claude -n "auth refactor" | Name the session for the prompt bar and the /resume picker |
claude --from-pr 123 | Resume the session linked to a pull request |
claude -w feature-x | Start in a new git worktree named feature-x |
claude --add-dir ../shared | Allow file access to another directory |
claude --model opus | Pick the model by alias, such as opus or sonnet, or by full name |
claude --effort high | Set the effort level: low, medium, high, xhigh, or max |
Print Mode for Scripts
-p runs a single prompt, prints the answer, and exits, which makes Claude Code usable in pipes and CI jobs.
| Command | Description |
|---|---|
claude -p "summarize README.md" | Print the response and exit |
cat error.log | claude -p "explain this error" | Send piped input along with the prompt |
claude -c -p "now add tests" | Continue the last conversation without opening the interface |
claude -p "..." --output-format json | Return the result as a single JSON object |
claude -p "..." --output-format stream-json --verbose | Stream events as they arrive |
claude -p "..." --json-schema '{...}' | Validate structured output against a JSON Schema |
claude -p "..." --max-budget-usd 2 | Stop when estimated API spend reaches $2; final spend may exceed this |
claude -p "..." --allowedTools "Bash(npm test *)" Read | Pre-approve the tools the job needs |
claude -p "..." --append-system-prompt "..." | Add instructions to the default system prompt |
claude -p "..." --no-session-persistence | Do not save the session to disk |
Print mode skips the workspace trust dialog, so run it only in directories you trust.
Session and Context Commands
Slash commands that manage the conversation itself. Type / to see everything available, including skills and plugin commands.
| Command | Description |
|---|---|
/clear | Start a new conversation with empty context |
/compact [instructions] | Summarize the conversation to free context, with optional focus |
/context | Show context usage as a colored grid |
/usage | Show session cost, plan limits, and activity (/cost is an alias) |
/model [model] | Switch the model and save it as the default |
/effort [level] | Change the effort level for this session |
/fast [on|off] | Toggle fast mode |
/resume [session] | Resume a conversation by ID or name, or open the picker |
/rename [name] | Rename the current session |
/branch [name] | Branch the conversation to try a different direction |
/rewind | Roll the conversation, the code, or both back to an earlier point |
/btw [question] | Ask a side question that does not enter the conversation |
/copy [N] | Copy the last response, or the Nth latest, to the clipboard |
/export [filename] | Export the conversation as plain text |
/exit | Leave Claude Code (/quit also works) |
Project and Setup Commands
Commands that change how Claude Code behaves in this project and on this machine.
| Command | Description |
|---|---|
/init | Generate a starting CLAUDE.md from the codebase |
/memory | Edit CLAUDE.md files and turn auto memory on or off |
/config | Open the settings interface |
/permissions | Manage allow, ask, and deny rules |
/add-dir <path> | Add a working directory during the session |
/mcp | Manage MCP server connections and OAuth sign-in |
/hooks | View hook configurations |
/skills | List available skills |
/plugin | Install, enable, and disable plugins |
/status | Show version, model, account, and connectivity |
/doctor | Diagnose installation, settings, and CLAUDE.md problems |
/terminal-setup | Install a Shift+Enter newline binding for supported terminals |
/keybindings | Open the keyboard shortcuts file |
/statusline | Configure the status line |
Review and Background Work
Commands for checking changes and running longer jobs while you keep typing.
| Command | Description |
|---|---|
/plan [description] | Enter plan mode, optionally starting on a task |
/diff | Review working tree changes, including the edits Claude made |
/code-review | Review the current diff, a PR number, a branch, or a path (/review is an alias) |
/security-review | Check the branch changes for security vulnerabilities |
/simplify | Review changed code for cleanup and apply the fixes |
/tasks | View and manage background shells and subagents |
/loop [interval] [prompt] | Run a prompt repeatedly while the session stays open |
/install-github-app | Set up the Claude GitHub App and Actions workflow for a repository |
claude --bg "run the tests and fix failures" | Start a session in the background and print its ID |
claude agents | List background sessions |
claude attach ID | Open a background session in this terminal |
claude logs ID | Print a background session’s recent output |
claude stop ID | Stop a background session and keep its conversation |
Keyboard Shortcuts
The shortcuts that control the session. Press ? on an empty prompt to see the full list.
| Shortcut | Description |
|---|---|
Esc | Interrupt Claude and keep the work done so far |
Esc Esc | Clear the draft, or open the rewind menu on an empty prompt |
Ctrl+C | Interrupt, or clear the input; a second press exits |
Ctrl+D | Exit Claude Code (press twice) |
Shift+Tab | Cycle permission modes |
Ctrl+R | Search prompt history |
Ctrl+O | Toggle the transcript viewer with full tool output |
Ctrl+B | Send a running Bash command or agent to the background (press twice in tmux) |
Ctrl+T | Show or hide Claude’s task checklist |
Ctrl+G | Edit the prompt in your default text editor |
Ctrl+S | Stash the prompt, then press again to restore it |
Ctrl+V | Paste an image from the clipboard |
Ctrl+L | Redraw the screen |
Alt+P | Switch the model without clearing the prompt (Option+P on macOS) |
Alt+T | Toggle extended thinking (Option+T on macOS) |
Ctrl+Z | Suspend Claude Code; run fg to resume |
Input and Multiline Prompts
Prefixes change what the prompt does, and newlines need a key that does not submit.
| Input | Description |
|---|---|
/ at the start | Run a command or skill |
! at the start | Shell mode: run the command and add its output to the session |
@ | Autocomplete a file path to mention |
\ then Enter | Insert a newline in any terminal |
Ctrl+J | Insert a newline without terminal configuration |
Shift+Enter | Insert a newline in iTerm2, WezTerm, Ghostty, Kitty, Warp, Apple Terminal, and Windows Terminal |
Option+Enter | Insert a newline on macOS with Option set as Meta |
Ctrl+A / Ctrl+E | Move to the start or end of the line |
Ctrl+W | Delete back to the previous whitespace |
Ctrl+U | Delete from the cursor to the line start |
Ctrl+K | Delete to the end of the line |
Ctrl+Y | Paste the text you last deleted |
On macOS, the Alt and Option shortcuts work only after you configure Option as Meta in your terminal.
Permission Modes
How much Claude Code may do before it asks. Cycle with Shift+Tab or set one at launch.
| Mode or flag | Description |
|---|---|
default | Ask on first use of each tool (shown as Manual) |
acceptEdits | Accept file edits and common filesystem commands in the working directory |
plan | Read and explore without editing source files |
auto | Skip routine prompts; a classifier reviews shell commands and network requests first |
dontAsk | Deny anything that would prompt, unless a rule allows it |
bypassPermissions | Skip permission prompts |
claude --permission-mode plan | Start the session in a given mode |
claude --dangerously-skip-permissions | Start with every permission check bypassed |
Use bypassPermissions and --dangerously-skip-permissions only inside an isolated container or VM, since Claude can then change any file and run any command without asking.
Permission Rules
Rules use the format Tool or Tool(specifier). Add them with /permissions, in a settings file, or with launch flags.
| Rule or flag | Description |
|---|---|
Bash | Match every Bash command |
Bash(npm run build) | Match one exact command |
Bash(git *) | Match every command that starts with git |
Read(./.env) | Match reads of .env in the current directory |
WebFetch(domain:example.com) | Match fetches from one domain |
claude --allowedTools "Bash(git *)" Edit | Allow tools for this session |
claude --disallowedTools "Bash(rm *)" | Deny tools for this session |
Claude Code checks deny rules first, then ask, then allow, and the first match wins, so an allow rule cannot carve an exception out of a deny rule. When you approve a Bash command permanently from its prompt, Claude Code saves the rule to .claude/settings.local.json.
MCP Servers
Connect external tools and data sources through the Model Context Protocol.
| Command | Description |
|---|---|
claude mcp add --transport http NAME URL | Add a remote HTTP server |
claude mcp add --transport http NAME URL --header "Authorization: Bearer ..." | Add a remote server with a request header |
claude mcp add NAME -e API_KEY=... -- npx my-mcp-server | Add a local stdio server with an environment variable |
claude mcp add --scope user NAME -- COMMAND | Make the server available in every project |
claude mcp add --scope project NAME -- COMMAND | Share the server with the team through .mcp.json |
claude mcp add-json NAME '{...}' | Add a server from a JSON definition |
claude mcp list | List configured servers and their health |
claude mcp get NAME | Show details for one server |
claude mcp remove NAME | Remove a server |
claude mcp login NAME | Authenticate with an HTTP or SSE server |
claude mcp reset-project-choices | Reset approvals for .mcp.json servers in this project |
claude --mcp-config servers.json | Load servers from a file for one session |
The default scope is local, which keeps the server private to you in the current project. Do not commit API keys inside .mcp.json; pass them through environment variables instead.
Settings and Instruction Files
Where Claude Code reads configuration and project instructions.
| Path | Description |
|---|---|
~/.claude/settings.json | User settings for every project |
.claude/settings.json | Project settings shared through version control |
.claude/settings.local.json | Personal settings for one project, kept out of git |
claude --settings FILE | Extra settings for one session |
~/.claude/CLAUDE.md | Personal instructions for every project |
./CLAUDE.md or ./.claude/CLAUDE.md | Project instructions for the whole team |
./CLAUDE.local.md | Personal project instructions; add it to .gitignore |
.claude/rules/*.md | Instruction files that can be scoped to paths |
@path/to/file | Import another file from inside CLAUDE.md |
.claude/skills/NAME/SKILL.md | Project skill, run as /NAME |
~/.claude/skills/NAME/SKILL.md | Personal skill for every project |
.claude/agents/ | Project subagent definitions |
.mcp.json | Project-scoped MCP servers |
When a key is set in several places, managed settings win, then --settings, then .claude/settings.local.json, then .claude/settings.json, then the user file.
Hooks
Hooks run your own shell commands at fixed points in a session. Define them under the hooks key in a settings file.
| Event | When it fires |
|---|---|
SessionStart | A session begins or resumes |
UserPromptSubmit | A prompt is submitted, before Claude processes it |
PreToolUse | Before a tool call runs; the hook can block it |
PermissionRequest | A tool call needs a permission decision |
PostToolUse | After a tool call succeeds |
PostToolUseFailure | After a tool call fails |
Notification | Claude Code sends a notification |
SubagentStop | A subagent finishes |
Stop | Claude finishes responding |
PreCompact | Before the context is compacted |
SessionEnd | The session ends |
Hooks run with your user account’s permissions. Read any hook that arrives with a project or plugin before you trust it.
Install, Update, and Sign In
Maintenance commands that run outside a session.
| Command | Description |
|---|---|
claude --version | Print the installed version |
claude update | Check for an update and install it |
claude install stable | Install the native build from the stable or latest channel, or a specific version |
claude doctor | Check the health of the installation |
claude auth login | Sign in to your Anthropic account |
claude auth status | Show the current authentication status |
claude auth logout | Sign out |
claude setup-token | Create a long-lived token for automation (requires a Claude subscription) |
claude plugin install NAME@MARKETPLACE | Install a plugin from a marketplace |
claude plugin list | List installed plugins |
claude --safe-mode | Start with CLAUDE.md, skills, plugins, hooks, and MCP servers disabled |
claude --debug="api,hooks" | Start with debug logging for selected categories |
Treat the token from claude setup-token as a password and store it in your CI secret manager, not in the repository.
Troubleshooting
Common problems and the first thing to check.
| Problem | Check |
|---|---|
claude: command not found after installing | Add ~/.local/bin to your PATH and reload the shell |
Shift+Enter submits the prompt | Run /terminal-setup, or use \ then Enter or Ctrl+J |
Alt or Option shortcuts do nothing on macOS | Set Option as Meta in the terminal preferences |
| Context fills up in a long session | Run /context, then /compact or /clear |
A project MCP server shows Pending approval | Approve it when prompted, or reset choices with claude mcp reset-project-choices |
| Claude keeps asking for the same command | Add an allow rule with /permissions |
| Startup breaks after a config change | Start with claude --safe-mode, then run /doctor |
Related Guides
Setup and the tools Claude Code works alongside.
| Guide | Description |
|---|---|
| How to Install Claude Code on Ubuntu and Linux | Native installer, package repositories, npm, and sign-in |
| git worktree: Work on Multiple Branches at Once | The worktrees that claude -w creates |
| GitHub CLI: Manage Repositories, Issues, and Pull Requests | Turn Claude’s changes into pull requests |
| tmux Command in Linux: Sessions, Windows, and Panes | Keep long sessions running on a remote server |
| How to Install and Use Ollama on Ubuntu: Run LLMs Locally | Run models locally instead |
| Git cheatsheet | Quick reference for the commits Claude Code prepares |