Skip to main content

Claude Code Cheatsheet

By Dejan Panovski •Updated on • Download PDF

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.

CommandDescription
claudeStart an interactive session in the current directory
claude "explain this project"Start a session with a first prompt
claude -cContinue the most recent conversation in this directory
claude -rOpen the session picker
claude -r SESSION_IDResume a specific conversation
claude -c --fork-sessionContinue 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 123Resume the session linked to a pull request
claude -w feature-xStart in a new git worktree named feature-x
claude --add-dir ../sharedAllow file access to another directory
claude --model opusPick the model by alias, such as opus or sonnet, or by full name
claude --effort highSet the effort level: low, medium, high, xhigh, or max

-p runs a single prompt, prints the answer, and exits, which makes Claude Code usable in pipes and CI jobs.

CommandDescription
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 jsonReturn the result as a single JSON object
claude -p "..." --output-format stream-json --verboseStream events as they arrive
claude -p "..." --json-schema '{...}'Validate structured output against a JSON Schema
claude -p "..." --max-budget-usd 2Stop when estimated API spend reaches $2; final spend may exceed this
claude -p "..." --allowedTools "Bash(npm test *)" ReadPre-approve the tools the job needs
claude -p "..." --append-system-prompt "..."Add instructions to the default system prompt
claude -p "..." --no-session-persistenceDo 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.

CommandDescription
/clearStart a new conversation with empty context
/compact [instructions]Summarize the conversation to free context, with optional focus
/contextShow context usage as a colored grid
/usageShow 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
/rewindRoll 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
/exitLeave Claude Code (/quit also works)

Project and Setup Commands

Commands that change how Claude Code behaves in this project and on this machine.

CommandDescription
/initGenerate a starting CLAUDE.md from the codebase
/memoryEdit CLAUDE.md files and turn auto memory on or off
/configOpen the settings interface
/permissionsManage allow, ask, and deny rules
/add-dir <path>Add a working directory during the session
/mcpManage MCP server connections and OAuth sign-in
/hooksView hook configurations
/skillsList available skills
/pluginInstall, enable, and disable plugins
/statusShow version, model, account, and connectivity
/doctorDiagnose installation, settings, and CLAUDE.md problems
/terminal-setupInstall a Shift+Enter newline binding for supported terminals
/keybindingsOpen the keyboard shortcuts file
/statuslineConfigure the status line

Review and Background Work

Commands for checking changes and running longer jobs while you keep typing.

CommandDescription
/plan [description]Enter plan mode, optionally starting on a task
/diffReview working tree changes, including the edits Claude made
/code-reviewReview the current diff, a PR number, a branch, or a path (/review is an alias)
/security-reviewCheck the branch changes for security vulnerabilities
/simplifyReview changed code for cleanup and apply the fixes
/tasksView and manage background shells and subagents
/loop [interval] [prompt]Run a prompt repeatedly while the session stays open
/install-github-appSet 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 agentsList background sessions
claude attach IDOpen a background session in this terminal
claude logs IDPrint a background session’s recent output
claude stop IDStop 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.

ShortcutDescription
EscInterrupt Claude and keep the work done so far
Esc EscClear the draft, or open the rewind menu on an empty prompt
Ctrl+CInterrupt, or clear the input; a second press exits
Ctrl+DExit Claude Code (press twice)
Shift+TabCycle permission modes
Ctrl+RSearch prompt history
Ctrl+OToggle the transcript viewer with full tool output
Ctrl+BSend a running Bash command or agent to the background (press twice in tmux)
Ctrl+TShow or hide Claude’s task checklist
Ctrl+GEdit the prompt in your default text editor
Ctrl+SStash the prompt, then press again to restore it
Ctrl+VPaste an image from the clipboard
Ctrl+LRedraw the screen
Alt+PSwitch the model without clearing the prompt (Option+P on macOS)
Alt+TToggle extended thinking (Option+T on macOS)
Ctrl+ZSuspend 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.

InputDescription
/ at the startRun a command or skill
! at the startShell mode: run the command and add its output to the session
@Autocomplete a file path to mention
\ then EnterInsert a newline in any terminal
Ctrl+JInsert a newline without terminal configuration
Shift+EnterInsert a newline in iTerm2, WezTerm, Ghostty, Kitty, Warp, Apple Terminal, and Windows Terminal
Option+EnterInsert a newline on macOS with Option set as Meta
Ctrl+A / Ctrl+EMove to the start or end of the line
Ctrl+WDelete back to the previous whitespace
Ctrl+UDelete from the cursor to the line start
Ctrl+KDelete to the end of the line
Ctrl+YPaste 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 flagDescription
defaultAsk on first use of each tool (shown as Manual)
acceptEditsAccept file edits and common filesystem commands in the working directory
planRead and explore without editing source files
autoSkip routine prompts; a classifier reviews shell commands and network requests first
dontAskDeny anything that would prompt, unless a rule allows it
bypassPermissionsSkip permission prompts
claude --permission-mode planStart the session in a given mode
claude --dangerously-skip-permissionsStart 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 flagDescription
BashMatch 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 *)" EditAllow 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.

CommandDescription
claude mcp add --transport http NAME URLAdd 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-serverAdd a local stdio server with an environment variable
claude mcp add --scope user NAME -- COMMANDMake the server available in every project
claude mcp add --scope project NAME -- COMMANDShare the server with the team through .mcp.json
claude mcp add-json NAME '{...}'Add a server from a JSON definition
claude mcp listList configured servers and their health
claude mcp get NAMEShow details for one server
claude mcp remove NAMERemove a server
claude mcp login NAMEAuthenticate with an HTTP or SSE server
claude mcp reset-project-choicesReset approvals for .mcp.json servers in this project
claude --mcp-config servers.jsonLoad 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.

PathDescription
~/.claude/settings.jsonUser settings for every project
.claude/settings.jsonProject settings shared through version control
.claude/settings.local.jsonPersonal settings for one project, kept out of git
claude --settings FILEExtra settings for one session
~/.claude/CLAUDE.mdPersonal instructions for every project
./CLAUDE.md or ./.claude/CLAUDE.mdProject instructions for the whole team
./CLAUDE.local.mdPersonal project instructions; add it to .gitignore
.claude/rules/*.mdInstruction files that can be scoped to paths
@path/to/fileImport another file from inside CLAUDE.md
.claude/skills/NAME/SKILL.mdProject skill, run as /NAME
~/.claude/skills/NAME/SKILL.mdPersonal skill for every project
.claude/agents/Project subagent definitions
.mcp.jsonProject-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.

EventWhen it fires
SessionStartA session begins or resumes
UserPromptSubmitA prompt is submitted, before Claude processes it
PreToolUseBefore a tool call runs; the hook can block it
PermissionRequestA tool call needs a permission decision
PostToolUseAfter a tool call succeeds
PostToolUseFailureAfter a tool call fails
NotificationClaude Code sends a notification
SubagentStopA subagent finishes
StopClaude finishes responding
PreCompactBefore the context is compacted
SessionEndThe 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.

CommandDescription
claude --versionPrint the installed version
claude updateCheck for an update and install it
claude install stableInstall the native build from the stable or latest channel, or a specific version
claude doctorCheck the health of the installation
claude auth loginSign in to your Anthropic account
claude auth statusShow the current authentication status
claude auth logoutSign out
claude setup-tokenCreate a long-lived token for automation (requires a Claude subscription)
claude plugin install NAME@MARKETPLACEInstall a plugin from a marketplace
claude plugin listList installed plugins
claude --safe-modeStart 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.

ProblemCheck
claude: command not found after installingAdd ~/.local/bin to your PATH and reload the shell
Shift+Enter submits the promptRun /terminal-setup, or use \ then Enter or Ctrl+J
Alt or Option shortcuts do nothing on macOSSet Option as Meta in the terminal preferences
Context fills up in a long sessionRun /context, then /compact or /clear
A project MCP server shows Pending approvalApprove it when prompted, or reset choices with claude mcp reset-project-choices
Claude keeps asking for the same commandAdd an allow rule with /permissions
Startup breaks after a config changeStart with claude --safe-mode, then run /doctor

Setup and the tools Claude Code works alongside.

GuideDescription
How to Install Claude Code on Ubuntu and LinuxNative installer, package repositories, npm, and sign-in
git worktree: Work on Multiple Branches at OnceThe worktrees that claude -w creates
GitHub CLI: Manage Repositories, Issues, and Pull RequestsTurn Claude’s changes into pull requests
tmux Command in Linux: Sessions, Windows, and PanesKeep long sessions running on a remote server
How to Install and Use Ollama on Ubuntu: Run LLMs LocallyRun models locally instead
Git cheatsheetQuick reference for the commits Claude Code prepares