Claude Code Cheatsheet
Complete reference for commands, shortcuts, config, MCP servers, and more.
Getting Started
Install
# 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 | iexUpdate
claude update
claude --versionLaunch
claude
claude "explain this codebase"
claude --continue
claude --resume <session-id>Keyboard Shortcuts
Permission modes (Shift+Tab)
| default | Shown as Manual. Asks before tool calls that need permission |
| acceptEdits | Accepts file edits without asking |
| plan | Explores and proposes a plan without editing files |
| auto | A classifier approves or blocks actions, when available on your plan |
Configuration
Config file priority (highest → lowest)
| .claude/settings.local.json | Project-local overrides (gitignored) |
| .claude/settings.json | Project-level (committed to repo) |
| ~/.claude/settings.json | User-level global defaults |
Change settings from a session
/config # open the settings screen
/config model=sonnet # set a value directly
/config theme=dark
/config --help # list the keys you can setExample settings.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.
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
| /help | Show all available slash commands |
| /clear | Start a new conversation with empty context |
| /rewind | Roll code and conversation back to a checkpoint (alias: /undo) |
| /compact | Compress conversation history to save tokens |
| /memory | Edit CLAUDE.md files and auto memory |
| /permissions | Show and edit current tool permissions |
| /model | Switch model and save it as your default |
| /usage | Show session cost and plan limits (alias: /cost) |
| /export | Export conversation to a file |
| /doctor | Check your setup and fix common problems |
| /bug | Report a bug to Anthropic |
| /code-review | Review your changes or a PR for bugs (alias: /review) |
| /context | See what is filling the context window |
| /init | Create 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
---
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.
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-jsonOutput formats
| --output-format text | Plain text (default) |
| --output-format json | Full JSON response object |
| --output-format stream-json | Streaming NDJSON tokens |
Pipeline examples
# 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
| description | Shown in /help and skill picker |
| allowed-tools | Comma-separated tools this skill may use |
| argument-hint | Placeholder shown after the slash command |
commit.md
---
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
---
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
claude plugins list
claude plugins install <plugin-name>
claude plugins install ./my-plugin
claude plugins remove <plugin-name>
claude plugins updateStructure
my-plugin/
├── plugin.json
├── commands/
│ └── my-skill.md
└── mcp/
└── my-server.json{
"name": "my-plugin",
"version": "1.0.0",
"description": "My custom plugin",
"commands": ["commands/my-skill.md"],
"mcpServers": ["mcp/my-server.json"]
}MCP Servers
claude mcp add <name> <command> [args...]
claude mcp add filesystem npx -y @modelcontextprotocol/server-filesystem /path
claude mcp remove <name>
claude mcp listsettings.json
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path"],
"env": {}
}
}
}Popular servers
Read repos, issues, PRs, and code search via the GitHub API.
@modelcontextprotocol/server-githubRead and write local files within allowed directories.
@modelcontextprotocol/server-filesystem <path>Run read-only SQL queries against a PostgreSQL database.
@modelcontextprotocol/server-postgres <conn>Post messages, list channels, and search Slack workspaces.
@modelcontextprotocol/server-slackWeb and local search powered by the Brave Search API.
@modelcontextprotocol/server-brave-searchQuery, create, and update pages and databases in Notion.
@notionhq/notion-mcp-serverCreate and triage issues, projects, and cycles in Linear.
@linear/linear-mcp-serverInspect Figma files, components, and design tokens.
@figma/mcp-serverAutomate browsers: navigate, click, screenshot, and scrape.
@executeautomation/playwright-mcp-serverGit Worktrees
Check out multiple branches simultaneously: run parallel Claude Code sessions without conflicts.
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 pruneParallel workflow
# 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 && claudeClaude Code shortcut
/worktree my-feature-name
# Creates .claude/worktrees/my-feature-name and switches into itSubagents
Specialised Claude instances for parallel or isolated subtasks.
code-reviewer
---
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
---
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
---
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
{
"permissions": {
"allow": ["Read", "Write", "Edit", "Bash(git *)"],
"deny": ["Bash(rm -rf *)", "Bash(curl *)", "Bash(wget *)"]
}
}Read-only / strict
{
"permissions": {
"allow": ["Read", "Glob", "Grep"],
"deny": ["Write", "Edit", "Bash", "WebFetch", "WebSearch"]
},
"autoApprove": false
}Enterprise
{
"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
| Read | All file reads |
| Bash | All shell commands |
| Bash(git *) | Only git sub-commands |
| Bash(npm run *) | Only npm run scripts |
| Bash(rm *) | Any rm command |
Hooks
Events
| PreToolUse | Before any tool call: block by exiting non-zero |
| PostToolUse | After any tool call completes |
| Stop | When Claude finishes its final response |
| Notification | When Claude emits a system notification |
| SubagentStop | When a subagent finishes |
{
"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
"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_NAME | Name of the tool being called |
| CLAUDE_TOOL_INPUT | JSON-encoded tool input arguments |
| CLAUDE_TOOL_OUTPUT | Tool result (PostToolUse only) |
| CLAUDE_SESSION_ID | Unique ID for the current session |
| CLAUDE_PROJECT_DIR | Absolute path to the project directory |