Claude Code Cheatsheet

Every command, shortcut, slash command, and config option — one page. Updated May 2026.

Full CLI Reference → Shortcuts Deep-Dive →
Install & First Run Full guide →

Install (npm)

npm install -g @anthropic-ai/claude-code
StepCommand
Installnpm i -g @anthropic-ai/claude-code
Set API keyexport ANTHROPIC_API_KEY=sk-ant-…
Verifyclaude --version
Launchclaude (in your project dir)
Updatenpm update -g @anthropic-ai/claude-code

Quick CLAUDE.md template

# CLAUDE.md — project context for Claude Code

## Stack
Node 20 · TypeScript · Postgres · React

## Commands
- Build: npm run build
- Test:  npm test
- Lint:  npm run lint

## Conventions
- kebab-case files, camelCase functions
- No default exports
- Tests alongside source files

## Off-limits
Never edit: src/generated/, .env
CLI Commands Full reference →

Core commands

CommandWhat it does
claudeLaunch interactive REPL in cwd
claude "prompt"One-shot: run prompt, print, exit
claude -p "msg"Pipe-friendly non-interactive mode
claude --continueResume last conversation
claude --resume <id>Resume a specific conversation by ID
claude --model opusOverride model (opus / sonnet / haiku)
claude --add-dir ./libAdd extra directory to context
claude --dangerously-skip-permissionsSkip all prompts (CI/headless only)

Flags reference

FlagPurpose
--output-format jsonJSON output for scripting
--output-format stream-jsonStreaming JSON (pipe-friendly)
--max-turns NLimit agentic loop iterations
--system "…"Override system prompt
--allowedTools T1,T2Whitelist specific tools only
--no-mcpDisable MCP servers this session
--verboseShow tool calls and reasoning
--versionPrint version and exit
Slash Commands (in-REPL) Full reference →

Session

/clearReset context
/compactSummarise + free tokens
/memoryView/edit CLAUDE.md files
/configOpen settings editor
/statusToken usage & model info
/helpList all slash commands
/quitExit the REPL

Code actions

/reviewReview current changes
/commitStage + commit with AI message
/prCreate a pull request
/testRun test suite, fix failures
/lintRun linter, auto-fix issues
/buildRun build command from config
/fixFix last error or lint warning

Model & tools

/modelSwitch model in-session
/fastToggle fast (Opus) mode
/toolsList available tools
/mcpManage MCP connections
/permissionsView granted permissions
/bugFile a bug report
/doctorDiagnose setup issues
Keyboard Shortcuts Full reference →

REPL input

KeyAction
EnterSubmit prompt
Shift+EnterNew line (multi-line input)
/ Navigate history
Ctrl+CCancel current generation
Ctrl+LClear screen
Ctrl+RSearch history (if shell)
TabAutocomplete file paths & commands
EscCancel input / go back

During generation

KeyAction
Ctrl+CInterrupt generation
Ctrl+ZSuspend to background
y / EnterApprove a tool call
nDeny a tool call
aApprove + allow all similar
dView full diff before approving
eEdit the tool call before approving
?Help (permission prompt options)
Settings & Config Full reference →

Settings file locations

ScopePath
global~/.claude/settings.json
project.claude/settings.json
local.claude/settings.local.json
ContextCLAUDE.md (any dir in tree)
Project settings override global; local overrides both. Commit settings.json, gitignore settings.local.json.

Key settings (settings.json)

{
  "model": "claude-opus-4-5",
  "permissions": {
    "allow": ["Bash(git *)", "Bash(npm *)"],
    "deny": ["Bash(rm -rf *)"]
  },
  "hooks": {
    "PostToolUse": [{
      "matcher": "Bash",
      "hooks": [{"type": "command",
        "command": "echo 'ran bash'"}]
    }]
  },
  "env": {
    "NODE_ENV": "development"
  }
}
CLAUDE.md Patterns Memory guide →

Essential sections

SectionWhat to include
## StackLanguages, frameworks, Node/Python version
## Commandsbuild, test, lint, dev-server commands
## ConventionsNaming, file structure, export style
## ArchitectureKey dirs, data flow, module layout
## TestingTest framework, pattern, where files live
## Off-limitsAuto-generated files, secrets, migrations
## DeployHow to deploy (command, env vars needed)

Advanced patterns

# Scoped context (applies only in src/api/)
# src/api/CLAUDE.md
## API module rules
- All routes must validate with Zod
- Errors: throw AppError, not raw Error
- No direct DB calls — use the repo layer

# ~/.claude/CLAUDE.md (global defaults)
## My defaults
- Prefer functional style
- Always add return types in TypeScript
- Ask before creating new files
Permissions & Safety

Permission syntax

PatternMeaning
BashAll bash commands
Bash(git *)Only git commands
Bash(npm run *)Only npm scripts
WriteAll file writes
Write(src/*)Only writes in src/
ReadAll file reads
WebFetch(*)All HTTP fetches

Env vars (runtime)

VarEffect
ANTHROPIC_API_KEYRequired — your API key
CLAUDE_NO_CONFIRM=1Skip all permission prompts (CI)
CLAUDE_MODELDefault model override
CLAUDE_MAX_TOKENSCap response length
ANTHROPIC_BASE_URLProxy / custom endpoint

Safety checklist

Review every diff before approving
CLAUDE.md: declare off-limits files
Use deny rules for destructive cmds
Never set CLAUDE_NO_CONFIRM=1 locally
Separate API key per developer / CI
Add .claude/ to .gitignore for local settings
Run in a branch — never directly on main
MCP (Model Context Protocol) Full guide →

Register an MCP server

# .claude/settings.json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres",
               "postgresql://localhost/mydb"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {"GITHUB_TOKEN": "${GITHUB_TOKEN}"}
    }
  }
}

Useful MCP servers

ServerGives Claude access to
@mcp/server-githubIssues, PRs, repos
@mcp/server-postgresSQL queries on local DB
@mcp/server-sqliteLocal SQLite databases
@mcp/server-filesystemExpanded filesystem access
@mcp/server-slackSlack channels & threads
@mcp/server-puppeteerBrowser automation
@mcp/server-sentryError tracking & issues
Run claude /mcp to list connected servers and their available tools.

Hook events

EventFires when
PreToolUseBefore any tool call (can block)
PostToolUseAfter tool completes
NotificationClaude sends a user notification
StopClaude finishes responding
SubagentStopA sub-agent completes

Hook recipes

# Auto-run tests after every file write
"PostToolUse": [{
  "matcher": "Write",
  "hooks": [{"type": "command",
    "command": "npm test -- --passWithNoTests"}]
}]

# Desktop notification when done
"Stop": [{
  "hooks": [{"type": "command",
    "command": "notify-send 'Claude done'"}]
}]
Workflow One-liners

Git workflows

TaskCommand
Smart commitclaude /commit
Review my PRclaude /review
Create PRclaude /pr
Explain diffgit diff | claude -p "explain"
Write changeloggit log --oneline | claude -p "write changelog"
Summarise PRgh pr diff 42 | claude -p "summarise"

Code operations

TaskCommand
Fix lint errorsnpm run lint 2>&1 | claude -p "fix"
Explain fileclaude "explain src/auth.ts"
Add testsclaude "write tests for src/utils.ts"
Refactor fnclaude "refactor getUser for readability"
Find bugcat error.log | claude -p "what caused this"
Headless CICLAUDE_NO_CONFIRM=1 claude -p "run checks"
Sub-agents & Parallel Work Full guide →
# Ask Claude Code to spawn parallel sub-agents
"Run these tasks in parallel using sub-agents:
  1. Write unit tests for src/api/users.ts
  2. Update the API docs in docs/api.md
  3. Check for TypeScript errors in src/lib/"

# Each sub-agent gets its own context + tool access
# Use when tasks are independent (no shared files)
# Results are synthesised by the orchestrator Claude
Sub-agents are most effective for parallel research, independent file edits, or multi-repo operations. Avoid for tasks with inter-dependencies — conflicts from parallel writes are hard to reconcile.
All Guides
📘 Free: 5 sample Claude Code prompts · plus the £3 pack with 25 moreSee the free 5 →