Claude Code Cheatsheet

Every command, shortcut, syntax pattern, and copy-paste prompt you need — all in one place. Bookmark this page and come back whenever you need a quick reminder.

Jump to: Installation · Slash Commands · Keyboard Shortcuts · CLAUDE.md Template · Hook Syntax · Subagents · MCP Setup · Workflow Prompts · Deep-Dive Guides


Installation & Setup

You need Node.js 18+ installed first. Full guides: Mac → | Windows →

Mac / Linux


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

# Launch
claude

# Check version
claude --version

Windows (use WSL2)


# Install WSL2 first
wsl --install

# Then in WSL terminal:
npm install -g @anthropic-ai/claude-code
claude

Useful launch flags


# Start with a specific model
claude --model claude-sonnet-4-6

# Skip confirmation prompts (use carefully)
claude --dangerously-skip-permissions

# Print mode — run one prompt, no interactive session
claude -p "your prompt here"

Built-in Slash Commands

Type these directly in the Claude Code prompt. Full guide →

Command What it does
`/help` List all available commands and keyboard shortcuts
`/clear` Clear the conversation history and start a fresh context
`/compact` Summarise the current conversation to save context window space
`/status` Show token usage, model name, and current session info
`/cost` Display how many tokens and how much money this session has used
`/model` Switch to a different Claude model mid-session
`/review` Ask Claude to review the last changes it made
`/undo` Revert the last file change Claude made
`/diff` Show a diff of all changes made in this session
`/plan` Switch to Plan Mode — Claude explains before acting
`/exit` End the session

Keyboard Shortcuts

Shortcut Action
`↑` / `↓` Scroll through previous prompts in history
`Ctrl + C` Stop Claude mid-response or cancel current action
`Ctrl + L` Clear the terminal screen (keeps context)
`Ctrl + R` Search through prompt history
`Ctrl + D` Exit Claude Code (same as `/exit`)
`Tab` Autocomplete slash command names
`Shift + Enter` Insert a newline without sending the message
`Esc` Cancel current input without sending

CLAUDE.md Template

Place this file in your project root as CLAUDE.md. Customise every section for your project. Full guide →


# CLAUDE.md — Project instructions for Claude Code

## Project overview
This is a [type] app built with [stack].

## Tech stack
- Language: TypeScript
- Framework: Next.js 14
- Database: PostgreSQL via Prisma
- Testing: Vitest

## Coding rules
- Always use TypeScript — never plain JavaScript
- Use async/await, never .then() chains
- Write a test for every function you create
- Never edit files inside /vendor/ or /generated/

## Commands
- Run tests: `npm test`
- Start dev server: `npm run dev`
- Build: `npm run build`
- Lint: `npm run lint`

## File structure notes
- API routes live in /src/app/api/
- Shared types live in /src/types/
- DB schema is in /prisma/schema.prisma

## What NOT to do
- Never commit directly to main
- Never use console.log in production code
- Never hard-code credentials — use .env

Hook Syntax Reference

Create a .claude/hooks.json file in your project root. Full guide →


{
  "hooks": {

    "PreToolUse": [
      {
        "matcher": { "tool_name": "bash" },
        "command": "python3 .claude/hooks/check_command.py"
      }
    ],

    "PostToolUse": [
      {
        "matcher": { "tool_name": "write_file" },
        "command": "npm run lint -- --fix"
      }
    ],

    "Stop": [
      {
        "command": "npm test -- --passWithNoTests"
      }
    ]

  }
}

The hook command can be any shell command or script. Exit code 0 = allow, non-zero = block (PreToolUse only).

Hook types at a glance:

Hook When it fires Common use
`PreToolUse` Before Claude uses a tool Block dangerous commands, check permissions
`PostToolUse` After Claude uses a tool Auto-format, log changes, run follow-up scripts
`Stop` When Claude finishes a task Run tests, send notifications, generate reports

Subagents

Spawn helpers and fork context for parallel work. Full guide →


# Spawn a subagent with a specific task
@agent "audit the /src/api/ folder for SQL injection vulnerabilities
        and write a report to /reports/security.md"

# Fork the current context into a subagent
# (the subagent inherits everything known so far)
context:fork "refactor the AuthService class to use the repository pattern"

# Spawn multiple subagents for parallel work
@agent "write unit tests for /src/services/user.service.ts"
@agent "write unit tests for /src/services/auth.service.ts"
@agent "write unit tests for /src/services/email.service.ts"

# Give a subagent a named role
@agent:reviewer "review the changes in the last commit for security issues"

MCP Server Setup

Connect Claude Code to external tools and services. Full guide → | MCP Registry →


# Add an MCP server (npx-based, most common)
claude mcp add github -- npx -y @modelcontextprotocol/server-github

# Add an MCP server globally (available in all projects)
claude mcp add --global slack -- npx -y @modelcontextprotocol/server-slack

# Add an MCP server with environment variables
claude mcp add notion \
  --env NOTION_TOKEN=your_token_here \
  -- npx -y @modelcontextprotocol/server-notion

# List all connected MCP servers
claude mcp list

# Remove an MCP server
claude mcp remove github

# Check MCP server status
claude mcp status

Common Workflow Prompts

Copy, paste, and adjust to fit your project. More workflows →

Bug fix


Find and fix the bug causing [describe error]. Show me what you changed and why.

Write tests


Write comprehensive tests for [filename]. Cover happy paths, edge cases, and error states. Use [Jest/Vitest/pytest].

Refactor


Refactor [filename] to be cleaner and more maintainable. Don't change any behaviour — just improve the structure. Explain what you changed.

Add documentation


Add JSDoc comments to every exported function in [filename]. Be concise but include params, return types, and a one-line description.

Security audit


Audit [filename or folder] for security vulnerabilities. Check for SQL injection, XSS, insecure dependencies, and exposed secrets. Write a prioritised report.

New feature


Build [feature description]. Use our existing patterns (check CLAUDE.md). Write tests alongside the code. Don't touch any files outside [folder].

Database migration


Create a database migration to [describe change]. Include both the UP and DOWN migration. Check existing migrations first to follow our naming convention.

Code review


Review the changes in [filename or recent diff]. Check for bugs, security issues, performance problems, and anything that breaks our coding standards in CLAUDE.md.

Deep-Dive Guides

Topic Guide
 Getting Started [Getting Started Guide](https://claudecodebeginner.com/claude-code-beginners-guide/)
 How It Works [How Claude Code Works](https://claudecodebeginner.com/how-claude-code-works-guide/)
 CLAUDE.md [CLAUDE.md Complete Guide](https://claudecodebeginner.com/claude-md-complete-guide/)
 Slash Commands & Skills [Slash Commands Guide](https://claudecodebeginner.com/claude-code-slash-commands-guide/)
 Hooks [Hooks Guide](https://claudecodebeginner.com/claude-code-hooks-guide/)
 Subagents [Subagents Guide](https://claudecodebeginner.com/claude-code-subagents-guide/)
 MCP [MCP Guide](https://claudecodebeginner.com/claude-code-mcp-guide/)
 Workflows [Workflows Guide](https://claudecodebeginner.com/claude-code-workflows-guide/)
 Glossary [Every term defined](https://claudecodebeginner.com/glossary/)
 Pricing [Claude Code Pricing](https://claudecodebeginner.com/claude-code-pricing/)