Claude Code Cheat Sheet

Quick reference for expert Claude Code usage. Keep this handy.


Essential Files

~/.claude/
  CLAUDE.md                          # Global instructions (all projects)
  settings.json                      # MCP servers, hooks, permissions
  keybindings.json                   # Keyboard shortcuts
  projects//memory/MEMORY.md   # Project-specific persistent memory

/
  CLAUDE.md                          # Project instructions
  .claude/commands/                  # Custom skills (slash commands)

Built-in Commands

/help          Show help
/plan          Enter plan mode (review before Claude acts)
/memory        View/edit project memory
/settings      Open settings
/clear         Clear conversation history

Key Concepts (5-Second Version)

Concept What It Does When to Use
CLAUDE.md Project rules Claude reads every session Set it up once at project start
Plan Mode Claude designs approach, you approve Any non-trivial task (3+ files)
Memory Knowledge persists across sessions After discovering patterns
Hooks Auto-run scripts on events Notifications, validation, logging
MCP Servers Give Claude new tools (DB, GitHub, etc.) Need external API/data access
Skills Reusable prompts via /command Repetitive workflows

Prompting Patterns

Bug Fixing

Context: [what it should do]
Symptom: [what's actually happening]
Location: file.ts:123
Fix: [scope constraint]

Feature Development

Add [feature] to [file].
Follow the pattern from [existing similar feature].
Don't touch [files to avoid].
Test with [test cases].

Code Review

Review the changes in this branch.
Check for: correctness, security, performance, style.
Output: Summary, Issues (critical/major/minor), Verdict.

Refactoring

Refactor [target] to [desired state].
Preserve: [what must not change]
Scope: only [these files]

CLAUDE.md Template (Minimal)

Markdown
# Project Name

## Tech Stack
- Language:
- Framework:
- Database:

## Project Structure
- /src/api — [description]
- /src/services — [description]

## Code Style
- [rule]
- [rule]

## Never Do This
- [forbidden pattern]
- [forbidden pattern]

## Development Commands
- Tests: `[command]`
- Dev: `[command]`

Full template: templates/CLAUDE.md


Common CLAUDE.md Rules

Communication:

Markdown
## Communication Style
- Be concise. Prefer bullets over paragraphs.
- No emoji.

Tools:

Markdown
## Development Tools
- Package manager: bun (never npm)
- Linter: biome (never eslint)

Git:

Markdown
## Git Workflow
- Conventional commits: feat:, fix:, chore:
- Never push to main
- Never use --no-verify

Architecture:

Markdown
## Architecture Rules
- No business logic in routes — use services
- All DB access via repositories
- Services never call each other — use events

MCP Server Quick Config

JSON
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..." }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://..."]
    }
  }
}

Hook Quick Config

JSON
{
  "hooks": {
    "Stop": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "powershell.exe -File ~/.claude/hooks/notify.ps1"
          }
        ]
      }
    ]
  }
}

Exit codes:

  • 0 = success, continue
  • 1 = warning, continue
  • 2 = block Claude from proceeding

Efficiency Patterns

Parallel requests:

Read these 3 files in parallel: A, B, C
Then tell me [question].

Batching:

Do all of these in one go:
1. [task]
2. [task]
3. [task]

Research then implement:

Phase 1: Research [topics]. Don't write code yet.
Phase 2: Based on research, implement [feature].

Plan Mode Workflow

You:    "I need to [task]"
Claude: [presents plan]
You:    "Approved" OR "Change step 3 to [revision]"
Claude: [implements]

Always use for:

  • 3+ file changes
  • Architecture decisions
  • Database migrations
  • Git operations (merge, rebase)
  • Deletions

Memory Management

Add to memory:

"Remember: we use Prisma, not raw SQL"

Check memory:

"What do you know about this project from memory?"

Correct memory:

"Forget what you saved about X — we changed it to Y"

Memory vs CLAUDE.md:

  • CLAUDE.md = stable rules you define upfront
  • MEMORY.md = discoveries Claude makes during work

Custom Skills (Slash Commands)

Create: ~/.claude/commands/skill-name.md

Markdown
[Instructions for Claude when /skill-name is invoked]

Use $ARGUMENTS for user input after the command.

Invoke: /skill-name some arguments

Popular skills:

  • /commit - Create conventional commit
  • /review - Code review current branch
  • /debug - Systematic debugging workflow
  • /explain - Deep code explanation

Troubleshooting Quick Fixes

Problem Fix
Claude asks known questions Add answers to CLAUDE.md
Wrong architectural choice Add architecture rules to CLAUDE.md
Went down wrong path Use Plan Mode next time
Can't find files Tell exact path, add to "Key Files" in CLAUDE.md
Tests broke "Read test output and fix failures"
Too many changes Constrain scope: "Only change X"
Wrong tool used Add tool preferences to CLAUDE.md
Forgot earlier context Start new session, save to MEMORY first
Too verbose Add communication style to CLAUDE.md

Model Selection

  • Haiku for high-volume, latency-sensitive, or simple tasks (classify, extract, summarize)
  • Sonnet is the right default for most coding and reasoning work
  • Opus for genuinely hard problems -- architecture, complex debugging, security audits
  • Haiku is roughly 60x cheaper than Opus; Sonnet is about 5x Haiku
  • Start with Sonnet, downgrade to Haiku once quality is validated, upgrade to Opus only when Sonnet fails
  • Check anthropic.com/pricing for current rates

Extended Thinking

  • Enable with thinking: {"type": "enabled", "budget_tokens": N} in API calls
  • Available on both Opus and Sonnet
  • Thinking tokens are billed at output token rates (not input)
  • Best for multi-step reasoning, debugging subtle bugs, tradeoff analysis
  • Don't enable by default -- reserve for problems where quality improvement justifies cost

Prompt Caching

  • Mark stable content with cache_control: {"type": "ephemeral"} to cache it
  • Cache reads cost ~10% of normal input price; cache writes cost ~125%
  • Put stable content first, dynamic content last (cache is prefix-keyed)
  • Minimum cacheable length: 1,024-2,048 tokens (model-dependent)
  • Max 4 cache breakpoints per request; 5-minute default TTL

Tool Use (Agentic Patterns)

  • Define tools as JSON schemas; Claude decides when to call them
  • Use a tool-call loop: send message, handle tool calls, feed results back
  • Validate tool inputs before executing; sandbox untrusted operations
  • Set reasonable max_tokens and loop limits to prevent runaway agents
  • Combine with model routing: Haiku for simple tool calls, Opus for complex planning

System Prompts

  • System prompts set persistent behavior for the entire conversation
  • Put stable instructions (persona, rules, constraints) in the system prompt
  • Cache system prompts for cost savings on repeated calls
  • Keep system prompts focused -- overly long prompts dilute the signal
  • Use system prompts for "what" and "how"; use user messages for "do this now"

Advanced Patterns

Test-Driven Development:

Here are the tests. Make them pass. Don't modify tests.

Self-Review:

Review your own implementation for:
correctness, edge cases, security, performance.
Suggest top 3 improvements.

Reflection:

Summarize what we built today.
What's incomplete? What's fragile?
What should be added to CLAUDE.md?

Living Spec: Maintain SPEC.md with current requirements. Claude reads it.

Architectural Decisions: Maintain DECISIONS.md with ADRs (Architecture Decision Records).


Expert Habits

  1. Invest in CLAUDE.md - Highest leverage activity
  2. Use Plan Mode - For anything non-trivial
  3. Be specific - File:line references, exact constraints
  4. Parallelize - Ask for multiple things at once
  5. Maintain memory - Capture learnings
  6. Update after mistakes - Add rule to CLAUDE.md
  7. Review before trusting - Self-review pattern
  8. Think in batches - Combine independent tasks

File Sizes to Watch

  • CLAUDE.md: Keep under ~200 lines (loaded every session)
  • MEMORY.md: Keep under ~200 lines (first 200 auto-loaded)
  • Long memory? Break into topic files

Getting Help


The Core Loop

1. Notice issue
2. Add rule to CLAUDE.md
3. Issue never happens again
4. Repeat

Your productivity compounds over time.


Print this. Keep it visible. Reference it daily.