📡Learn-in-Depth
Back to Cheat Sheets📅 2026-06-1113 min read

Claude Code Cheat Sheet — every command and scenario on one page

#claude-code#anthropic#cli#coder-agents

The tool that ignited the terminal-agents market when Anthropic released it in February 2025. The idea: open a terminal inside your project, type what you want in plain language, and it reads, edits, runs, and fixes until the job is done.

Install & First Run

Command What it does
npm install -g @anthropic-ai/claude-code Install (Node 18+)
brew install claude-code Install via Homebrew (macOS)
claude Interactive session in current directory
claude "explain this repo" Start with a prompt
claude -p "generate a commit message" Non-interactive: answer and exit
claude -c Continue last conversation
claude -r Pick from previous conversations
claude update Update the CLI
claude --version Verify version

All Slash Commands

Session Management

Command Alias What it does Scenario
/help ? All available commands Forgot a command
/clear Wipe context, fresh start Between unrelated tasks
/compact Summarize conversation to save tokens Long job
/model Switch model (Opus / Sonnet / Haiku) Need stronger/cheaper
/cost Session spend so far Cost control
/status Current state: model, cost, tokens Quick check-up
/settings Configuration settings Change settings
/profile Switch between profiles Different projects
/exit or Ctrl+D /quit, q Quit Done for the day

Context Management (Most Important!)

Command What it does Scenario
/files Files Claude is currently tracking See what's in context
/add <file> Add file to context Important file not tracked
/drop <file> Remove file from context Free up space
/grep <pattern> Search codebase Find something
/find <name> Find file by name "Where's the auth file?"
/read <file> Read specific file Verify file content
/tree Directory tree Understand structure

Code Operations

Command What it does Scenario
/edit <file> Open file for editing Edit this
/diff Changes Claude made Review before commit
/undo Revert last edit Mistake
/redo Re-apply reverted edit Undone by mistake
/review AI code review Get AI review
/lint Run linter Verify quality
/test Run tests Verify nothing broke
/commit Stage + AI commit Quick commit

Memory & Configuration

Command What it does Scenario
/init Generate CLAUDE.md New project
/memory Edit memory files Update conventions
/permissions Manage tool permissions Control access
/agents Manage subagents Delegate work
/hooks Auto-run commands Automation
/mcp MCP server status Check integrations
/bash Execute bash directly Quick command

Plan Mode (For Big Tasks)

Command Alias What it does
/plan /p Enter Plan Mode
/execute Execute current plan
/next Execute next step
/skip Skip current step
/abort Cancel entire plan
/edit-plan Modify plan
/show Display current plan

Advanced / Hidden

Command What it does
/editor Open current task in $EDITOR
/debug Toggle debug mode
/export Save conversation as JSON
/tokens Per-message token breakdown
/vim Vim editing mode
/delegate "<task>" Spawn subagent
/agent <id> Switch to subagent
/kill <id> Kill subagent
/merge <id> Merge subagent results

Keyboard Shortcuts

Input Shortcuts

Key Action
Ctrl+C Cancel generation mid-run
Ctrl+D Exit Claude Code
Tab Autocomplete paths and commands
↑/↓ Navigate command history
Ctrl+R Search command history
Ctrl+L Clear screen
Shift+Enter New line in multi-line input

Approval Shortcuts (when Claude asks)

Key Action
y or Enter Yes / Approve once
n No / Deny
a Yes to all (remaining session)
d Show diff before deciding
e Edit command before executing
q Quit approval and cancel

Power User Shortcuts

Key Action
Esc Interrupt agent (pause, not quit)
Esc twice Rewind conversation — edit earlier message
Shift+Tab Cycle permission modes
# at line start Append note to CLAUDE.md instantly
! at line start Run bash command, output in chat
@ Mention file — path autocomplete

Approval Modes (Security!)

Full Approval (Default) — Safest

  • Every file write: y/n
  • Every shell command: y/n
  • Every external API: y/n
  • Use for: production codebases

Partial Approval — Balanced

  • File reads: automatic
  • File writes: require approval
  • Shell commands: require approval
  • Use for: active development

No Approval (--no-approval) — Dangerous ⚠️

  • Everything auto-executes
  • Use for: isolated containers/test environments ONLY!
  • Never on: your main machine

CLI Flags

Flag Alias What it does Scenario
--help -h Help
--version -v Version
--model <model> Start with specific model --model opus
--debug Debug mode from start
--no-approval Auto-approve everything ⚠️
--approval-mode <mode> full / partial / none
--profile <name> Start with profile
--plan Start in Plan Mode
--verbose Verbose output
--no-color Disable colors
--context <file> Preload file into context
--execute <command> Run single command and exit CI/CD
--silent No TUI — output only scripting
--batch <file> Execute JSON sequence automation
--offline No network (limited)
--recover Recover session after crash

Configuration

Config Files

File Purpose
~/.claude/config.json Global user config
~/.claude/profiles/<name>.json Profile-specific
./.claude/settings.json Project-specific
./.claude/ignore Files to ignore

Example config.json

{
  "model": "claude-3-7-sonnet",
  "approvalMode": "full",
  "autoUpdate": true,
  "theme": "dark",
  "editor": "vim",
  "maxContextTokens": 200000,
  "shell": "/bin/zsh",
  "aliases": {
    "test": "npm test",
    "build": "npm run build"
  }
}

Environment Variables

Variable Purpose
ANTHROPIC_API_KEY API key (required)
CLAUDE_MODEL Default model
CLAUDE_DEBUG Enable debug
CLAUDE_NO_COLOR Disable colors
CLAUDE_EDITOR Default editor
CLAUDE_SHELL Default shell
CLAUDE_PROFILE Default profile

Plan Mode — Deep Dive

When to use: Any task > 3 files or > 5 steps

How it works:

  1. Describe Goal: You say what you want
  2. Claude Proposes Plan: Numbered list of steps
  3. Review & Edit: You modify, reorder, or delete
  4. Execute: Claude executes step by step with approval
  5. Checkpoint: After each step: /undo, /skip, /abort

Example:

> /plan
> Refactor all callback-style async code in src/ to async/await

Claude:
Plan:
1. Identify all files with callback patterns
2. Convert each to async/await
3. Run tests to verify
4. Handle edge cases

> /execute
[Claude executes step 1… approval… step 2… approval…]

Subagents — Branching

Claude Code can spawn subagents — separate instances working on delegated tasks:

Command What it does
/delegate "<task>" --name <name> Spawn subagent
/agents List active subagents
/agent <id> Switch to subagent
/kill <id> Kill subagent
/merge <id> Merge results into main

Patterns:

  • Parallel: Subagents on different files simultaneously
  • Sequential: Subagent finishes → results fed to parent
  • Hierarchical: Parent → subagent → sub-subagent

Hooks — Automation

Git Hooks

claude --install-hook pre-commit
Hook What it does
pre-commit Claude reviews staged changes
post-commit Claude generates PR description
prepare-commit-msg Claude writes commit message

Custom Hooks

Add to ./.claude/hooks/:

#!/bin/bash
# .claude/hooks/before-edit
npm run lint -- --fix
Event When it fires
before-edit Before Claude edits any file
after-edit After editing
before-command Before shell command
after-command After shell command
before-commit Before commit

MCP (Model Context Protocol)

Built-in MCP Servers

Server Capability
filesystem Read/write local files
shell Execute shell commands
git Git operations
github GitHub API
fetch HTTP requests
browser Web browsing

Custom MCP Servers

Create ~/.claude/mcp.json:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": { "DATABASE_URL": "postgresql://..." }
    },
    "slack": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-slack"],
      "env": { "SLACK_TOKEN": "xoxb-..." }
    }
  }
}

Practical Scenarios

Scenario 1: Refactoring (Plan Mode)

> /plan
> Refactor all callback-style async code in src/ to async/await
[Claude plans… you approve… /execute]

Scenario 2: Debugging

> The tests in auth.test.js are failing. Find and fix the bug.
Claude: I'll run the tests, analyze the error, and trace through...
[Reads → runs → finds bug → fixes → tests]

Scenario 3: Code Review

> Review the changes in this branch for security issues
> /diff
Claude: Analyzing 12 changed files... Found 2 potential SQL injection vectors...

Scenario 4: Documentation

> Generate API documentation from the OpenAPI spec and update the README
[Claude reads spec → generates docs → updates README]

Scenario 5: Learning a Codebase

> Explain the architecture of this project. Start with the entry points.
> @src/main.js what does this do?
> /tree

Scenario 6: Test Generation

> Write comprehensive tests for src/services/payment.js
> Coverage should include edge cases and error handling
[Claude writes tests → runs them → fixes edge cases]

Scenario 7: CI/CD Integration (Non-interactive)

# Non-interactive mode for CI
claude --execute "Review the PR diff and report issues" --no-approval < diff.patch

Scenario 8: Multi-tasking (Subagents)

> /delegate "Audit all API routes for missing auth checks" --name security-audit
> Meanwhile, refactor the database layer to use connection pooling
[Subagent works on security + Claude works on refactor simultaneously]

Scenario 9: Cost Control

> /cost
Session cost: $0.18 · 42.3k tokens

> /compact
[Summarizes conversation → frees context → continues]

Scenario 10: Custom System Prompt

# In ~/.claude/prompts/custom.md:
You are a senior Rust engineer. Always suggest idiomatic solutions.

> /prompt custom
> Rewrite this Go function in Rust

Hidden / Lesser-Known Features

# Tip How
1 Silent mode claude --silent < script.txt — no TUI
2 Batch mode claude --batch commands.json — command sequence
3 Export conversation /export > session.json — save for analysis
4 Import context claude --context previous-session.json
5 Custom prompts ~/.claude/prompts/custom.md + /prompt custom
6 Workspace presets claude --save-preset "react-app" + --load-preset
7 Token analytics /tokens — per-message breakdown
8 Diff side-by-side /diff --side-by-side
9 Auto-save Saves to ~/.claude/sessions/--recover after crash
10 Network isolation claude --offline — limited functionality
11 Plugin system claude --plugin @anthropic-ai/plugin-eslint
12 @-mentions @src/utils/helpers.js or @UserController — focus on code

Troubleshooting

Issue Solution
"Context full" /compact or /clear
Slow responses /drop unused files
Wrong file edits /undo + be more specific
Claude not finding files /add to explicitly include
Approval fatigue Switch to partial approval
API errors Check ANTHROPIC_API_KEY
Permission denied Check permissions or use sudo

The Verdict

Top 3 productivity movers (in order):

  1. Good CLAUDE.md — write your project conventions, commands, architecture
  2. /clear between tasks — clean context = better decisions
  3. Plan Mode for big changes/plan → plans → you approve → executes

Golden Rules:

  • Use /compact every 20-30 turns in long sessions
  • Use /add to pin critical files in context
  • Use @mentions to focus Claude on specific code
  • Use Subagents for parallelizable research
  • Use Hooks for automated lint/test before commit

Claude Code vs GitHub Copilot CLI:

Claude Code Copilot CLI
Concept "Fix this bug" "What do I want to do?"
Workflow Reads → edits → tests → fixes Generates command → you execute
Multi-file ✅ Deep ❌ One-shot
Plan mode
Subagents
Cost tracking
Git integration ✅ Deep ✅ Surface

Try the live demo below and see the workflow yourself. All the cheat sheets are here, and the full comparison lives on the Models page.

Try it live — interactive terminal
# Hit Play and watch the commands run…

🔗 Sources

🧭 Related to this