Claude Code Cheatsheet

Complete reference for Anthropic's agentic coding assistant

Claude Code is an agentic coding tool that lives in your terminal. It understands your codebase, can edit files, run commands, and help you code faster with AI. This cheatsheet covers CLI commands, keyboard shortcuts, configuration, MCP integrations, hooks, subagents, skills, plugins, and best practices.

175

Commands

15

Categories

0

Favorites

38

Sections

Terminal Native

Lives in your terminal

Codebase Aware

Understands your code

MCP Extensible

50+ integrations

Automation Ready

Hooks & headless mode

Getting Started
Installation
npm install -g @anthropic-ai/claude-code

Install via npm (Node.js 18+)

curl -fsSL https://claude.ai/install.sh | bash

Install via curl (macOS/Linux)

brew install --cask claude-code

Install via Homebrew (macOS)

irm https://claude.ai/install.ps1 | iex

Install via PowerShell (Windows)

Getting Started
Launch & Update
cd your-project && claude

Start Claude Code in project

claude update

Update to latest version

claude --version

Check version

claude --help

Show help

CLI Commands
Session Control
claude

Start interactive REPL session

claude "query"

Start with initial prompt

claude -p "query"

Print mode - execute and exit

claude -c

Continue most recent conversation

claude -c -p "query"

Continue in print mode

claude --resume <id> -p "query"

Resume specific session

CLI Commands
Model & Output
--model sonnet

Use Sonnet model (faster)

--model opus

Use Opus model (more capable)

--output-format json

JSON output with metadata

--output-format stream-json

Stream JSON messages

--max-turns 3

Limit agentic turns

--verbose

Enable verbose logging

CLI Commands
Configuration CLI
claude config list

List current configuration

claude config get <key>

Check specific setting

claude config set <key> <value>

Change a setting

claude config add <key> <value>

Add to array settings

claude config remove <key> <value>

Remove from array

Shortcuts
Essential Keys
Esc

Interrupt/stop Claude

Esc + Esc

Open rewind menu (undo changes)

Ctrl+C

Cancel current operation

Ctrl+D

Exit Claude Code

Ctrl+R

Full output/context

Ctrl+V

Paste image

Shortcuts
Productivity
Shift+Tab

Auto-accept (yolo mode)

Shift+Tab+Tab

Plan mode

\

Line break (backslash + Enter)

Cmd+Esc / Ctrl+Esc

Quick launch in IDEs

Cmd+Option+K / Alt+Ctrl+K

Insert file references

Shortcuts
References & Shell
@file.txt

Reference a file

@./directory/

Reference directory

!

Bash mode prefix / toggle shell

!command

Run shell command

#note

Add memory quickly

Slash Commands
Session
/help

Show all commands

/clear

Clear conversation history

/exit

Exit the REPL

/compact [instructions]

Compact conversation with focus

/cost

Show token usage statistics

/status

View account and system status

/usage

Show plan usage and rate limits

Slash Commands
Configuration
/config

View/modify configuration

/permissions

View or update permissions

/model

Select or change AI model

/vim

Enter vim editing mode

/terminal-setup

Install Shift+Enter binding

/sandbox

Enable sandboxed bash tool

Slash Commands
Tools & Extensions
/mcp

Manage MCP servers and OAuth

/agents

Manage custom subagents

/plugin

Manage plugins

/memory

Edit CLAUDE.md memory files

/init

Initialize project with CLAUDE.md

/doctor

Check installation health

/bug

Report bugs to Anthropic

Slash Commands
Code & Review
/review

Request code review

/pr_comments

View pull request comments

/add-dir

Add working directories

/rewind

Rewind conversation/code

/login

Switch Anthropic accounts

/logout

Sign out

Checkpointing
Rewind Commands
Esc + Esc

Open rewind menu

/rewind

Open rewind via slash command

Checkpointing
Rewind Options
Conversation Rewind

Restore to previous message, keep code

Code Rewind

Revert file changes, keep conversation

Full Rewind

Restore both code and conversation

💡 Every user prompt creates a checkpoint automatically

Checkpointing
Limitations
Bash changes not tracked

rm, mv, cp cannot be undone

External changes not tracked

Manual edits outside Claude

Not version control

Use Git for permanent history

Config Files
Settings Priority (High→Low)
/etc/claude-code/managed-settings.json

Enterprise (highest priority)

.claude/settings.local.json

Project local (git-ignored)

.claude/settings.json

Project shared (team)

~/.claude/settings.json

User global (defaults)

Config Files
Memory & Commands
~/.claude/CLAUDE.md

Global memory file

./CLAUDE.md

Project memory file

.claude/commands/

Project slash commands

~/.claude/commands/

Personal slash commands

Config Files
Agents & Skills
.claude/agents/

Project subagents

~/.claude/agents/

Personal subagents

.claude/skills/

Project skills

~/.claude/skills/

Personal skills

.mcp.json

Project MCP servers

Permissions
Permission Flags
--allowedTools

Allow specific tools

--disallowedTools

Block specific tools

--dangerously-skip-permissions

Skip all prompts (caution!)

Permissions
Permission Levels
allow

Auto-approve without asking

ask

Prompt user for approval

deny

Block completely

💡 Use glob patterns: Write(src/**), Bash(npm *)

Permissions
Common Denials
Read(./.env*)

Block env files

Read(./secrets/**)

Block secrets directory

Bash(rm -rf:*)

Block destructive commands

Bash(curl:*)

Block network requests

MCP Servers
MCP Management
claude mcp add <name> <cmd> [args]

Add stdio MCP server

claude mcp add --transport sse <name> <url>

Add SSE server

claude mcp add --transport http <name> <url>

Add HTTP server

claude mcp list

List installed servers

claude mcp remove <name>

Remove server

MCP Servers
Popular MCP Servers
GitHub

Repos, PRs, issues

Figma

Design context for code

Notion

Docs, pages, tasks

Linear

Issue tracking

Sentry

Error monitoring

Vercel

Deployments, logs

MCP Servers
More Integrations
Supabase

Database operations

Playwright

Browser automation

Stripe

Payments

Slack

Messages, channels

Zapier

8,000+ app connections

Hooks
Hook Events
PreToolUse

Before tool calls (can block)

PostToolUse

After tool calls complete

UserPromptSubmit

Before processing user input

Notification

When Claude sends notifications

Stop

When Claude finishes responding

SubagentStop

When subagent tasks complete

SessionStart

When session starts/resumes

SessionEnd

When session ends

PreCompact

Before compact operation

Hooks
Hook Management
/hooks

Open hooks configuration

claude --debug

Debug hook execution

chmod +x .claude/hooks/script.sh

Make hook executable

💡 Exit codes: 0=success, 2=block & show to Claude

Subagents
Subagent Basics
/agents

Open subagents management

.claude/agents/

Project subagents (team shared)

~/.claude/agents/

Personal subagents

claude "Use the [name] subagent"

Explicitly invoke subagent

Subagents
Frontmatter Options
name:

Subagent identifier

description:

When to invoke (include 'proactively')

tools:

Allowed tools (Read, Edit, Bash...)

model:

Model override (sonnet, opus, inherit)

💡 Include 'proactively' in description for auto-invocation

Skills
Skill Basics
.claude/skills/skill-name/SKILL.md

Project skill definition

~/.claude/skills/skill-name/SKILL.md

Personal skill

💡 Skills are model-invoked (automatic), not user-invoked

Skills
Skill Frontmatter
name:

Skill identifier

description:

When Claude should use this skill

allowed-tools:

Tool restrictions (Read, Grep, Glob)

Plugins
Plugin Commands
/plugin

Open plugin management

/plugin marketplace add <url>

Add plugin marketplace

/plugin install <name>@<marketplace>

Install plugin

/plugin enable <name>@<marketplace>

Enable plugin

/plugin disable <name>@<marketplace>

Disable plugin

/plugin uninstall <name>@<marketplace>

Remove plugin

Plugins
Plugin Capabilities
Custom Commands

Add slash commands

Specialized Agents

Deploy expert subagents

Agent Skills

Package discoverable capabilities

Automation Hooks

Run scripts on events

MCP Servers

Connect external tools

Git Worktrees
Worktree Commands
git worktree add <path> <branch>

Create with existing branch

git worktree add <path> -b <branch>

Create with new branch

git worktree list

List all worktrees

git worktree remove <path>

Remove worktree

git worktree prune

Clean up references

Git Worktrees
Use Cases
Parallel Features

Work on multiple features simultaneously

Hotfix While Developing

Handle urgent fixes without context loss

Safe Experiments

Test risky changes in isolation

Model Comparison

Compare Sonnet vs Opus on same task

💡 Each worktree keeps full Claude context

Headless Mode
Automation Commands
claude -p "query"

Non-interactive, print and exit

claude -p --output-format json "query"

JSON output with metadata

echo "query" | claude -p

Process piped input

--append-system-prompt "..."

Add system context

--max-turns 3

Limit agentic turns

Headless Mode
CI/CD Examples
SRE Incident Response

Automated investigation

Security Audit

PR security review

Multi-turn Session

Maintain context across commands

💡 Use JSON formats for programmatic parsing

Best Practices
Efficiency
Use /clear often

Clear chat between tasks

Start different sessions

Separate sessions for tasks

Queue multiple prompts

Claude works through them

Use /compact

Summarize long conversations

Best Practices
Security
Deny dangerous tools

Block "Bash(rm *)", "Bash(sudo *)"

Use .local.json for secrets

Keep sensitive settings git-ignored

Review changes

Always verify modifications

Review hooks before adding

Hooks execute with your credentials

Quick Workflow

1. Install

npm i -g @anthropic-ai/claude-code

2. Start

cd project && claude

3. Context

@file or @dir/

4. Task

"fix the bug"

5. Review

verify changes

6. Clear

/clear

CLAUDE.md Memory File

# Project Context

## Tech Stack
- Next.js 15 with App Router
- TypeScript, Tailwind CSS

## Commands
- `pnpm dev` - Start dev server
- `pnpm test` - Run tests

## Coding Standards
- Use TypeScript for all new code
- Follow ESLint configuration

Auto-Format Hook

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{
        "type": "command",
        "command": "npx prettier --write $FILE_PATH"
      }]
    }]
  }
}

Custom Slash Command

.claude/commands/review.md:

---
allowed-tools: Read, Grep, Glob
description: Review code for issues
argument-hint: [file-or-feature]
---

Review this code for:
1. Security vulnerabilities
2. Performance issues
3. Best practices

Focus on: $ARGUMENTS

Subagent Definition

.claude/agents/code-reviewer.md:

---
name: code-reviewer
description: Expert code review. Use proactively after writing code.
tools: Read, Grep, Glob
model: inherit
---

You are a senior code reviewer.
Review checklist:
- Code is simple and readable
- Proper error handling
- No exposed secrets
- Good test coverage

Permission Settings

.claude/settings.json:

{
  "permissions": {
    "allow": [
      "Bash(npm run *)",
      "Bash(git *)"
    ],
    "deny": [
      "Read(./.env*)",
      "Read(./secrets/**)",
      "Bash(rm -rf:*)",
      "Bash(curl:*)"
    ]
  }
}

MCP Configuration

.mcp.json:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@anthropic-ai/mcp-server-github"],
      "env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
    },
    "notion": {
      "transport": "http",
      "url": "https://mcp.notion.com/mcp"
    }
  }
}

Pricing Tiers

Pro - $20/mo

Medium-high workload, limited Opus

Max5 - $100/mo

5x tokens, full Opus access

Max20 - $200/mo

20x tokens, larger context

💡 Sessions last 5 hours. Opus burns tokens faster. Use /clear between tasks and separate sessions for different work.