Claude Code cheat sheet

A scannable Claude Code reference: 25 short snippets across 11 topics, each linking back to the lesson it came from.

At a glance

TopicWhat it covers
Installing and configuring Claude CodeClaude Code is an agentic coding assistant that runs in your terminal, inside the directory you start it from. It readslesson
A typical editing workflowThe most expensive sessions are the ones where the agent starts editing before it understands the code. Ask for anlesson
Permissions and safety with agentsPermission modes, why deny rules matter more than instructions, and the specific risks of an agent that can run shelllesson
Managing the context window and session hygieneThe context window is the model's working memory for one session. Everything competes for it: the system prompt, yourlesson
Slash commands and reusable promptsAny markdown file in .claude/commands becomes a slash command named after the file. The body is the prompt; thelesson
Scoped instructions: memory, rules and path-specific contextMore specific files are appended after more general ones, so a directory-level instruction can refine or contradict alesson
Subagents and context isolationA subagent runs in its own conversation with its own context window. It reads files, greps, and explores, and returnslesson
Hooks and deterministic automationHooks are shell commands, HTTP calls or prompts that run at fixed points in a session. They are deterministic: unlikelesson
Skills, plugins and marketplacesA skill packages instructions plus optional supporting files. Only the name and description sit in context until thelesson
Cost, model choice and troubleshootingKeep the source of truth in version control. Before each session, commit or stash, so the worst case is git checkout --lesson
Building your own agent with the Agent SDKThe CLI is an agent application built on the Agent SDK. Shelling out with -p covers scripts and CI. Building on the SDKlesson

Quick snippets

Installing and configuring Claude Code

Install and authenticate

# install the CLI
npm install -g @anthropic-ai/claude-code
claude --version

# run it from the project root, not from your home directory
cd ~/work/my-service
claude
# first launch: sign in, then verify the working directory it reports

Instructions and permissions

<!-- CLAUDE.md, at the repository root, committed with the code -->
# Working agreement

- Run `npm test` before claiming any task is complete; paste the summary.
- Never edit files under dist/ or any generated file.
- Prefer the existing helpers in src/lib/ over new dependencies.
- Two-space indentation, no semicolons, single quotes.

<!-- These are instructions, not enforcement. Permissions decide what can run. -->

Instructions and permissions

{
  "permissions": {
    "allow": ["Bash(npm test)", "Bash(npm run lint)", "Read(./src/**)"],
    "deny":  ["Read(./.env)", "Read(./secrets/**)", "Bash(curl:*)"],
    "ask":   ["Bash(git push:*)", "Bash(npm install:*)"]
  }
}

Full lesson: Installing and configuring Claude Code →

A typical editing workflow

Explore and plan before editing

> /init
  reads the repository and writes a starter CLAUDE.md you can edit

> how does the auth middleware attach a user to the request? cite the files.
  < explanation with file:line references

> that is wrong about the refresh path - it re-reads the cookie at line 42.
  now propose a plan to return 401 when the token is expired, and change nothing yet

> proceed, then run the tests. keep the change to src/auth/ and its test file.

Edit, verify, commit

git status --short        # clean before the agent starts
git switch -c agent/expiry-401

# ... one focused request, then review
git diff                  # read the whole patch
npm test                  # run the gate yourself
git add -p && git commit -m "Return 401 for expired tokens in auth middleware"

# clear context between unrelated tasks so old noise stops influencing edits
# (inside the session: /clear)

Full lesson: A typical editing workflow →

Permissions and safety with agents

Modes and rules

claude --permission-mode plan

# A narrow allow-list beats a broad mode: allow the commands you actually use
#   "allow": ["Bash(npm test)", "Bash(npm run lint)", "Bash(git diff:*)", "Read(./src/**)"]
#   "deny":  ["Read(./.env)", "Bash(rm -rf:*)", "Bash(git push --force:*)"]

Full lesson: Permissions and safety with agents →

Managing the context window and session hygiene

What fills the window

# inside a session
/context        # token usage broken down by source
/cost           # what this session has spent so far
/clear          # start over with an empty conversation
/compact        # summarise the conversation so far and continue

# from the shell
claude -c                       # continue the most recent session
claude -r                       # pick a past session to resume
claude --fork-session -c        # resume, but branch instead of overwriting

Session hygiene that keeps quality up

# a cheap way to cap how much output enters the window
npm test 2>&1 | tail -40

# check what a file costs before reading it
wc -l src/server/*.js

# non-interactive, with a hard ceiling on turns
claude -p "list the exported functions in src/api" --max-turns 3

Resuming, branching and long-running work

# a long refactor split into three resumable sessions
claude -p "rename the User model to Account across src/models and update imports" --max-turns 20
claude -c -p "now update the tests to match the rename"
claude -c -p "summarise what changed and which files still reference the old name"

Full lesson: Managing the context window and session hygiene →

Slash commands and reusable prompts

A command is a markdown file

# after saving as .claude/commands/review.md
/review error handling in the upload path

# subdirectories create a namespace
# .claude/commands/db/migrate.md  ->  /db:migrate

Arguments and shell substitution

---
description: Explain a failing test file
allowed-tools: Read, Bash(npm test:*)
---
The test file $1 is failing. Run it, then explain the failure.

Recent commits touching it:
!git log --oneline -5 -- $1

Keeping a command library useful

claude
> /help            # commands appear alongside the built-ins
> /review          # project command, from .claude/commands/review.md

# personal shorthand, available in every repo
mkdir -p ~/.claude/commands

Full lesson: Slash commands and reusable prompts →

Scoped instructions: memory, rules and path-specific context

Path-scoped rules

---
paths:
  - "src/api/**/*.ts"
  - "src/workers/**/*.ts"
---

# Server-side rules

- Every handler validates input with the schema from src/schemas.
- Never log a full request body; log the request id instead.
- Return the error envelope: { error: { code, message } }.
- Database access goes through the repository module, never raw SQL here.

Why mid-session edits do not apply

# the honest sequence
vim CLAUDE.md          # add: "always run npm test before finishing"
# ... the running session does not know about this

# a new session picks it up
exit
claude

Full lesson: Scoped instructions: memory, rules and path-specific context →

Subagents and context isolation

Invoking and designing them

# list and manage definitions
/agents

# delegate explicitly
> use the code-reviewer subagent on the staged diff

# fan out deliberately: several independent searches in parallel
> use three subagents to locate the rate limiter, the retry policy and the timeout config

Concurrency and cost

---
name: migration-auditor
description: Audit a directory for patterns that block a framework migration.
tools: Read, Grep, Glob
model: haiku
---

Audit the path given in the task. Report only files that need manual changes,
each as: path, line, pattern found, suggested replacement.
Do not explain the migration. Do not read test fixtures.

Full lesson: Subagents and context isolation →

Hooks and deterministic automation

Blocking a call

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write|MultiEdit",
        "hooks": [
          { "type": "command", "command": ".claude/hooks/guard-secrets.sh" }
        ]
      }
    ]
  }
}

Hook safety and debuggability

# verify that stdin really is what you think it is
echo '{"tool_name":"Write","tool_input":{"file_path":".env","content":"A=1"}}' \
  | .claude/hooks/guard-secrets.sh ; echo "exit=$?"

# then force the whole run to fail when the guard is wrong
claude -p "append DEBUG=1 to .env" --allowedTools "Edit" ; echo "exit=$?"

Full lesson: Hooks and deterministic automation →

Skills, plugins and marketplaces

Bundling a setup as a plugin

my-plugin/
  .claude-plugin/
    plugin.json          # name, version, description, author
  commands/
    review.md            # becomes /review
  agents/
    code-reviewer.md     # a subagent definition
  skills/
    release-notes/
      SKILL.md
  hooks/
    hooks.json           # hook configuration shipped with the plugin

Bundling a setup as a plugin

{
  "name": "acme-standards",
  "version": "1.2.0",
  "description": "Review commands, release-notes skill and lint hooks for Acme services"
}

Full lesson: Skills, plugins and marketplaces →

Cost, model choice and troubleshooting

Model choice and effort

# per session
/model                 # switch interactively
/cost                  # usage for this session

# per invocation
claude -p "rename getUser to fetchUser everywhere" --model haiku
claude --model opus

# from the environment
export ANTHROPIC_MODEL=claude-sonnet-4-5

Diagnosing loops and thrashing

# give evidence, not opinions
npm test 2>&1 | tail -60 > /tmp/fail.txt
claude -p "Here is the real failure output. Read /tmp/fail.txt and the handler it names, then state the root cause before changing anything."

# cap the blast radius of an experiment
claude -p "make the failing test in src/cart.test.ts pass without touching any other file" \
  --max-turns 12

Health checks and bad edits

claude doctor        # installation, auth and environment health
claude --version
/status             # account, model and workspace in a session
/doctor             # same checks from inside a session

Full lesson: Cost, model choice and troubleshooting →

Building your own agent with the Agent SDK

When to build rather than drive the CLI

npm install @anthropic-ai/claude-agent-sdk
# or, for Python
pip install claude-agent-sdk

Custom tools and evaluation

const cases = [
  { q: "Why did order A-1042 fail?", expect: ["declined", "insufficient funds"] },
  { q: "Which orders are stuck in review?", expect: ["A-1030"] },
];

for (const c of cases) {
  const answer = await runOnce(c.q);
  const ok = c.expect.some((e) => answer.text.toLowerCase().includes(e));
  console.log(ok ? "pass" : "FAIL", "|", c.q, "| turns:", answer.numTurns);
}

Full lesson: Building your own agent with the Agent SDK →

FAQ

Is this Claude Code cheat sheet free to use?
Yes. No sign-up and no tracking: the page is static, every example is on the page itself, and you can print it or save it as a one-page reference.
Where do the examples come from?
Every snippet is taken from the 11 lessons of the Claude Code course on this site, and each section links back to the lesson it was pulled from.
How do I go deeper than a cheat sheet?
Open the full Claude Code course — it carries the worked explanations, the edge cases and the exercises behind every line here.

AI Basics AI Agents Math for AI Machine Learning scikit-learn TensorFlow

Last refreshed 2026-09-27.