ai/courses

Vibe coding/Cheat sheet

Claude Code Cheat Sheet: Commands, Shortcuts, and Prompts

Every command, flag, and shortcut checked against Anthropic's docs, copy-paste templates for CLAUDE.md, subagents, skills, and hooks, and the prompting habits that actually make a difference.

Updated
Reading time
10 min
Checked against
14 sources
Keyboard keycaps and a terminal window on a reference card

TL;DR

The Short Answer

If you only memorize ten things in Claude Code, make it these:

  • claude starts a session in the current folder. claude -c continues the last one.
  • /init writes a starter CLAUDE.md, the file Claude reads at the start of every session.
  • @ mentions a file, ! runs a shell command, / opens commands and skills.
  • Shift+Tab cycles permission modes, including plan mode (Claude proposes, but doesn't edit).
  • Esc stops Claude mid-action. Esc twice on an empty prompt opens rewind.
  • /clear between unrelated tasks. /compact to shrink a long one.
  • claude -p "..." runs once and exits, for scripts and CI.
  • claude mcp add connects external tools through MCP.
  • Rules that must never be broken go in hooks or deny rules, not CLAUDE.md.
  • Give Claude a check to run (tests, a build, a linter) and ask for the output.

Everything here was checked against Anthropic's docs on November 5, 2026. Claude Code updates often; type / to see what your version has.

Install Claude Code and Run Your First Session

This is the 5-minute Claude Code tutorial. You need a terminal, a project folder, and a Claude subscription (Pro, Max, Ultra, Team, or Enterprise) or a Claude Console account with API credits.

The native installer is recommended because it updates itself. Homebrew and WinGet installs don't, so upgrade those now and then. npm also works (npm install -g @anthropic-ai/claude-code, Node.js 22+), but don't use sudo.

On first launch, Claude Code opens your browser to log in. Then ask plain-English questions like "what does this project do?" or "explain the folder structure".

Not a terminal person? Claude Code also runs as a desktop app, in VS Code and JetBrains, and at claude.ai/code. This cheat sheet covers the terminal version.

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

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

# Or with a package manager (no auto-update)
brew install --cask claude-code
winget install Anthropic.ClaudeCode

# Check it worked, then start in your project
claude --version
cd /path/to/your/project
claude

# Something wrong? Diagnose without starting a session
claude doctor

Slash Commands You'll Actually Use

Slash commands are typed inside a running session. Type / to open the menu and keep typing to filter it. Some are built-in commands. Others, like /code-review, /loop, and /doctor, are bundled skills: prompt-based playbooks that ship with Claude Code. The full list of 100+ is in the commands reference.

What it doesExample
/helpShow help and available commands/help
/initGenerate a starter CLAUDE.md from your codebase, or suggest improvements to an existing one/init
/clearStart a new conversation with empty context. A name labels the old one for /resume/clear oauth-migration
/compactSummarize the conversation to free up context, with optional focus instructions/compact keep the API changes and the test commands
/contextShow what fills the context window, including which CLAUDE.md files loaded/context all
/planEnter plan mode, optionally with a task/plan fix the auth bug
/modelSwitch model and save it as your default/model sonnet
/effortSet how hard Claude thinks: low to xhigh, max, or auto/effort high
/rewindRoll code, conversation, or both back to an earlier prompt (aliases /checkpoint, /undo)/rewind
/resumeResume a past conversation by ID or name, or open the picker/resume auth-refactor
/diffReview changes in your working tree, including Claude's edits/diff
/code-reviewReview the current diff in a fresh subagent that never saw your conversation/code-review
/security-reviewCheck your branch's changes for security vulnerabilities/security-review
/btwAsk a side question without adding it to the conversation/btw what does this regex match?
/goalKeep Claude working across turns until a condition is met/goal all tests in tests/auth pass and lint is clean
/loopRepeat a prompt on an interval while the session is open/loop 15m check CI on this branch
/memoryEdit CLAUDE.md files and toggle auto memory/memory
/permissionsManage allow, ask, and deny rules for tools/permissions
/mcpManage MCP server connections and sign-ins/mcp
/skillsList available skills/skills
/agentsReminds you to ask Claude for a subagent or edit .claude/agents/ (v2.1.197 and earlier opened a wizard)/agents
/usageSession cost, plan limits, and activity stats (alias /cost)/usage
/doctorDiagnose installation, settings, and CLAUDE.md problems and propose fixes/doctor

CLI Commands and Flags

These run from your shell, before a session starts.

  • claude "fix the build error": start a session with a first prompt.
  • claude -c (--continue): load the most recent conversation in this folder.
  • claude -r "auth-refactor" (--resume): resume by ID or name. No argument opens a picker.
  • claude -n "auth-refactor" (--name): name a new session.
  • claude -w feature-auth (--worktree): start in an isolated git worktree so parallel sessions don't collide.
  • --model sonnet: pick a model by alias (sonnet, opus, haiku, fable) or full name.
  • --permission-mode plan: start in a given permission mode (see below).
  • --add-dir ../lib: let Claude read and edit another folder too.
  • --allowedTools "Bash(git diff *)" "Read": pre-approve tools. --disallowedTools blocks them.
  • claude update, claude -v, claude auth status: update, check the version, check your login.

--dangerously-skip-permissions turns off every permission check. Anthropic says to use it only in isolated containers or VMs, not on your laptop.

cli-examples.sh
# Start a named session in plan mode
claude -n "auth-refactor" --permission-mode plan

# Pick it up tomorrow
claude --resume auth-refactor

# Parallel work in its own worktree (<repo>/.claude/worktrees/feature-auth)
claude -w feature-auth

# Specific model, plus access to a sibling folder
claude --model opus --add-dir ../shared-lib

Keyboard Shortcuts

Press ? on an empty prompt to see the shortcuts for your terminal. The ones that matter:

  • Esc: stop Claude mid-turn. Work so far is kept, so you can redirect.
  • Esc Esc on an empty prompt: open the rewind menu.
  • Shift+Tab: cycle permission modes.
  • Ctrl+C: interrupt or clear input. Ctrl+D twice exits.
  • Ctrl+B: send a running command or agent to the background.
  • @: file autocomplete, which puts the file into your message.
  • ! at the start: shell mode. Runs the command and shows Claude the output.
  • Ctrl+V (Cmd+V in iTerm2, Alt+V on Windows): paste an image, like a screenshot of an error.
  • Ctrl+G: open your prompt, or a proposed plan, in your text editor.
  • Ctrl+R: search prompt history. Ctrl+O: transcript with full tool calls.
  • Option+P / Alt+P: switch model without clearing your prompt.
  • New line without sending: \ then Enter, or Ctrl+J anywhere. Shift+Enter works natively in iTerm2, WezTerm, Ghostty, Kitty, Warp, Apple Terminal, and Windows Terminal. In VS Code, Cursor, Alacritty, or Zed, run /terminal-setup once.

On macOS, Alt shortcuts need "Option as Meta" turned on in your terminal.

Permission Modes and Plan Mode

A permission mode decides what Claude can do without asking. Shift+Tab cycles them, and the status bar shows the current one.

  • default (shown as Manual): reads run freely, everything else asks.
  • acceptEdits: file edits and common file commands (mkdir, mv, cp) run without asking.
  • plan: Claude researches and writes a plan but can't edit your source until you approve.
  • auto: actions run without prompts, but a separate classifier model reviews each one and blocks risky ones. Since v2.1.283 this is the built-in starting mode in the terminal and VS Code.
  • dontAsk: only pre-approved tools run; anything else is denied. Built for CI.
  • bypassPermissions: no checks. Containers and VMs only.

Plan mode is the best habit for anything bigger than a one-line fix. Enter it with Shift+Tab or /plan. When the plan is ready, approve it (with auto mode or manual edit review) or choose "No, keep planning" and give feedback. Ctrl+G lets you edit the plan first.

Note that claude -p runs start in Manual mode, so anything you didn't pre-approve gets denied instead of prompting.

modes.sh
# Start a session in plan mode
claude --permission-mode plan

# CI run with an exact allowlist: anything else is refused
claude -p "run the test suite" --permission-mode dontAsk --allowedTools "Bash(npm test)" "Read"

CLAUDE.md Template and Memory

CLAUDE.md is a Markdown file Claude loads into every session. It's guidance, not enforced configuration, so keep it short and specific. Anthropic recommends under 200 lines.

  • ~/.claude/CLAUDE.md: your preferences for all projects.
  • ./CLAUDE.md or ./.claude/CLAUDE.md: the project file. Commit it.
  • ./CLAUDE.local.md: your personal notes for this project. Add it to .gitignore.
  • .claude/rules/*.md: rules with a paths: filter that load only for matching files.
  • @path/to/file inside CLAUDE.md imports another file.
  • If the repo has an AGENTS.md (the file Codex and other agents use) and no CLAUDE.md, Claude Code reads AGENTS.md.
  • Auto memory is separate: Claude keeps its own notes in ~/.claude/projects/<project>/memory/. Manage it with /memory.

Put in: exact test, typecheck, and lint commands; places where the code is misleading; decisions that live outside the repo; anything you've corrected twice. Leave out your folder layout, because Claude reads the repo itself. This template follows Anthropic's own example:

CLAUDE.md
# Commands
- Install: pnpm install
- Run one test file: pnpm vitest run path/to/file.test.ts
- Typecheck: pnpm tsc --noEmit

# Conventions
- Use the error helpers in src/lib/errors.ts, never throw raw strings
- src/legacy/ is still live but don't copy its patterns into new code

# Gotchas
- Integration tests need DATABASE_URL set, see .env.example

Settings Files: Where Everything Lives

Settings are strict JSON (no comments, no trailing commas). Highest priority first:

  1. Managed (managed-settings.json): set by your organization.
  2. Command line: --settings <file-or-json> for one session.
  3. Project local: .claude/settings.local.json, just you, kept out of git.
  4. Shared project: .claude/settings.json, committed for the team.
  5. User: ~/.claude/settings.json, you, every project.

Other locations: subagents in ~/.claude/agents/ and .claude/agents/; skills in ~/.claude/skills/<name>/SKILL.md and .claude/skills/<name>/SKILL.md; MCP servers in ~/.claude.json and .mcp.json at the project root. Run /status to confirm a file loaded. This example lets lint and tests run without asking and blocks reading .env files:

~/.claude/settings.json
{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "permissions": {
    "allow": [
      "Bash(npm run lint)",
      "Bash(npm run test *)"
    ],
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)"
    ]
  }
}

Subagent Template

A subagent is a helper with its own context window, instructions, and tool list. Claude hands it a task and gets a summary back. That's useful for parallel research, for keeping noisy output out of your chat, and for review by fresh eyes. Built-in ones include Explore (fast, read-only search) and Plan.

To make one, ask Claude ("create a read-only code-reviewer subagent in .claude/agents/ that uses Sonnet") or write the file yourself. To use it, name it in your prompt, or @-mention it to guarantee it runs. Anthropic's own caveat: delegating doesn't make an answer better by itself, and each subagent costs extra tokens.

.claude/agents/code-reviewer.md
---
name: code-reviewer
description: Reviews code for quality and best practices
tools: Read, Glob, Grep
model: sonnet
---

You are a code reviewer. When invoked, analyze the code and provide
specific, actionable feedback on quality, security, and best practices.

Skills Template (Custom Slash Commands)

A skill is a saved procedure: a folder with a SKILL.md file. The folder name becomes a slash command, and Claude can also load it on its own when your request matches its description. Until then only the description sits in context, so long playbooks cost almost nothing. Custom commands were merged into skills: .claude/commands/deploy.md still works and creates /deploy, just like .claude/skills/deploy/SKILL.md.

Set disable-model-invocation: true for anything with side effects, like deploys, so only you can start it. Set user-invocable: false for background knowledge only Claude should load. Skills follow the open Agent Skills standard. This one is adapted from Anthropic's best-practices page:

.claude/skills/release/SKILL.md
---
name: release
description: Cut a new release. Bumps the version, writes the changelog entry, tags it and pushes the tag so CI can publish.
disable-model-invocation: true
---
1. Make sure you're on main with a clean tree. If not, stop and ask.
2. Run `pnpm changeset version` and commit the result.
3. Summarize the PRs merged since the last tag into CHANGELOG.md, one line each, user-facing changes only.
4. Tag `v<new version>` and push the tag. CI publishes from there, never publish from your machine.

Hooks Template

A hook is a shell command that Claude Code (the program, not the model) runs automatically at a fixed point, so it fires every time. Anthropic's rule of thumb: if you keep adding emphasis to a CLAUDE.md line and Claude still misses it, that line belongs in a hook.

The events you'll use most: PreToolUse (before a tool runs, can block it), PostToolUse (after a tool succeeds, good for formatting), Stop (when Claude tries to finish; exit code 2 sends it back to work), and Notification (when Claude needs your input). There are more than 25 others. Hooks go in a hooks block in any settings file; check them with /hooks. This example from the docs runs Prettier on every file Claude edits:

.claude/settings.json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write"
          }
        ]
      }
    ]
  }
}

MCP: Connect Claude Code to Other Tools

MCP (Model Context Protocol) is an open standard for plugging tools into AI apps: a browser, Notion, Sentry, your database. If a system already has a CLI (like gh for GitHub), Claude can usually just use that instead.

  • Remote servers use --transport http and a URL. For local servers, everything after -- is the command that starts them.
  • The default scope is local (you, this project). --scope user covers all your projects; --scope project writes .mcp.json for the team.
  • If a server needs a login, finish it from /mcp inside a session.
  • Every connected server adds tool descriptions to your context, so turn off the ones you don't use.

Want to write your own? See how to build an MCP server.

mcp.sh
# Remote (HTTP) server
claude mcp add --transport http notion https://mcp.notion.com/mcp

# Local server: everything after -- starts it
claude mcp add playwright -- npx -y @playwright/mcp@latest

# Available in all your projects
claude mcp add --scope user --transport http sentry https://mcp.sentry.dev/mcp

# Check, inspect, remove
claude mcp list
claude mcp get sentry
claude mcp remove sentry

Headless Mode: claude -p in Scripts and CI

claude -p "prompt" (--print) runs one task and exits. That's how Claude Code runs in CI jobs, git hooks, and shell loops. Useful flags:

  • --output-format json returns one result object; stream-json with --verbose streams events.
  • --allowedTools pre-approves tools, and --permission-mode dontAsk refuses everything else.
  • --max-turns and --max-budget-usd cap how far a run can go.
  • --bare skips hooks, skills, plugins, MCP servers, and CLAUDE.md so runs behave the same everywhere. It needs ANTHROPIC_API_KEY or cloud credentials, not your claude.ai login.
  • --continue or --resume <id> carries a conversation across several -p calls.

Anthropic's advice: try a loop like this on three files first, fix the prompt, then run the rest.

headless.sh
# One-off question, piped input
cat error.log | claude -p "what's going on here"

# Structured output for scripts
claude -p "Summarize this project" --output-format json

# Batch migration with a tight allowlist and a turn cap
for file in $(cat files.txt); do
  claude --bare -p "Migrate $file to the new logger API and commit. Reply OK or FAIL." \
    --allowedTools "Read,Edit,Bash(git add *),Bash(git commit *)" \
    --permission-mode dontAsk \
    --max-turns 20
done

Claude Code Prompting Tips That Actually Work

These come from Anthropic's own best-practices page. Most bad sessions come down to one of four things: Claude was missing information, had no way to check its work, broke a rule nothing enforced, or spent more than the task was worth.

  1. Tell Claude what it can't see. Name the file, describe the symptom, say what "fixed" looks like. Not "fix the login bug", but "users report login fails after the session times out. look at token refresh in src/auth/, write a failing test that reproduces it, then fix it."
  2. Hand over the evidence. @ the file, paste the screenshot, pipe in the log.
  3. Say "be ambitious" when you want the full version. Claude reads requests conservatively and builds the smallest thing that works. Only you know the scope you want.
  4. Not sure what you want? Ask to be interviewed. Let Claude ask questions until it can write SPEC.md, then build from it in a fresh session.
  5. Give it a check that passes or fails, like tests or a build, and ask for the command and its output. "All tests pass" on its own tells you little.
  6. Review with fresh eyes. Use /code-review, or a subagent that checks against your spec. Add "skip style", or the reviewer will always find something.
  7. Steer early. Watch the first minute and press Esc when Claude drifts. After two failed corrections, /clear and write one better prompt.
  8. /clear between unrelated tasks. Every turn re-sends the whole conversation, so old tasks keep costing you.

What you can stop doing: ALL CAPS and "IMPORTANT" (use a hook instead), "think harder" (that's what /effort is for, though ultrathink still asks for deeper reasoning on one turn), and "don't be lazy" (give it a check to pass).

prompts.txt
I want to add rate limiting to the public API but haven't thought it through yet. Interview me until you could write the spec, then write it to SPEC.md.

build the settings page from the mockup. be ambitious: empty and error states, the save flow wired up, keyboard navigation, not just the layout

run the auth tests after, and keep going until they pass

use a subagent to review the rate limiter diff against SPEC.md, check every requirement is implemented and the listed edge cases have tests, report gaps that affect correctness and skip style

Where to Go Next

FAQ

Is Claude Code free?
No. Claude Code needs a paid Claude subscription (Pro, Max, Ultra, Team, or Enterprise), a Claude Console account with pre-paid API credits, or access through Amazon Bedrock, Google Cloud, or Microsoft Foundry. Run /usage in a session to see your cost and plan limits.
How do I see all Claude Code commands?
Type / in a session to open the command menu and keep typing to filter it, or run /help. From the shell, claude --help lists the CLI flags. The full lists are on code.claude.com under Commands and CLI reference.
What is the difference between CLAUDE.md, skills, and hooks?
CLAUDE.md is short guidance loaded into every session. A skill is a longer procedure that loads only when it is needed or when you type its slash command. A hook is a shell command Claude Code runs automatically at a fixed point, so it is enforced every time instead of being up to the model.
How do I stop Claude Code from asking permission all the time?
Use auto mode, the default starting mode in recent versions, where a classifier reviews risky actions instead of asking you. Or add allow rules for commands you trust with /permissions or in settings.json. Keep --dangerously-skip-permissions for isolated containers and VMs.
How do I undo what Claude Code changed?
Press Esc twice on an empty prompt or run /rewind to roll the code, the conversation, or both back to an earlier prompt. Checkpoints only cover files Claude edited with its own file tools, not changes made by shell commands, so keep using git too.

Read next

  1. 01Claude Code Templates: CLAUDE.md, Subagents, Skills, Hooks, and MCPNine copy-paste templates that cover most Claude Code setups, each with its exact path, a note on when to use it, and only the fields the official docs list. Copy one, change the commands and paths to match your repo, and commit it.Guide
  2. 02Claude Code Tutorial: Build Your First App, Step by StepInstall Claude Code, learn how a session works on a real codebase, then build a small tested web app from an empty folder. Every prompt you type is in this guide, and every command was checked against Anthropic's docs.Guide
  3. 0310 Claude Code Projects to Build (With the Exact Prompts)You installed Claude Code. Now what? Here are ten projects ordered from first-afternoon to genuinely useful, each with a starter prompt you can paste, the follow-ups that come next, and the check that tells you it actually works.Guide
  4. 04Claude Code Alternatives: 7 AI Coding Agents ComparedWhat each tool actually is, whether it's open source, which models it runs, how you pay for it, and when it beats Claude Code. Plus a dedicated Claude Code vs OpenCode breakdown.Comparison
  5. 05The Best Claude Code Courses in 2026 (Free and Paid)Anthropic's own courses are free and better than most paid ones. Here's which Claude Code course to take first, where to get a certificate, and a 7-day plan with practice projects.Best courses

Sources: Claude Code quickstart, Advanced setup (install options), CLI reference, Commands reference, Interactive mode and keyboard shortcuts, Permission modes, How Claude remembers your project (CLAUDE.md), Settings files and precedence, Create custom subagents, Extend Claude with skills, Automate actions with hooks, Connect to MCP servers, Run Claude Code programmatically, Best practices for Claude Code.