Claude Code Cheat Sheet
Everything you type into Claude Code, on one page: the CLI commands, every slash command, the keys that steer a running turn, permission modes, the CLAUDE.md and config files, hook events, MCP, subagents, headless mode and worktrees. Each row links to the AI Coding Dictionary entry that explains the idea and to the Course 01 lesson that drills it.
Install & start
Get Claude Code onto your machine and open a session in the right folder.
npm install -g @anthropic-ai/claude-codeInstalls the Claude Code CLI globally with npm. Anthropic also ships a native installer script; either route ends with a claude command on your PATH.
npm install -g @anthropic-ai/claude-code
claudeStarts an interactive session in the current directory. The folder you launch from is the project the agent can see and edit.
cd my-app && claude
claude "prompt"Starts a session and sends the first message immediately.
claude "explain the folder structure and find the entry point"
claude -p "prompt"Print mode: runs one prompt non-interactively, prints the answer, exits. The basis of every script and CI job.
claude -p "list the TODO comments in src/"
claude --continueReopens the most recent session in this directory with its full context. Short form: -c.
claude -c
claude --resumeShows a picker of past sessions in this directory so you can reopen one. Short form: -r; pass a session id to skip the picker.
claude -r
--model <name>Picks the model for the session. Aliases like sonnet and opus work, as do full model ids. You can also switch mid-session with /model.
claude --model opus
--add-dir <path>Grants the agent access to an extra directory outside the one you launched from, for monorepos or shared packages.
claude --add-dir ../shared-lib
claude update · claude --versionUpdates to the latest release, or prints the version you are on. Run update before filing a bug.
claude update
Slash commands
Type / inside a session. Built-ins below; your own live in .claude/commands.
/initScans the project and writes a starter CLAUDE.md with build, test and convention notes.
/clearEmpties the context window and starts fresh in the same directory. Use it between unrelated tasks.
/compact [focus]Summarises the conversation so far to free context. Add a focus phrase to tell it what to keep.
/compact keep the failing test output and the plan
/helpLists every available command, including custom ones and skills.
/configOpens the settings UI: theme, notifications, auto-compact, model defaults.
/costShows tokens used and, on API billing, the cost of the current session.
/contextBreaks down what is filling the context window: system prompt, tools, messages, files. Newer builds; check /help.
/memoryOpens the CLAUDE.md files that apply to this session so you can edit them in place.
/modelSwitches the model for the rest of the session.
/permissionsViews and edits the allow and deny rules for tools and commands.
/reviewAsks for a code review of the current changes or a pull request.
/statusShows the account, model, working directory and session details.
/mcpLists connected MCP servers, their tools, and lets you authenticate remote ones.
/agentsCreates, edits and lists subagents for this project or your user account.
/hooksViews and configures hooks that run on tool events.
/rewindRestores files and conversation to an earlier checkpoint in this session. Also reachable by pressing Escape twice.
/resumeSwitches to a different past session without leaving the terminal.
/vimToggles vim keybindings in the input box.
/terminal-setupConfigures Shift+Enter for newlines in supported terminals.
/login · /logoutSigns in with a Claude subscription or switches accounts.
/doctorChecks the installation for problems: version, permissions, environment.
/bugFiles a bug report to Anthropic with the session context attached.
Keyboard & input
The keystrokes that separate steering from spectating.
Shift+TabCycles the permission mode: normal, accept edits, plan mode. Watch the label under the input box.
EscInterrupts the current turn. The agent stops, keeps what it already did, and waits for your next message.
Esc EscOpens the message history so you can jump back to an earlier point, rewinding the conversation and, optionally, the files.
@pathAttaches a file or directory to the message with a fuzzy picker. Cheaper than pasting the file.
@src/auth/session.ts why does this expire early?
!commandRuns a shell command yourself and puts the output into the conversation.
!npm test
# noteStarts a memory note; Claude asks which CLAUDE.md to save it to.
# always run pnpm, never npm
Ctrl+CCancels the current input or action; press twice to exit the session.
\ then EnterInserts a newline for multi-line prompts. After /terminal-setup, Shift+Enter does the same.
↑ / ↓Walks back through your previous prompts.
Modes & permissions
What the agent may do without asking, from read-only to fully unattended.
Default (ask)Reads and searches freely; asks before every file edit and every command that changes state.
Accept editsAuto-approves file edits in the project; still asks before shell commands. Good for a tight loop where you review diffs after.
Plan modeRead-only: the agent investigates and proposes a plan you approve before anything is edited.
claude --permission-mode plan
--dangerously-skip-permissionsSkips every prompt. Only inside a sandbox or container with no secrets and nothing you cannot restore.
claude --dangerously-skip-permissions
--allowedTools · --disallowedToolsPre-approves or blocks specific tools for the session, with optional argument patterns.
claude --allowedTools "Read" "Bash(npm test)"
permissions.allow / denyThe same rules, persisted in .claude/settings.json so the whole team shares them.
{ "permissions": { "allow": ["Bash(pnpm test*)"], "deny": ["Read(./.env)"] } }/permissionsInspects and edits the active rules without leaving the session.
Memory & config files
Where instructions, settings, commands and agents live. Most of it belongs in git.
~/.claude/CLAUDE.mdYour personal instructions, loaded in every project: preferred tools, style, things you always want.
./CLAUDE.mdProject memory, committed to the repo and loaded every session: how to build and test, conventions, gotchas. Keep it short; point to docs instead of pasting them.
./CLAUDE.local.mdPersonal notes for this project that stay out of git. Add it to .gitignore.
@path in CLAUDE.mdImports another file into memory on load, so CLAUDE.md can pull in AGENTS.md or a conventions doc without duplicating it.
@AGENTS.md
.claude/settings.jsonShared project settings: permissions, hooks, environment variables, model defaults.
.claude/settings.local.jsonYour overrides for this project; gitignored by default.
.claude/commands/<name>.mdA custom slash command. The file body is the prompt; $ARGUMENTS is replaced by whatever you type after /name.
# .claude/commands/fix-issue.md Fix GitHub issue $ARGUMENTS. Read it with gh, write a failing test, then make it pass.
.claude/agents/<name>.mdA subagent: frontmatter for name, description and tools, then its system prompt.
.claude/skills/<name>/SKILL.mdA skill the agent loads on demand when the task matches its description. Personal skills live under ~/.claude/skills.
.mcp.jsonProject-scoped MCP servers, shared with the team through git.
AGENTS.mdThe cross-tool convention read by Codex and other agents. Keep one source of truth and import it from CLAUDE.md.
Hooks
Shell commands the harness runs on events. Deterministic, unlike an instruction the model might skip.
PreToolUseRuns before a tool call. Exit code 2 blocks the call and sends your stderr to the model as the reason.
PostToolUseRuns after a tool call succeeds. The classic use: format the file that was just edited.
{ "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "npx prettier --write \"$FILE\"" }] }UserPromptSubmitRuns when you send a message, before the model sees it. Can add context or block the prompt.
NotificationRuns when Claude Code wants your attention, such as waiting for permission. Wire it to a desktop notification.
Stop · SubagentStopRuns when the agent (or a subagent) finishes a turn. Use it to require green tests before it is allowed to stop.
PreCompactRuns before compaction, so you can save the transcript or inject what must survive.
SessionStartRuns when a session starts or resumes. Good for loading environment context.
matcherFilters which tool names a hook applies to; a plain name or a regex such as Edit|Write. Omit it to match everything.
Hook input & exit codesHooks receive JSON on stdin (tool name, input, session, cwd). Exit 0 allows, exit 2 blocks with feedback, anything else is a non-blocking error shown to you.
MCP
Plug external tools into the session: databases, browsers, SaaS APIs, your own servers.
claude mcp add <name> -- <command>Adds a local stdio server. Everything after -- is the command that starts it.
claude mcp add github -- npx -y @modelcontextprotocol/server-github
claude mcp add --transport http <name> <url>Adds a remote HTTP server; use --transport sse for servers that still speak SSE. Authenticate with /mcp.
claude mcp add --transport http linear https://mcp.linear.app/mcp
claude mcp list · get · removeLists configured servers, shows one, or removes one.
claude mcp remove github
-s local | project | userScope: local is this folder for you only, project writes .mcp.json for the team, user applies everywhere.
claude mcp add -s project ...
mcp__<server>__<tool>How MCP tools are named once connected; use the same names in permission rules and --allowedTools.
"allow": ["mcp__github__create_issue"]
/mcpChecks server status, lists tools, and completes OAuth for remote servers.
Subagents & skills
Delegate research or specialist work to a fresh context; teach the agent reusable procedures.
Agent toolSpawns a subagent with its own context window and reports back a summary, keeping bulk output out of your main session.
.claude/agents/<name>.md frontmattername, description (when to use it), tools (allow-list) and optionally model. The description is how Claude decides to delegate automatically.
--- name: code-reviewer description: Reviews diffs for bugs and style. Use after any change. tools: Read, Grep, Glob, Bash ---
/agentsInteractive UI to create and edit subagents, at project or user scope.
"use the code-reviewer subagent"Explicit delegation: name the subagent in your prompt when you do not want to rely on automatic routing.
SKILL.mdA skill folder: frontmatter name and description, then instructions and any helper files. Loaded only when relevant, so it costs no context until used.
/<skill-name>Many skills can also be invoked by hand like a slash command.
Headless & scripting
Run Claude Code from scripts, cron and CI with no terminal UI.
claude -p "prompt"One prompt, one answer, exit. Combine with the flags below for automation.
claude -p "summarise the last 10 commits"
--output-format text | json | stream-jsonPlain text (default), a single JSON result with usage and cost, or streamed JSON events for tooling.
claude -p "..." --output-format json
--max-turns <n>Caps the number of agentic turns so a runaway task cannot loop forever.
--max-turns 15
--append-system-promptAdds instructions to the default system prompt for this run without replacing it.
--append-system-prompt "Only touch files under packages/api"
stdin pipingAnything piped in becomes part of the prompt context.
git diff | claude -p "review this diff for bugs"
CI usageSet ANTHROPIC_API_KEY, pick an explicit permission mode or allow-list, and let the run end in a pull request rather than a merge. Anthropic publishes an official GitHub Action.
claude -p "fix the failing test" --allowedTools "Read" "Edit" "Bash(npm test)"
Worktrees & parallel work
Run several agents on one repo without them stepping on each other.
git worktree add ../repo-feature -b featureCreates a second checkout of the repo on a new branch, sharing one .git. Start a separate claude session inside it.
git worktree add ../my-app-auth -b feat/auth && cd ../my-app-auth && claude
One agent per worktreeEach session gets its own files and its own branch; merge the results through pull requests.
git worktree list · removeLists active worktrees and deletes one when the branch is merged. Worktrees cost disk; clean up.
git worktree remove ../my-app-auth
Built-in worktree supportNewer builds can create an isolated worktree for a task themselves; check claude --help for the current flag.
Cost & limits
Where the tokens go and how to make a session last.
/costTokens in, tokens out, cached tokens, and the API cost so far.
/contextWhat fills the window right now. If tool definitions or old files dominate, clear or compact.
Prompt cachingAutomatic: the stable prefix (system prompt, CLAUDE.md, tools) is cached between requests. Changing early context invalidates it.
/model per taskUse a cheaper, faster model for grunt work and the strongest one for planning and hard bugs.
/clear between tasksA new task in an old session starts closer to the dumb zone and pays for context it does not need.
Subscription windows vs API billingSubscriptions meter usage in rolling windows; the API bills per token. /status shows which you are on; newer builds add a /usage view.
Best practices
The habits that make the same model produce better work.
Plan before editingAnything bigger than a one-file change starts in plan mode. Correct the plan, then execute.
Small turnsOne outcome per message. Long multi-part prompts get the last part wrong.
Tests are the checkGive the agent a command that proves it is done, and let it run it. Green tests beat a confident summary.
Keep CLAUDE.md shortCommands, conventions, gotchas. Long docs get pointed to, not pasted; every line costs context in every session.
Clear between tasksStart unrelated work in a fresh session so it gets the sharp part of the context window.
Review every diffRead what changed before you accept it. The model is confident whether it is right or wrong.
Commit before big runsA clean commit is the cheapest checkpoint; git resets what /rewind cannot.
Hooks for hard rulesAnything that must always happen (formatting, blocking rm -rf, tests before stop) goes in a hook, not a sentence.
Subagents for researchSend codebase archaeology and log reading to a subagent so the findings, not the noise, land in your session.
Headless for batch workRepetitive changes across many files or repos belong in claude -p with an allow-list and a PR at the end.
Claude Code FAQ
The questions people search before they type their first prompt.
What is Claude Code?
Claude Code is Anthropic's agentic coding tool that runs in your terminal. You describe what you want in plain language; it reads your codebase, edits files, runs commands and tests, and reports back, asking permission for anything risky.
How do I install Claude Code?
Install it with npm (npm install -g @anthropic-ai/claude-code) or Anthropic's native installer, then run claude inside a project folder and sign in with a Claude subscription or an API key.
Is Claude Code free?
The tool itself is free to install. Usage is metered through Claude subscription plans or API billing; see anthropic.com for current pricing and plan limits.
Claude Code vs Cursor: which should I use?
Claude Code is a terminal agent that works through your whole project autonomously; Cursor is an AI-native editor where you stay in the file. Many people use both. Our comparison page walks through the tradeoffs.
What is CLAUDE.md?
CLAUDE.md is the project memory file Claude Code loads at the start of every session: build and test commands, conventions and gotchas. Generate a starter with /init and keep it short.
How do I run Claude Code in CI?
Use print mode (claude -p) with an explicit permission allow-list, an API key in the environment, and --output-format json if a script consumes the result. Anthropic also publishes an official GitHub Action. Have the run end in a pull request, not a merge.
Skim it once, then keep it open for a week. The commands are the easy part; the habits under Best practices are what make the same model ship better code. Flags and slash commands change between releases, so when a row disagrees with your install, claude --help and /help win.
Course 01 takes you from install to a deployed side project in 28 free lessons: the loop, plan mode, CLAUDE.md, hooks, MCP, subagents and skills, each with a hands-on step.
Start Course 01 →