โ† 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

Claude Code is distributed as an npm package. You need Node.js 18+ installed, then install the CLI globally so the `claude` command is available everywhere.

npm install -g @anthropic-ai/claude-code
  • Package name: @anthropic-ai/claude-code
  • After install, run `claude` inside any project folder
  • First run: it opens a browser to log in with your Anthropic account

Starting & exiting a session

Once installed, you start Claude by cd-ing into your project and running `claude`. To leave a session cleanly, type the slash command `/exit`.

cd my-project
claude
# โ€ฆ later โ€ฆ
/exit

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 Slash Commands

Custom slash commands

Drop a markdown file in `.claude/commands/` and it becomes a reusable slash command. `.claude/commands/review.md` โ†’ type `/review` to run it. Perfect for repeated workflows.

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

๐Ÿ”Œ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. Use `--` to separate Claude's flags from the server command. Scope it with `-s user` (all projects), `-s project` (commit a .mcp.json), or default `local` (this project only).

claude mcp add linear -- npx -y @linear/mcp-server
claude mcp list
claude mcp remove linear

๐Ÿค–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.

Extended Thinking

think โ†’ think hard โ†’ ultrathink

Claude Code recognizes escalating 'thinking' keywords in your prompt. Each tier allocates a larger internal reasoning budget before Claude responds. Use for tricky design or debugging โ€” skip for trivial edits.

  • `think` โ€” small budget
  • `think hard` / `think harder` โ€” medium
  • `ultrathink` โ€” maximum thinking budget

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 slash commands

A handful of slash 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
  • /cost โ€” show token usage and $ spend for the session
  • /model โ€” switch model (e.g. Sonnet โ†” Opus)
  • /init โ€” generate a starter CLAUDE.md for this repo

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

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>

๐Ÿ†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