Quick Reference

Claude Code Cheatsheet

All CLI flags, keyboard shortcuts, slash commands, built-in skills, and power-user tips — in one bookmarkable page.

Contents

  1. CLI Flags
  2. Keyboard Shortcuts
  3. Slash Commands
  4. Built-in Skills
  5. Hooks Quick Ref
  6. Permission Modes
  7. Key Env Vars
  8. Power Tips

CLI Flags

Pass these when launching claude from your terminal
FlagDescriptionExample
--print / -pNon-interactive mode — print response and exitclaude -p "explain this file"
--output-formatOutput format in print mode: text, json, or stream-jsonclaude -p "…" --output-format json
--model / -mOverride the model (e.g. claude-opus-4-7)claude -m claude-opus-4-7
--resumeResume a specific prior conversation by session IDclaude --resume <session-id>
--continue / -cContinue the most recent conversationclaude -c
--no-toolsDisable all tool use (pure conversation mode)claude --no-tools "what is X?"
--dangerously-skip-permissionsSkip all permission prompts (CI/script use only)claude --dangerously-skip-permissions -p "…"
--allowedToolsWhitelist specific tools (comma-separated)claude --allowedTools Bash,Edit
--disallowedToolsBlacklist specific toolsclaude --disallowedTools Bash
--system-promptPrepend a system prompt (print mode only)claude -p "…" --system-prompt "You are…"
--append-system-promptAppend text to existing system promptclaude -p "…" --append-system-prompt "…"
--max-turnsLimit agentic loop iterationsclaude -p "…" --max-turns 5
--add-dirAdd extra directory to Claude's file accessclaude --add-dir /path/to/extra
--verboseShow detailed tool call outputclaude --verbose
--versionPrint current Claude Code versionclaude --version
Pipe-friendly

Combine --print with shell pipes: cat myfile.ts | claude -p "find bugs" --output-format json | jq .content

⌨️

Keyboard Shortcuts

Works inside the interactive claude REPL
ActionShortcut
Submit messageEnter
Insert newlineShift+Enter
Accept auto-completeTab
Interrupt / cancel responseCtrl+C
Exit Claude CodeCtrl+C twice, or Ctrl+D
Clear screenCtrl+L
ActionShortcut
Previous message (history)
Next message (history)
Move cursor word-leftCtrl+
Move cursor word-rightCtrl+
Jump to line startCtrl+A
Jump to line endCtrl+E
Customize keybindings

Add custom shortcuts in ~/.claude/keybindings.json. Use chord sequences like "ctrl+k ctrl+r" to avoid conflicts with terminal shortcuts.

💬

Slash Commands

Type these at the Claude Code prompt — built-in and user-created skills

Slash commands appear in the autocomplete menu. Built-ins always available; user skills live in ~/.claude/commands/ or .claude/commands/ (project scope).

CommandWhat it does
/helpShow all available commands and shortcuts
/clearClear the current conversation context
/compactCompact conversation — keeps key context, reclaims token budget
/configOpen the Claude Code settings editor
/costShow cost and token usage for the current session
/modelSwitch model mid-session (e.g. swap Opus ↔ Sonnet ↔ Haiku)
/statusShow context usage, model, and active tools
/memoryEdit your CLAUDE.md memory files
/doctorRun a self-diagnostic and check for config issues
/resetReset all settings to defaults
/pr-commentsFetch and display comments from the current PR
/review SkillFull code review of the current branch's changes
/commit SkillStage, diff, draft, and create a git commit
/pr SkillCreate a pull request for the current branch
/scaffold SkillGenerate a project skeleton (Next.js, FastAPI, etc.)
/mock SkillGenerate mock data, fixtures, or test stubs
/docker SkillCreate Dockerfile + compose config for the project
/migrate SkillProduce a schema migration (SQL or ORM)
/fastToggle Fast Mode (Opus with faster output)
Create your own slash commands

Drop a .md file in ~/.claude/commands/my-command.md. Claude runs it when you type /my-command. Project-scoped commands go in .claude/commands/. See full slash commands guide →

🔧

Built-in Skills by Category

30+ skills across git, testing, code quality, infra, and more

Search and preview all skills at the Claude Skills Browser →

Git & Version Control

/commit
Stage, diff, draft, and git commit with a well-formed message
/pr
Open a pull request with summary and test plan auto-filled
/review
Full diff review — logic, style, security, tests
/migrate
Generate a database schema migration (SQL or ORM-flavoured)

Testing & Quality

/mock
Generate realistic mock data, fixtures, or test stubs
/optimize
Profile and optimize hot paths for speed or memory
/lint-fix
Run linter + auto-fix all auto-fixable violations
/security-review
OWASP-style security audit of staged changes

Scaffolding & Generation

/scaffold
Bootstrap a full project (Next.js, FastAPI, Express, etc.)
/docker
Write Dockerfile + docker-compose.yml for the project
/init
Generate CLAUDE.md with codebase documentation + conventions
/component
Generate a typed, accessible UI component with tests

Automation & Config

/hooks-setup
Configure event-triggered shell commands (pre/post tool calls)
/mcp-connect
Add and verify MCP server connections
/ci-setup
Generate GitHub Actions / CircleCI workflow files
/env-setup
Generate .env.example + validation schema

Docs & Explanation

/explain
Walk through a complex function or module step by step
/readme
Generate or update README.md for the project
/changelog
Generate CHANGELOG entries from git history
/api-docs
Document REST or GraphQL endpoints from code
🔗

Hooks Quick Reference

Event-triggered shell commands — full guide at claude-code-hooks →
Hook EventWhen it fires
PreToolUseBefore Claude calls any tool
PostToolUseAfter a tool call completes
StopWhen Claude finishes responding
UserPromptSubmitWhen you submit any message
Exit CodeMeaning
0Success — continue
2Block the tool call (PreToolUse only)
otherError — logged, but execution continues
# ~/.claude/settings.json — minimal hook example
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          { "type": "command", "command": "npm run lint --silent 2>&1 | head -20" }
        ]
      }
    ]
  }
}
🔐

Permission Modes

Control what Claude can do without asking
ModeSet viaBehaviour
Default No flag Prompts for each new tool before executing
Allow-list --allowedTools or settings.json Only the listed tools run without asking; all others still prompt
Deny-list --disallowedTools Listed tools are always blocked; everything else prompts normally
Full auto --dangerously-skip-permissions All tools execute silently — intended for CI scripts only
Fine-grained allow-list in settings.json

Use "permissions": { "allow": ["Bash(git *)", "Edit", "Read"] } to allow only safe git commands inside Bash, while still blocking arbitrary shell execution.

🌿

Key Environment Variables

Set in your shell profile or pass inline before the command
VariablePurpose
ANTHROPIC_API_KEYYour Anthropic API key (required for API usage; not needed for the Claude.ai plan)
CLAUDE_MODELDefault model to use (e.g. claude-opus-4-7)
CLAUDE_MAX_TOKENSOverride default max output token budget
CLAUDE_SKIP_PERMISSIONSSet to 1 to skip prompts (same as --dangerously-skip-permissions)
ANTHROPIC_BASE_URLOverride the API endpoint (for proxies or local models)
NO_COLORDisable colour output (CI-friendly)
CLAUDE_CONFIG_DIROverride the default config directory (~/.claude)
💡

Power Tips

Patterns from experienced Claude Code users
CLAUDE.md is your system prompt

Put architecture rules, coding conventions, and DO NOTs in CLAUDE.md at the project root. Claude reads it on every session. Run /init to generate one from your existing code. See also tips & tricks →

Automate with -p + pipes

Chain claude -p into shell pipelines: git diff HEAD~1 | claude -p "write release notes" --output-format text > RELEASE_NOTES.md. Combine with --max-turns 1 for deterministic one-shot tasks.

Worktrees for isolation

Run dangerous refactors in a git worktree add ../my-branch-wt my-branch, then claude --add-dir ../my-branch-wt. Mistakes stay isolated; main working tree is never touched.

Multi-agent with subagents

Claude Code can spawn subagents with the Agent tool. Use the Explore subagent for read-only research so the main context isn't flooded, and general-purpose for write tasks.

Compact before big tasks

Run /compact before starting a large feature. It summarises prior context into a tight header, freeing the token budget for the actual work rather than old conversation history.

hooks = free CI in your editor

Wire a PostToolUse hook on Edit|Write to run your linter and test suite on every file save. You get instant feedback without leaving the Claude Code session. See hooks guide →

Steer with project settings

Commit a .claude/settings.json to the repo. It sets default allowed tools, custom hooks, and permissions for the entire team — everyone gets the same safe defaults automatically.

Resume interrupted sessions

Run claude --continue to pick up exactly where you left off. Or claude --resume <id> to jump to a specific past session. /cost shows session cost at any point.

📚

Related Guides

⚡ Using Claude Code? 30 power prompts that 2× your output · £5 £3 first 10Get PDF £3 →