cheat-sheets

Claude Code

Anthropic’s terminal coding agent. It reads and edits files, runs commands and talks to MCP servers, under a permission system you control. Pairs with MCP and the Claude API.

Documentation: Claude Code docs · CLI reference · Settings · Hooks

Verification: CLI flags and subcommands were checked against claude --help (version 2.1.220). Slash commands, keyboard shortcuts, settings keys and file layouts are from the official docs and not executed here; those not confirmed are marked (unverified).

Start and Resume #

COMMANDDESCRIPTION
claudeStart an interactive session in the current directory
claude "PROMPT"Start interactive with an initial prompt
claude -p "PROMPT"Print mode: answer and exit (headless)
claude -cContinue the most recent conversation in this directory
claude -r [ID_OR_SEARCH]Resume by session ID, or pick from a list
claude -n NAMEName the session
claude -w [NAME]Work in a new git worktree
claude --from-pr [PR]Resume a session linked to a pull request
claude --add-dir DIRAllow tool access to an extra directory
claude updateCheck for and install updates
claude doctorCheck installation health
claude auth login / claude auth status / claude auth logoutManage authentication
claude setup-tokenCreate a long-lived token for scripts and CI

Common Flags #

FLAGDESCRIPTION
--model MODELAlias (sonnet, opus) or full model name
--effort LEVELlow, medium, high, xhigh or max
--permission-mode MODEacceptEdits, auto, bypassPermissions, manual, dontAsk or plan
--allowedTools "Bash(git *)" EditTools allowed without prompting
--disallowedTools TOOLTools denied
--tools TOOL...Restrict the set of available tools
--append-system-prompt TEXTAdd to the default system prompt
--system-prompt TEXTReplace the system prompt
--settings FILE_OR_JSONLoad extra settings
--setting-sources user,project,localChoose which settings sources load
--mcp-config FILE...Load MCP servers from JSON
--strict-mcp-configUse only servers from --mcp-config
--agents JSONDefine subagents inline
--plugin-dir PATHLoad a plugin from a directory
--debug [FILTER] / --debug-file PATHDebug logging
--safe-modeStart with all customisations disabled
--dangerously-skip-permissionsSkip every permission check. Only in a sandbox with no sensitive access

Headless Mode (-p) #

Options below only apply with -p.

COMMANDDESCRIPTION
claude -p "PROMPT" --output-format jsonOne JSON result object
claude -p "PROMPT" --output-format stream-jsonStreaming JSON events (add --verbose if the CLI asks for it)
claude -p "PROMPT" --json-schema SCHEMA_JSONValidate output against a JSON Schema
claude -p "PROMPT" --max-budget-usd 2Stop at a spend limit
claude -p "PROMPT" --fallback-model sonnetFall back if the model is overloaded
claude -p "PROMPT" --no-session-persistenceDo not save the session
cat FILE | claude -p "Summarise this"Pipe input
bash
git diff main... | claude -p "Review this diff for bugs" --output-format text

Slash Commands #

Type / in a session to list what is available (/help). Custom commands and skills appear in the same list.

COMMANDDESCRIPTION
/helpShow help and commands
/clearStart a fresh conversation
/compact [FOCUS]Summarise history to free context
/resumePick a previous session
/modelChange model
/configOpen settings
/permissionsView or edit permission rules
/memoryEdit memory files (CLAUDE.md)
/initCreate a CLAUDE.md for the repo
/mcpManage MCP servers
/agentsManage subagents
/hooksView hook configuration
/doctorDiagnose the install
/costShow token use and cost (unverified)
/statusShow version, model and account (unverified)
/login / /logoutSwitch account
/exitQuit

Keyboard Shortcuts #

Shortcuts are (unverified); use /help for the list on your version.

KEYACTION
EscInterrupt the current turn
Esc EscRewind or edit an earlier message
Shift+TabCycle permission modes
Ctrl+CCancel input or interrupt
Ctrl+DExit
Ctrl+RSearch prompt history
@PATHMention a file
!COMMANDRun a shell command from the prompt

Settings and Permissions #

Settings merge from user (~/.claude/settings.json), project (.claude/settings.json, shared) and local (.claude/settings.local.json, not committed). Managed policy overrides all.

json
{
  "model": "sonnet",
  "permissions": {
    "allow": ["Bash(git status)", "Bash(git diff *)", "Read"],
    "ask": ["Bash(git push *)"],
    "deny": ["Read(./.env)", "Read(./secrets/**)"]
  },
  "env": { "EXAMPLE_VAR": "value" }
}
RULE FORMMEANING
ToolThe whole tool (for example Read, Edit, WebFetch)
Bash(PATTERN)Shell commands matching a pattern (Bash(npm run test *))
Read(PATH_GLOB) / Edit(PATH_GLOB)File access by path
mcp__SERVER__TOOLA tool from an MCP server

Deny rules win over allow. Never rely on prompt text to protect secrets; deny the file read.

CLAUDE.md and Memory #

FILESCOPE
~/.claude/CLAUDE.mdPersonal, all projects
./CLAUDE.mdProject, committed to git
./CLAUDE.local.mdPersonal project notes, not committed (unverified)
@path/to/file.md inside CLAUDE.mdImport another file

Keep CLAUDE.md short and concrete: build and test commands, conventions, things not obvious from code. See Prompting and Context Engineering.

Hooks #

Hooks run your commands at lifecycle events. Configure in settings under hooks.

EVENTFIRES
PreToolUseBefore a tool runs; can block it
PostToolUseAfter a tool succeeds
UserPromptSubmitWhen you submit a prompt
Stop / SubagentStopWhen the agent or a subagent finishes
SessionStart / SessionEndSession boundaries
NotificationWhen Claude needs attention
PreCompactBefore context compaction
json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "/path/to/check-command.sh" }]
      }
    ]
  }
}

The hook receives event JSON on stdin. Exit code 2 blocks the action and feeds stderr back to Claude; 0 continues.

Skills and Subagents #

WHATWHERE
Skill.claude/skills/NAME/SKILL.md (or ~/.claude/skills/NAME/)
Subagent.claude/agents/NAME.md (or ~/.claude/agents/)
Pluginclaude plugin install PLUGIN@MARKETPLACE; also enable, disable, details
markdown
---
name: log-triage
description: Use when asked to find the cause of an error in logs.
---
Steps and instructions for the skill go here.
markdown
---
name: reviewer
description: Reviews diffs for bugs. Use after code changes.
tools: Read, Grep, Glob
model: sonnet
---
You review diffs and report problems with file and line.

MCP Servers #

COMMANDDESCRIPTION
claude mcp add --transport http NAME URLAdd a remote HTTP server
claude mcp add NAME -e KEY=VALUE -- COMMAND ARGSAdd a local stdio server
claude mcp add-json NAME 'JSON'Add from a JSON string
claude mcp listList servers and health
claude mcp get NAMEShow one server
claude mcp remove NAMERemove a server
claude mcp login NAME / claude mcp logout NAMEOAuth for a server
claude mcp add -s user ...Scope: local (default), user or project
claude mcp serveRun Claude Code itself as an MCP server

Project-scoped servers live in .mcp.json and need approval on first use. More in MCP.

Environment Variables #

VARIABLEUSE
ANTHROPIC_API_KEYAPI key authentication instead of an account login
ANTHROPIC_MODELDefault model (unverified)
MAX_THINKING_TOKENSExtended thinking budget (unverified)
CLAUDE_CODE_SIMPLE=1Same as --bare (set by that flag)

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.