Reference · Claude Code

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.

105 entries · 12 sections · updated Sep 12, 2026

Install & start

Get Claude Code onto your machine and open a session in the right folder.

npm install -g @anthropic-ai/claude-code

Installs 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
claude

Starts 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 --continue

Reopens the most recent session in this directory with its full context. Short form: -c.

claude -c
claude --resume

Shows 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 --version

Updates 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.

/init

Scans the project and writes a starter CLAUDE.md with build, test and convention notes.

/clear

Empties 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
/help

Lists every available command, including custom ones and skills.

/config

Opens the settings UI: theme, notifications, auto-compact, model defaults.

/cost

Shows tokens used and, on API billing, the cost of the current session.

/context

Breaks down what is filling the context window: system prompt, tools, messages, files. Newer builds; check /help.

/memory

Opens the CLAUDE.md files that apply to this session so you can edit them in place.

/model

Switches the model for the rest of the session.

/permissions

Views and edits the allow and deny rules for tools and commands.

/review

Asks for a code review of the current changes or a pull request.

/status

Shows the account, model, working directory and session details.

/mcp

Lists connected MCP servers, their tools, and lets you authenticate remote ones.

/agents

Creates, edits and lists subagents for this project or your user account.

/hooks

Views and configures hooks that run on tool events.

/rewind

Restores files and conversation to an earlier checkpoint in this session. Also reachable by pressing Escape twice.

/resume

Switches to a different past session without leaving the terminal.

/vim

Toggles vim keybindings in the input box.

/terminal-setup

Configures Shift+Enter for newlines in supported terminals.

/login · /logout

Signs in with a Claude subscription or switches accounts.

/doctor

Checks the installation for problems: version, permissions, environment.

/bug

Files a bug report to Anthropic with the session context attached.

Keyboard & input

The keystrokes that separate steering from spectating.

Shift+Tab

Cycles the permission mode: normal, accept edits, plan mode. Watch the label under the input box.

Esc

Interrupts the current turn. The agent stops, keeps what it already did, and waits for your next message.

Esc Esc

Opens the message history so you can jump back to an earlier point, rewinding the conversation and, optionally, the files.

@path

Attaches 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?
!command

Runs a shell command yourself and puts the output into the conversation.

!npm test
# note

Starts a memory note; Claude asks which CLAUDE.md to save it to.

# always run pnpm, never npm
Ctrl+C

Cancels the current input or action; press twice to exit the session.

\ then Enter

Inserts 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 edits

Auto-approves file edits in the project; still asks before shell commands. Good for a tight loop where you review diffs after.

Plan mode

Read-only: the agent investigates and proposes a plan you approve before anything is edited.

claude --permission-mode plan
--dangerously-skip-permissions

Skips every prompt. Only inside a sandbox or container with no secrets and nothing you cannot restore.

claude --dangerously-skip-permissions
--allowedTools · --disallowedTools

Pre-approves or blocks specific tools for the session, with optional argument patterns.

claude --allowedTools "Read" "Bash(npm test)"
permissions.allow / deny

The same rules, persisted in .claude/settings.json so the whole team shares them.

{ "permissions": { "allow": ["Bash(pnpm test*)"], "deny": ["Read(./.env)"] } }
/permissions

Inspects 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.md

Your personal instructions, loaded in every project: preferred tools, style, things you always want.

./CLAUDE.md

Project 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.md

Personal notes for this project that stay out of git. Add it to .gitignore.

@path in CLAUDE.md

Imports 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.json

Shared project settings: permissions, hooks, environment variables, model defaults.

.claude/settings.local.json

Your overrides for this project; gitignored by default.

.claude/commands/<name>.md

A 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>.md

A subagent: frontmatter for name, description and tools, then its system prompt.

.claude/skills/<name>/SKILL.md

A skill the agent loads on demand when the task matches its description. Personal skills live under ~/.claude/skills.

.mcp.json

Project-scoped MCP servers, shared with the team through git.

AGENTS.md

The 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.

PreToolUse

Runs before a tool call. Exit code 2 blocks the call and sends your stderr to the model as the reason.

PostToolUse

Runs 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\"" }] }
UserPromptSubmit

Runs when you send a message, before the model sees it. Can add context or block the prompt.

Notification

Runs when Claude Code wants your attention, such as waiting for permission. Wire it to a desktop notification.

Stop · SubagentStop

Runs when the agent (or a subagent) finishes a turn. Use it to require green tests before it is allowed to stop.

PreCompact

Runs before compaction, so you can save the transcript or inject what must survive.

SessionStart

Runs when a session starts or resumes. Good for loading environment context.

matcher

Filters 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 codes

Hooks 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 · remove

Lists configured servers, shows one, or removes one.

claude mcp remove github
-s local | project | user

Scope: 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"]
/mcp

Checks 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 tool

Spawns a subagent with its own context window and reports back a summary, keeping bulk output out of your main session.

.claude/agents/<name>.md frontmatter

name, 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
---
/agents

Interactive 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.md

A 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-json

Plain 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-prompt

Adds instructions to the default system prompt for this run without replacing it.

--append-system-prompt "Only touch files under packages/api"
stdin piping

Anything piped in becomes part of the prompt context.

git diff | claude -p "review this diff for bugs"
CI usage

Set 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 feature

Creates 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 worktree

Each session gets its own files and its own branch; merge the results through pull requests.

git worktree list · remove

Lists active worktrees and deletes one when the branch is merged. Worktrees cost disk; clean up.

git worktree remove ../my-app-auth
Built-in worktree support

Newer 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.

/cost

Tokens in, tokens out, cached tokens, and the API cost so far.

/context

What fills the window right now. If tool definitions or old files dominate, clear or compact.

Prompt caching

Automatic: the stable prefix (system prompt, CLAUDE.md, tools) is cached between requests. Changing early context invalidates it.

/model per task

Use a cheaper, faster model for grunt work and the strongest one for planning and hard bugs.

/clear between tasks

A new task in an old session starts closer to the dumb zone and pays for context it does not need.

Subscription windows vs API billing

Subscriptions 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 editing

Anything bigger than a one-file change starts in plan mode. Correct the plan, then execute.

Small turns

One outcome per message. Long multi-part prompts get the last part wrong.

Tests are the check

Give the agent a command that proves it is done, and let it run it. Green tests beat a confident summary.

Keep CLAUDE.md short

Commands, conventions, gotchas. Long docs get pointed to, not pasted; every line costs context in every session.

Clear between tasks

Start unrelated work in a fresh session so it gets the sharp part of the context window.

Review every diff

Read what changed before you accept it. The model is confident whether it is right or wrong.

Commit before big runs

A clean commit is the cheapest checkpoint; git resets what /rewind cannot.

Hooks for hard rules

Anything that must always happen (formatting, blocking rm -rf, tests before stop) goes in a hook, not a sentence.

Subagents for research

Send codebase archaeology and log reading to a subagent so the findings, not the noise, land in your session.

Headless for batch work

Repetitive 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.

Keep going
How to use this sheet

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.

Learn Claude Code by shipping with it

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 →