The Claude AI Community Discord is open.Join us

Claude Code Cheatsheet

Complete reference for commands, shortcuts, config, MCP servers, and more.

Getting Started

Install

bash
# macOS, Linux, WSL (recommended)
curl -fsSL https://claude.ai/install.sh | bash

# Homebrew
brew install --cask claude-code

# npm (global)
npm install -g @anthropic-ai/claude-code

# PowerShell (Windows)
irm https://claude.ai/install.ps1 | iex

Update

bash
claude update
claude --version

Launch

bash
claude
claude "explain this codebase"
claude --continue
claude --resume <session-id>

Keyboard Shortcuts

!Run a bash command directly
@Mention a file by path
\ EnterNew line without sending
EscInterrupt Claude, or close a dialog
Esc EscClear the draft, or open the rewind menu
Ctrl+RSearch your prompt history
Shift+TabCycle permission modes
Ctrl+CInterrupt, or clear the input
Ctrl+LRedraw the screen
Ctrl+DExit Claude Code
↑ / ↓Navigate input history
TabAccept an autocomplete suggestion

Permission modes (Shift+Tab)

defaultShown as Manual. Asks before tool calls that need permission
acceptEditsAccepts file edits without asking
planExplores and proposes a plan without editing files
autoA classifier approves or blocks actions, when available on your plan

Configuration

Config file priority (highest → lowest)

.claude/settings.local.jsonProject-local overrides (gitignored)
.claude/settings.jsonProject-level (committed to repo)
~/.claude/settings.jsonUser-level global defaults

Change settings from a session

bash
/config                 # open the settings screen
/config model=sonnet    # set a value directly
/config theme=dark
/config --help          # list the keys you can set

Example settings.json

json
{
  "model": "sonnet",
  "permissions": {
    "allow": ["Bash(npm test *)", "Bash(git diff *)"]
  }
}

Checkpointing

Rewind the conversation and all file changes to a previous state, like a session-level undo.

Esc EscOpen the rewind menu (on an empty prompt)
/rewindSame menu. Also available as /undo and /checkpoint

Limitations

  • Only affects files modified in the current session
  • Git commits are not automatically reverted
  • Shell side-effects (installs, migrations) are not undone
  • Cannot rewind past the start of the session

Slash Commands

Built-in

/helpShow all available slash commands
/clearStart a new conversation with empty context
/rewindRoll code and conversation back to a checkpoint (alias: /undo)
/compactCompress conversation history to save tokens
/memoryEdit CLAUDE.md files and auto memory
/permissionsShow and edit current tool permissions
/modelSwitch model and save it as your default
/usageShow session cost and plan limits (alias: /cost)
/exportExport conversation to a file
/doctorCheck your setup and fix common problems
/bugReport a bug to Anthropic
/code-reviewReview your changes or a PR for bugs (alias: /review)
/contextSee what is filling the context window
/initCreate a starter CLAUDE.md for the project

These are the basics. See all Claude Code commands explained for every slash command, CLI flag and shortcut.

Custom: .claude/commands/<name>.md

markdown
---
description: "Run all linters and fix auto-fixable issues"
allowed-tools: Bash
---

1. `npm run lint -- --fix`
2. `npm run type-check`
3. Summarise what was fixed.

Headless Mode

Use -p / --print for non-interactive use: CI, scripts, automation.

bash
claude -p "summarise the last commit"
cat README.md | claude -p "check for spelling errors"
claude -p "list all TODO comments" --output-format json
claude -p "explain main.go" --output-format stream-json

Output formats

--output-format textPlain text (default)
--output-format jsonFull JSON response object
--output-format stream-jsonStreaming NDJSON tokens

Pipeline examples

bash
# CI: fail if tests broken
claude -p "run tests and exit 1 if any fail" --allowedTools Bash

# Nightly summary
git log --since=yesterday --oneline | \
  claude -p "plain-English summary of today's commits" > summary.txt

# Auto PR review
gh pr diff | claude -p "review for bugs and security issues"

Agent Skills

Markdown files in ~/.claude/commands/ (global) or .claude/commands/ (project).

Frontmatter fields

descriptionShown in /help and skill picker
allowed-toolsComma-separated tools this skill may use
argument-hintPlaceholder shown after the slash command

commit.md

markdown
---
description: "Stage all changes and create a conventional commit"
allowed-tools: Bash, Read, Glob
argument-hint: "[optional: commit message]"
---

1. Run `git diff --staged` and `git status`.
2. If nothing is staged, run `git add -A`.
3. Write a conventional commit message.
4. Run `git commit -m "<message>"`.

review.md

markdown
---
description: "Review current branch diff for bugs and style issues"
allowed-tools: Bash, Read
---

1. Run `git diff main...HEAD`.
2. Check for: bugs, security, missing error handling, style.
3. Output grouped by severity.

Plugins

bash
claude plugins list
claude plugins install <plugin-name>
claude plugins install ./my-plugin
claude plugins remove <plugin-name>
claude plugins update

Structure

bash
my-plugin/
├── plugin.json
├── commands/
│   └── my-skill.md
└── mcp/
    └── my-server.json
json
{
  "name": "my-plugin",
  "version": "1.0.0",
  "description": "My custom plugin",
  "commands": ["commands/my-skill.md"],
  "mcpServers": ["mcp/my-server.json"]
}

MCP Servers

bash
claude mcp add <name> <command> [args...]
claude mcp add filesystem npx -y @modelcontextprotocol/server-filesystem /path
claude mcp remove <name>
claude mcp list

settings.json

json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path"],
      "env": {}
    }
  }
}

Popular servers

View all MCP servers in the directory

Git Worktrees

Check out multiple branches simultaneously: run parallel Claude Code sessions without conflicts.

bash
git worktree list
git worktree add ../feature-branch feature-branch
git worktree add -b my-feature ../my-feature main
git worktree remove ../feature-branch
git worktree prune

Parallel workflow

bash
# Terminal 1
git worktree add -b feat/auth ../project-auth main
cd ../project-auth && claude

# Terminal 2
git worktree add -b fix/perf ../project-perf main
cd ../project-perf && claude

Claude Code shortcut

bash
/worktree my-feature-name
# Creates .claude/worktrees/my-feature-name and switches into it

Subagents

Specialised Claude instances for parallel or isolated subtasks.

code-reviewer

markdown
---
description: "Deep code review: bugs, security, style"
allowed-tools: Read, Glob, Grep
---

Review the provided diff for:
- Logic bugs and edge cases
- Security vulnerabilities (OWASP Top 10)
- Performance issues

Output a markdown report with severity labels.

debugger

markdown
---
description: "Root-cause analysis for failing tests or errors"
allowed-tools: Read, Bash, Grep, Glob
---

1. Reproduce the error.
2. Identify the root cause.
3. Propose the minimal fix.
4. Verify the fix doesn't break other tests.

data-scientist

markdown
---
description: "Analyse data files and produce statistical summaries"
allowed-tools: Bash, Read
---

1. Load and describe the schema.
2. Identify missing values and outliers.
3. Compute summary statistics.
4. Suggest visualisations and next steps.

Permissions

Basic

json
{
  "permissions": {
    "allow": ["Read", "Write", "Edit", "Bash(git *)"],
    "deny": ["Bash(rm -rf *)", "Bash(curl *)", "Bash(wget *)"]
  }
}

Read-only / strict

json
{
  "permissions": {
    "allow": ["Read", "Glob", "Grep"],
    "deny": ["Write", "Edit", "Bash", "WebFetch", "WebSearch"]
  },
  "autoApprove": false
}

Enterprise

json
{
  "permissions": {
    "allow": ["Read","Write","Edit","Glob","Grep",
      "Bash(npm *)","Bash(git *)","Bash(docker *)"],
    "deny": ["Bash(curl *)","Bash(wget *)","Bash(ssh *)","WebFetch"]
  },
  "autoApprove": false,
  "requireApprovalForNewFiles": true
}

Patterns

ReadAll file reads
BashAll shell commands
Bash(git *)Only git sub-commands
Bash(npm run *)Only npm run scripts
Bash(rm *)Any rm command

Hooks

Events

PreToolUseBefore any tool call: block by exiting non-zero
PostToolUseAfter any tool call completes
StopWhen Claude finishes its final response
NotificationWhen Claude emits a system notification
SubagentStopWhen a subagent finishes
json
{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Bash",
      "hooks": [{ "type": "command",
        "command": "echo '$CLAUDE_TOOL_INPUT' >> ~/.claude/bash-log.txt" }]
    }],
    "Stop": [{
      "hooks": [{ "type": "command",
        "command": "osascript -e 'display notification \"Claude finished\"'" }]
    }]
  }
}

PreToolUse blocker

json
"PreToolUse": [{ "matcher": "Bash", "hooks": [{
  "type": "command",
  "command": "if echo \"$CLAUDE_TOOL_INPUT\" | grep -qE 'rm -rf|DROP TABLE'; then exit 1; fi"
}]}]

Environment variables

CLAUDE_TOOL_NAMEName of the tool being called
CLAUDE_TOOL_INPUTJSON-encoded tool input arguments
CLAUDE_TOOL_OUTPUTTool result (PostToolUse only)
CLAUDE_SESSION_IDUnique ID for the current session
CLAUDE_PROJECT_DIRAbsolute path to the project directory