โ† Back

Claude Code Cheat Sheet

Every key concept from the Claudio course, in one page. Print it, pin it, ship it.

๐ŸŒฑGetting Started

Meet Claude Code and set up your first session.

What is Claude Code?

Meet Claude Code

Claude Code is an AI coding agent built by Anthropic. Unlike a chat window, it actually lives inside your terminal โ€” reading your files, editing code, and running commands in your real repository (with your permission).

  • Runs locally in your terminal, inside your repo
  • Can read, edit, search files & run shell commands
  • Asks before doing anything destructive

Install & Launch

Install Claude Code

There are two supported ways to install the CLI: the npm package, or the native installer (recommended if you'd rather not manage Node yourself). Either way you end up with a `claude` command on your PATH.

# npm (needs Node 18+)
npm install -g @anthropic-ai/claude-code

# or the native installer
curl -fsSL https://claude.ai/install.sh | bash

claude --version   # 2.1.x today
  • npm package name: @anthropic-ai/claude-code
  • Native installer needs no Node toolchain
  • First run opens a browser to sign in (Pro/Max plan or API key)
  • Docs live at code.claude.com/docs

Starting, resuming & exiting

You start Claude by cd-ing into your project and running `claude`. Pick up where you left off with `/resume` (or `claude --resume`), and leave cleanly with `/exit` or Ctrl+D.

cd my-project
claude
# โ€ฆ later โ€ฆ
/resume    # continue an earlier session
/exit      # or Ctrl+D

Your First Session

Your first prompt

Claude starts each session knowing nothing about your repo. Your first prompt sets the tone. Aim for a friendly orientation request rather than 'do everything'.

  • Ask for an overview before asking for changes
  • Mention the entry point or main file if you know it
  • Claude will ask permission before running shell commands

๐Ÿ’ฌTalking to Claude

Prompt like a pro โ€” be specific, give context, iterate.

Be Specific

Specificity is the cheat code

Claude does its best with what you give it. A vague prompt like 'fix login' forces Claude to guess at goal, scope, and acceptance. A specific prompt names the file, the behavior, and what 'done' looks like.

  • Name the file or area to change
  • Describe the desired behavior, not just the problem
  • Add acceptance criteria when it matters

Give Context

Point Claude at the right files

Claude doesn't read your whole repo on every message โ€” it searches and opens files on demand. You speed things up dramatically by mentioning the relevant file paths up front.

Refactor src/components/Button.tsx so the variant prop also accepts 'ghost'.
Related types live in src/components/types.ts.

Iterate

Steering > restarting

When Claude goes off track, your instinct may be to scrap the conversation. Usually it's faster to course-correct: tell Claude exactly what's wrong and what to do next. Only start fresh when context is large and unrelated.

๐Ÿ“Files & the Repo

How Claude reads, edits, and searches your code.

Reading & Editing

Surgical edits, not rewrites

Claude prefers targeted search-and-replace edits over rewriting entire files. This keeps diffs small and reviewable โ€” and makes it easy to revert with git if you don't like the result.

git diff           # see exactly what Claude changed
git checkout -- .  # discard everything if needed

Searching the Repo

Searching the repo

Claude uses ripgrep (`rg`) under the hood because it's fast and respects .gitignore. You can ask in plain English ('find every usage of fetchUser') and Claude will translate it to the right command.

rg "fetchUser" -t ts

๐Ÿ› ๏ธThe Toolbelt

Bash, file ops, web fetch, and permission prompts.

Permissions

You're the safety net

Before running shell commands or editing files, Claude shows you exactly what it wants to do. Read it. Approve commands that are scoped and reversible. Pause on anything destructive: `rm -rf`, `git push --force`, DB drops.

  • Approve: ls, cat, npm test, git diff
  • Pause and read: rm, mv, git reset --hard, SQL writes
  • Auto-accept is for scoped, trusted loops only

Web & Docs

Ground answers in real docs

Claude's training data has a cutoff. For anything that changes โ€” APIs, library versions, your team's docs โ€” ask Claude to fetch the URL first and summarize before acting.

Fetch https://docs.anthropic.com/en/docs/claude-code/overview
and summarize the section on permissions.

๐Ÿ”Workflows

Plan, debug, refactor, test โ€” the daily loops.

Plan First

Plan first, build second

For anything non-trivial, ask Claude for a plan before touching files. A plan is cheap; bad code is expensive. Read the plan, push back, and only then say 'go'.

Write a plan first; wait for me to approve before you change any files.

Debugging

The debugging loop

Good debugging follows a tight loop: reproduce โ†’ isolate โ†’ hypothesize โ†’ fix โ†’ verify. Claude is great at every step, but only if you keep it focused on one bug at a time.

Writing Tests

Tests lock in behavior

The best moment to write a test is right after fixing a bug โ€” that test will catch the same bug if it ever comes back. Ask Claude to add one as part of the fix.

npx vitest watch

๐ŸŒฟGit with Claude

Commits, branches, PR descriptions, reviews.

Commits

Small, descriptive commits

Claude can write commit messages for you. Push for conventional, descriptive style โ€” `fix:`, `feat:`, `refactor:` โ€” and keep each commit to one logical change so reverting is painless.

git add -A && git commit -m "fix: prevent double-submit on login form"

Pull Requests

Let Claude draft the PR

After you've staged your changes, ask Claude to read the diff and write a PR description: what changed, why, how to test, and any risks. You'll edit it in 30 seconds instead of writing it from scratch.

๐Ÿ““CLAUDE.md & Memory

Teach Claude your project's rules once.

CLAUDE.md Basics

Teach Claude your project โ€” once

`CLAUDE.md` is a markdown file at your repo root that Claude reads at the start of every session. Put your project's conventions, commands, and 'don'ts' here so you stop repeating yourself.

# CLAUDE.md
## Commands
- Dev: bun dev
- Test: bun test
## Conventions
- Use TanStack Router, never react-router
## Don'ts
- Never commit directly to main
  • Lives at the repo root (commit it)
  • Never put secrets here โ€” it's in git
  • Subfolders can have their own CLAUDE.md too

Custom Commands

Custom commands live in .claude/commands/

Drop a markdown file in `.claude/commands/` and it becomes a reusable command. `.claude/commands/review.md` โ†’ type `/review` to run it. In today's docs custom commands are described as part of the wider **Skills** system (next unit) โ€” same folder, bigger family.

.claude/commands/review.md
โ†’ invoke with: /review

Use $ARGUMENTS to pass input:
/review src/api.ts

What Claude reads from .claude/

The `.claude/` directory is the whole configuration surface for a project. Knowing what lives there tells you where to put things.

CLAUDE.md            # project memory
.claude/settings.json # shared config + permissions
.claude/commands/     # custom commands
.claude/skills/       # SKILL.md skills
.claude/agents/       # subagents
.claude/hooks         # lifecycle hooks (in settings)

๐Ÿ”ŒMCP & Integrations

Plug external tools into Claude via Model Context Protocol.

What is MCP?

MCP = tools for Claude

Model Context Protocol is an open standard for connecting Claude to external tools: your database, Linear, Figma, Playwright, internal APIs. Claude gets new capabilities without changing the model.

  • Standard protocol โ€” works across many clients
  • Each MCP server exposes a set of tools Claude can call
  • Bring your own, or use community servers

Adding an MCP Server

Wiring up an MCP server

Adding an MCP server is one CLI command. For local (stdio) servers use `--` to separate Claude's flags from the server command. For remote servers pass `--transport http` (or `sse`) and a URL โ€” remote servers usually authenticate through an OAuth flow you approve in the browser.

# local stdio server
claude mcp add linear -- npx -y @linear/mcp-server

# remote HTTP server
claude mcp add --transport http notion https://mcp.notion.com/mcp

claude mcp list
claude mcp remove linear
  • Scopes: `-s local` (default), `-s project` (writes .mcp.json, commit it), `-s user` (all projects)
  • Check connection status in-session with /mcp

๐Ÿค–Sub-agents & Automation

Spawn focused agents for parallel work.

Sub-agents

Delegate with sub-agents

A sub-agent is a fresh Claude instance you spawn for a scoped task. It gets its own context, does the work, and returns a summary. Use them for parallelizable jobs that would otherwise bloat your main conversation.

  • Good fit: 'audit these 10 files for X'
  • Good fit: independent research / search jobs
  • Bad fit: a single linear task you're already on

Project Sub-agents

.claude/agents/*.md

You can pre-define sub-agents as markdown files with frontmatter. Each file gets a `name`, `description` (used for auto-delegation), and optionally a restricted `tools` list. Claude will dispatch matching tasks to them automatically, or you can invoke with `/agents`.

---
name: code-reviewer
description: Use proactively after code changes to review for bugs, style, and security.
tools: Read, Grep, Glob, Bash
---
You are a senior reviewer. Focus on correctness, edge cases, and security.
Return findings as a bulleted list grouped by severity.
  • Per-project: .claude/agents/
  • Per-user (all projects): ~/.claude/agents/
  • Omit `tools` to inherit all of the parent agent's tools

๐Ÿง Thinking & Modes

Extended thinking, Plan Mode, and when to use each.

Reasoning Effort

Models & effort levels

Two dials control how much brain Claude brings: which model, and how much reasoning effort it spends. Set both from `/model`. Today's lineup is Opus 4.5 (deepest), Sonnet 4.5 (the daily driver), and Haiku 4.5 (fast and cheap).

/model              # pick model + effort level
claude --model opus  # one-off session
  • Opus 4.5 โ€” hardest reasoning, highest cost
  • Sonnet 4.5 โ€” best default for everyday coding
  • Haiku 4.5 โ€” fast, cheap, great for small mechanical edits
  • Effort level is a setting now, not a magic prompt word

Plan Mode

Shift+Tab cycles modes

Press Shift+Tab in the prompt to cycle through modes: default โ†’ auto-accept edits โ†’ Plan Mode. In Plan Mode Claude can read and search but cannot edit files or run mutating commands โ€” it produces a plan you approve before exiting back to a build mode.

  • Default: ask before edits/commands
  • Auto-accept edits: trusted scoped loops
  • Plan Mode: read-only investigation + plan

โšกSession Power Tools

Slash commands every regular uses.

Core Slash Commands

The daily-driver commands

A handful of commands cover 90% of session management. Learn them once and stop fighting your context window.

  • /clear โ€” wipe the conversation, keep CLAUDE.md
  • /compact โ€” summarize the conversation so far to free tokens
  • /resume โ€” pick a previous session to continue
  • /context โ€” see what's filling your context window
  • /cost and /usage โ€” spend and plan-limit tracking
  • /model โ€” switch model and reasoning effort
  • /init โ€” generate a starter CLAUDE.md for this repo
  • /rewind โ€” jump back to an earlier checkpoint
  • /doctor โ€” full setup checkup when something's off

Images & Paste

Vision in the terminal

You can paste images directly into the Claude Code prompt (or drag a file path). Great for 'match this Figma', 'here's the error screenshot', or 'read this whiteboard'.

  • Paste from clipboard or drag-drop a file
  • Works with PNGs, JPGs, and screenshots
  • Combine with a textual goal: 'rebuild this UI in src/components/Card.tsx'

โš™๏ธSettings & Permissions

Configure tools, allowlists, and safe defaults.

settings.json

Three settings files

Claude Code reads layered JSON config. Commit team rules, keep personal tweaks local.

~/.claude/settings.json          # personal, all projects
.claude/settings.json            # project, committed
.claude/settings.local.json      # project, gitignored
  • `permissions.allow` / `permissions.deny` โ€” auto-approve or block tool patterns
  • `env` โ€” environment variables for the session
  • `hooks` โ€” event-driven shell commands (see Hooks unit)

Permission rules

Rules use tool-name plus an optional matcher. Allow safe commands; deny anything you never want auto-run.

{
  "permissions": {
    "allow": ["Bash(npm test:*)", "Bash(git diff:*)", "Read(./**)"],
    "deny":  ["Bash(git push:*)", "Bash(rm -rf:*)"]
  }
}

๐ŸชHooks

Run your own shell commands on Claude events.

Hook Events

Deterministic guardrails

Hooks let you run shell commands at fixed points in Claude's lifecycle โ€” independent of the model deciding to. Use them to auto-format on edit, block forbidden commands, send notifications, or log every tool call.

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Edit|Write",
      "hooks": [{ "type": "command", "command": "bun run format" }]
    }]
  }
}
  • PreToolUse โ€” fires BEFORE a tool runs (can block by exiting non-zero)
  • PostToolUse โ€” fires AFTER a tool runs (great for format/lint)
  • UserPromptSubmit, Stop, SubagentStop, Notification

๐Ÿค–Headless & CI

Run Claude non-interactively, in scripts and pipelines.

Print Mode (-p)

claude -p "..."

`claude -p` runs a single prompt non-interactively and prints the result to stdout. Pipe stdin in, parse stdout out โ€” Claude as a CLI primitive. Add `--output-format json` for structured output, or `--output-format stream-json` to stream events.

git diff | claude -p "Write a conventional commit message for this diff"
claude -p "Summarize CHANGELOG.md" --output-format json

The Claude Agent SDK

When a shell one-liner isn't enough, you build on the **Claude Agent SDK** (TypeScript and Python). Heads up: it used to be called the 'Claude Code SDK' โ€” that name is retired, and older tutorials still use it.

  • Old name: Claude Code SDK โ†’ new name: Claude Agent SDK
  • Same primitives as the CLI: tools, hooks, subagents, permissions
  • Use it to embed agents in your own product or pipeline

GitHub Actions

Claude in your PRs

Install the official Claude Code GitHub Action and mention `@claude` in an issue or PR comment to dispatch a Claude run. It can read context, propose changes, and push a branch โ€” all gated by the workflow's permissions and your repo's secrets.

  • Trigger: comment `@claude do X` on an issue or PR
  • Auth: ANTHROPIC_API_KEY repo secret
  • Scope: limit allowed tools and paths in the workflow

๐ŸŒฒParallel Work

Git worktrees, background tasks, and multiple Claudes.

Git Worktrees

One Claude per worktree

A git worktree is a second working directory tied to a different branch in the same repo. Spin one up per task and run a separate Claude in each โ€” no branch-switching, no file conflicts, true parallelism.

git worktree add ../myapp-feature-x feature-x
cd ../myapp-feature-x && claude
  • Independent file state per worktree
  • Share the same .git, history, and remotes
  • Remove with: git worktree remove <path>

๐ŸงฉAgent Skills

Teach Claude new capabilities with SKILL.md files.

What a Skill Is

SKILL.md

A Skill is a folder containing a `SKILL.md` file: a name, a description of when to use it, and instructions. Claude reads the description, and when a task matches it pulls the full skill in. Skills are how you package repeatable know-how โ€” house style, release process, a tricky migration.

.claude/skills/changelog/SKILL.md

---
name: changelog
description: Use when adding an entry to CHANGELOG.md.
---

Append under ## Unreleased, newest first,
using conventional-commit prefixes.
  • Personal skills: ~/.claude/skills/
  • Project skills: .claude/skills/ (commit them)
  • The `description` is what makes Claude pick it up โ€” write it as a trigger
  • Manage them with /agents-style menus and invoke by name when needed

Plugins & Marketplaces

Plugins bundle everything

A plugin packages skills, subagents, commands, hooks and MCP servers together so a whole workflow installs in one step. Teams publish them through marketplaces so everyone gets the same setup.

  • One install = commands + skills + agents + hooks + MCP config
  • Great for standardising a team's Claude setup
  • Anthropic ships bundled plugins too โ€” e.g. a model-migration helper

๐Ÿ›ŸCheckpoints & Sandboxing

Undo anything; let Claude run freely without risk.

Checkpoints & /rewind

Rewind, don't panic

Claude Code automatically checkpoints file edits as it works. If a change goes sideways, `/rewind` (or tapping Esc twice) lets you pick an earlier state and restore it โ€” conversation, files, or both.

/rewind      # pick a checkpoint to restore
Esc Esc      # same thing, faster
  • Checkpoints cover Claude's edits, not your own manual ones
  • Still commit often โ€” git is the real safety net
  • Rewinding the conversation is different from /clear: it goes back, not blank

Sandboxed Bash

Fewer prompts, still safe

Sandboxing runs shell commands inside filesystem and network isolation: you declare which paths and hosts are reachable, and Claude can then run most commands without stopping to ask. It's the modern answer to permission fatigue โ€” and a far better idea than skipping permissions entirely.

  • Declare allowed paths and network destinations
  • Commands that stay inside the sandbox run without prompting
  • Anything that escapes it still asks you

๐Ÿ–ฅ๏ธBeyond the Terminal

Desktop, web, IDEs, Chrome, and your phone.

Where Claude Code Runs

Pick your surface

Claude Code is no longer terminal-only. The same agent shows up in several places, and they share your config in `.claude/`.

  • Terminal โ€” the original, most scriptable
  • Desktop app โ€” parallel sessions with git isolation, visual diff review, PR monitoring
  • Claude Code on the web โ€” kick off work from a browser
  • VS Code extension โ€” the recommended graphical experience
  • JetBrains plugin โ€” IntelliJ, PyCharm, WebStorm and friends
  • Claude in Chrome โ€” drive and debug a real browser

Agent Teams

Four ways to parallelise

Parallel work is now a first-class topic. Subagents isolate a side task, agent view lets you watch several running agents, agent teams coordinate a group on one goal, and dynamic workflows let Claude compose the steps itself.

  • Subagent โ€” one focused side task, separate context
  • Agent view โ€” monitor and steer running agents
  • Agent teams โ€” several agents coordinating on one goal
  • Worktrees โ€” physical isolation on disk per agent

๐Ÿ†Pro Habits

Safety, context, cost โ€” work like a Claude veteran.

Context Hygiene

Fresh context = better answers

Long sessions accumulate stale context that distracts Claude and burns tokens. When you switch tasks, start a new session. Keep one session per coherent goal.

When NOT to Use Claude

Know the limits

Claude Code is powerful, but it's not a replacement for human judgment on irreversible, high-stakes actions: production deploys without review, prod DB writes, anything involving secrets or money. Use it; don't surrender to it.

Generated from the Claudio course ยท claude-code-cheatsheet