← Claude Code

Claude Code 2.1 Cheat Sheet

Complete reference for Claude Code CLI tool. Updated for v2.1.x (January 2026).

---

What's New in v2.1

Major Features:
  • MCP Tool Search — Lazy loading for tools, reducing context usage from ~134k to ~5k tokens
  • Background Agents — Run up to 15 agents in parallel (Ctrl+B)
  • Task Management — Built-in task tracking with dependencies (/tasks)
  • Skill Hot-Reload — Skills update without restart
  • Forked Contextcontext: fork for isolated sub-agent execution
  • Hooks in Frontmatter — Define hooks directly in skills, commands, and agents
  • Setup Hooks — New event triggered via --init, --init-only, --maintenance
  • Wildcard PermissionsBash(npm ), Bash( --help), etc.
  • PR Review Status — Colored dot showing PR state in prompt footer
  • Language Setting — Configure Claude's response language
  • Customizable Keybindings/keybindings command
  • Web Session Teleport/teleport to claude.ai/code
  • Shift+Enter — Works out-of-the-box (iTerm2, WezTerm, Ghostty, Kitty)
New CLI Flags: --agents, --json-schema, --fallback-model, --max-budget-usd, --remote, --teleport, --init, --maintenance, --chrome, --fork-session, --tools New Slash Commands: /keybindings, /tasks, /plan, /stats, /context, /feedback, /rename, /teleport, /remote-env

---

Core CLI Commands

CommandDescription
claudeStart interactive REPL
claude "query"One-shot prompt, no REPL
claude -p "query"Print mode — output and exit
claude -cContinue last conversation
claude --resume <id>Resume a specific session
claude --model <model>Use specific model (sonnet/opus/haiku)
claude --allowedTools <tools>Restrict available tools
claude --agents <path>Add custom agent definitions
claude --initRun setup hooks only
claude --maintenanceRun maintenance tasks
claude --teleportSend session to claude.ai/code
claude --fork-session <id>Fork from specific session
claude --remote <url>Connect to remote session
claude mcpManage MCP servers
claude configView/set configuration
claude config set <key> <value>Update config value
claude config resetReset to defaults
---

CLI Flags (Detailed)

Model & Budget

  • --model <name> — sonnet (default), opus, haiku
  • --fallback-model <name> — Model to use if primary fails
  • --max-budget-usd <amount> — Hard stop at dollar limit
  • --max-turns <N> — Limit agentic turns (default: 100)

Permissions & Safety

  • --no-permissions — Use default permissions
  • --dangerously-skip-permissions — Skip all prompts (use carefully!)
  • --allowedTools <tool1,tool2> — Whitelist specific tools
  • --forbiddenTools <tool1,tool2> — Blacklist specific tools

Context & Session

  • --continue / -c — Continue last conversation
  • --resume <id> — Resume specific session
  • --fork-session <id> — Fork from session, keep transcript
  • --add-dir <path> — Add additional working directory
  • --remote <url> — Connect to remote session
  • --teleport — Send to claude.ai/code (web UI)

Output & Verbosity

  • --print / -p — Print mode (non-interactive)
  • --verbose — Show full tool calls
  • --output-format json — JSON output (for scripting)
  • --json-schema — Output JSON schema for responses

Tools & Agents

  • --agents <path> — Load custom agent definitions
  • --tools <plugin:tool> — Load specific MCP tools
  • --init — Run setup hooks only
  • --init-only — Setup hooks, then exit
  • --maintenance — Run maintenance tasks

Browser & Advanced

  • --chrome — Enable Chrome MCP plugin
  • --no-cache — Disable prompt caching
---

Slash Commands (Inside REPL)

Core Commands

CommandDescription
/helpShow all available commands
/clearClear conversation context
/compactCompress conversation (reduce tokens)
/costShow token usage and cost
/statsShow detailed session statistics
/statusShow session status
/copyCopy last response to clipboard
/contextView current context summary

Model & Configuration

CommandDescription
/modelSwitch model mid-conversation
/permissionsView and manage permissions
/keybindingsCustomize keyboard shortcuts
/rename <name>Rename current session
/feedbackSend feedback to Anthropic

Memory & Files

CommandDescription
/memoryEdit CLAUDE.md memory file
/cd <path>Change working directory
/lsList files in current directory

Git & Code Review

CommandDescription
/commitCommit staged changes with AI message
/prCreate a pull request
/reviewCode review current changes
/review-pr <number>Review a PR by number
/simplifyReview and simplify changed code

Advanced Features

CommandDescription
/planEnter planning mode (approve before edit)
/tasksView task list and dependencies
/teleportSend session to claude.ai/code
/remote-envConnect to remote environment
/batch <file>Execute batch commands from file
---

Agent Teams (Subagents)

Claude Code can spawn multiple agents to work in parallel or specialize tasks.

Built-in Agent Types

Agent TypeTools AvailableUse Case
general-purposeAll tools (Read, Write, Edit, Bash, etc.)Full implementation tasks
ExploreRead-only (Read, Glob, Grep)Codebase exploration, search
PlanRead-only + planning toolsArchitecture planning, design
statusline-setupRead, EditConfigure status line

Team Workflow

1. Create teamTeamCreate tool 2. Create tasksTaskCreate with dependencies 3. Spawn teammatesAgent tool with team_name parameter 4. Assign tasksTaskUpdate with owner field 5. Coordinate — Teammates communicate via SendMessage 6. Shutdown — Send shutdown_request when done

Example: Parallel Work

- Teammate A: Implement backend API
  • Teammate B: Build frontend UI
  • Teammate C: Write tests

Task Management Commands

  • TaskCreate — Create new task
  • TaskList — List all tasks
  • TaskUpdate — Update task status/owner
  • SendMessage — DM or broadcast to teammates
---

Hooks System

Hooks run shell commands on specific events. Configure in .claude/settings.json or skill frontmatter.

Hook Events

EventWhen it fires
PreToolUseBefore any tool runs
PostToolUseAfter any tool runs
NotificationOn agent notifications
StopWhen agent stops
SetupOn --init, --init-only, --maintenance
SubmitPromptWhen user submits prompt

Hook Configuration (settings.json)

{
  "hooks": {
    "PostToolUse": {
      "Write": "echo 'File written: {{file_path}}'",
      "Edit": "prettier --write {{file_path}}"
    },
    "Setup": "npm install && npm run build"
  }
}

Hook Variables

  • {{file_path}} — File being operated on
  • {{command}} — Bash command being run
  • {{content}} — Tool content/result

Frontmatter Hooks (Skills/Commands/Agents)

---
name: my-skill
hooks:
  PreToolUse:
    Bash: echo "Running bash command"
---

---

Keyboard Shortcuts

Default Bindings

ShortcutAction
EnterSend message
Shift+EnterNew line (iTerm2, WezTerm, Ghostty, Kitty)
EscapeCancel current action
Ctrl+CInterrupt generation
Ctrl+LClear screen
Ctrl+RSearch history
Ctrl+BView background agents
TabAccept autocomplete
Up/DownNavigate history

Customizable Keybindings

Use /keybindings command or edit ~/.claude/keybindings.json:
{
  "toggleTodos": "ctrl+shift+t",
  "toggleTranscript": "ctrl+shift+x",
  "searchHistory": "ctrl+/",
  "chatStash": "ctrl+shift+s"
}

---

Configuration Files

FilePurpose
CLAUDE.mdProject instructions (root)
.claude/settings.jsonProject settings
~/.claude/CLAUDE.mdGlobal user instructions
~/.claude/settings.jsonGlobal settings
~/.claude/keybindings.jsonCustom keyboard shortcuts
.claude/commands/.mdCustom slash commands
.claude/skills//SKILL.mdAgent skills (auto-invoked)
.claude/agents/*/AGENT.mdCustom agent definitions

CLAUDE.md Structure

  • User preferences and environment context
  • Project-specific instructions
  • Code style guidelines
  • Forbidden actions (e.g., "don't run tests on commit")

settings.json Options

{
  "model": "sonnet",
  "maxTurns": 100,
  "permissionMode": "default",
  "language": "en",
  "hooks": { / ... / },
  "allowedTools": ["Read", "Write", "Edit"],
  "forbiddenTools": ["Bash"]
}

---

Skills vs Commands vs Agents

Commands (User-Invoked)

  • Location: .claude/commands/<name>.md
  • Invocation: /command-name
  • Examples: /commit, /review-pr, /simplify
Frontmatter:
---
allowed-tools: Read, Write, Edit
description: Review and simplify code changes
---

Skills (Model-Invoked)

  • Location: .claude/skills/<name>/SKILL.md
  • Invocation: Automatic (model decides)
  • Examples: claude-developer-platform, frontend-design
Frontmatter:
---
name: frontend-design
description: Build production-grade UIs
triggers:
  - user asks to build web components
  - user mentions React/Vue/Svelte
allowed-tools: Read, Write, Edit, Bash
---

Agents (Custom Subagent Types)

  • Location: .claude/agents/<name>/AGENT.md
  • Invocation: Via Agent tool with subagent_type
  • Examples: Custom test runners, specialized reviewers
Frontmatter:
---
name: test-runner
description: Runs tests and reports results
allowed-tools: Read, Bash
context: fork
---

---

Worktree Patterns

Use EnterWorktree to work in isolated git worktrees:

# User says: "work in a worktree"
claude uses EnterWorktree

Creates: .claude/worktrees/<name>

On exit: prompt to keep or remove

When to Use Worktrees

  • Experimental changes without affecting main branch
  • Parallel feature development
  • Testing risky refactors
---

/simplify Command

Purpose: Review changed code for reuse, quality, and efficiency. Workflow: 1. User invokes /simplify 2. Reviews git diff 3. Identifies: - Duplicate code → Extract helpers - Over-engineering → Simplify abstractions - Missing error handling → Add validation - Performance issues → Optimize Auto-applies fixes — No confirmation needed.

---

/batch Command

Purpose: Execute multiple prompts from a file sequentially. Usage:
# Create batch.txt
echo "Add logging to user.ts" > batch.txt
echo "Write tests for auth.ts" >> batch.txt
echo "Update README with new API" >> batch.txt

Execute

/batch batch.txt

Each line is executed as a separate prompt in order.

---

MCP Plugin System

Model Context Protocol — Extend Claude with external tools.

Manage Plugins

claude mcp add <plugin-name>
claude mcp remove <plugin-name>
claude mcp list

Popular Plugins

  • filesystem — Enhanced file operations
  • github — GitHub API integration
  • postgres — Database queries
  • brave-search — Web search
  • chrome — Browser automation (--chrome flag)

Lazy Loading (v2.1)

Tools are loaded on-demand via ToolSearch instead of all-at-once, reducing context from ~134k to ~5k tokens.

---

HTTP API (Remote Sessions)

Run Claude Code as an HTTP server for remote access:

claude --remote http://0.0.0.0:8080
Endpoints:
  • POST /messages — Send message
  • GET /sessions — List sessions
  • GET /sessions/:id — Get session details
Connect from another machine:
claude --remote http://remote-ip:8080

---

Tips & Best Practices

Performance

  • Use --max-turns to prevent runaway loops
  • Use /compact to compress context when approaching limits
  • Prefer Explore agent over general-purpose for read-only tasks

Security

  • Never use --dangerously-skip-permissions in shared environments
  • Use .gitignore to exclude .claude/ from version control (or commit selectively)
  • Review CLAUDE.md before sharing projects

Collaboration

  • Commit .claude/CLAUDE.md for team-shared instructions
  • Use hooks to enforce code style (prettier, eslint)
  • Use /plan mode for high-impact changes

Debugging

  • Use /stats to see token usage breakdown
  • Use --verbose to inspect tool calls
  • Check .claude/sessions/*.jsonl for full transcripts
---

Common Workflows

1. Quick Fix

claude "Fix the bug in auth.ts where tokens expire too soon"

2. Code Review

# Make changes, then:
/review
/simplify
/commit

3. Feature Development

claude
> /plan
> [Review plan]
> Approve
> [Implementation begins]
> /commit
> /pr

4. Multi-Agent Parallel Work

claude
> Create a team to build a REST API with tests
> [Spawns backend, frontend, test agents]
> [Agents work in parallel]
> [Review final output]

---

Troubleshooting

"Context too large" error

  • Use /compact to compress
  • Reduce conversation length with /clear
  • Use --max-turns to limit agent loops

Agent stuck in loop

  • Ctrl+C to interrupt
  • Review task list with /tasks
  • Simplify prompt or break into smaller steps

Hooks not firing

  • Check .claude/settings.json syntax
  • Ensure hook scripts are executable
  • Check hook output in console (--verbose)

MCP plugin not loading

  • Verify plugin is installed: claude mcp list
  • Check plugin config in ~/.claude/mcp.json
  • Try --tools <plugin:tool> to load explicitly
---

Resources

  • Official Docs: https://docs.claude.ai/code
  • GitHub: https://github.com/anthropics/claude-code
  • Changelog: https://github.com/anthropics/claude-code/releases
  • Community: https://discord.gg/anthropic