Claude Code Best Practices Cheatsheet

A one-page reference for working well with Claude Code: tell it what it can't see, give it a check to run, enforce rules that can't have exceptions, change defaults only with evidence, steer the session, and run it safely unattended — plus the old advice you can stop following.

On this page

Simple definition#

Claude Code’s defaults already do the right thing for most prompts: auto mode, Opus 5.5 at medium effort, automatic sub-agents and automatic compaction. Best practice is mostly about the few things no default can know — what is not in your repo, how to check the work, which rules can never bend, and what you are willing to spend.

When a session goes wrong, it is one of four things#

Symptom Root cause Fix
Built the wrong thing, or rediscovers the same fact every session Missing information that is not in the repo Tell it what it can’t see
Said “done” and it wasn’t No check to run Give it a check
Did something that must never happen, or skipped a mandatory step A rule written as advice Enforce it
Right answer, but too slow, costly or prompt-heavy A default that doesn’t fit this task Change a default
From task to merged change: plan, build, check, review · drawn with Archify · zoom, guided views, search and SVG/PNG export. © 2026 Samir Kumar Sahoo, all rights reserved. Open full screen ↗

Advise or enforce?#

Advise — Claude decides Enforce — the harness decides
What to do Prompt, CLAUDE.md, skills Hooks; skills only you can start (disable-model-invocation)
What it can touch Auto mode’s classifier Deny rules, sandbox in strict mode, managed settings
When it’s done Ask for evidence, /goal, /code-review Tests, typecheck, a Stop hook, CI
How much it spends Effort level --max-turns, --max-budget-usd, spend limits
Who has the last word Claude’s summary Branch protection, a human approving the merge

1. Tell Claude what it can’t see#

The test before writing anything down: Could Claude find this by reading the code? Would it actually go and look? If both are yes, leave it out.

Write specific prompts — name the file, the symptom, and what “fixed” looks like.

Instead of Try
“fix the login bug” “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”
“add a calendar widget” “follow the pattern in HotDogWidget.php; build a calendar widget with month picker and year paging. No new libraries”
“build the settings page” “build the settings page from the mockup. Be ambitious: empty and error states, save flow, keyboard navigation”
  • Hand over, don’t describe: @path/to/file, paste a screenshot, or pipe output: cat error.log | claude -p "what's going on here".
  • Brainstorm first when unsure: “Interview me until you could write the spec, then write it to SPEC.md.” Then build from a fresh session.
  • be ambitious still helps — it tells Claude about scope, which only you know. think step by step and be thorough do not raise effort.

Keep CLAUDE.md short (under 200 lines). Put in it only:

  • How to confirm work: exact test, typecheck, lint and single-test commands.
  • Where the code misleads: legacy patterns not to copy, directories that look dead but aren’t.
  • Decisions not in the repo: the error helper you chose, how deploys work, what needs migration review.
  • Anything you have corrected twice.
Where What goes there
CLAUDE.md Every-session facts for the whole project
CLAUDE.local.md (gitignored) Your personal preferences
.claude/rules/*.md with paths: Rules for one part of the codebase
.claude/skills/<name>/SKILL.md Procedures and team knowledge — loaded only when needed
MCP server or a CLI (gh, --help) Systems Claude can’t see: tracker, dashboards, databases
Code-intelligence plugin Go-to-definition for typed languages

Tooling: /init drafts it, /doctor suggests cuts, /doctor prompt-audit finds stale or contradictory lines, /context all confirms it loaded.

2. Give Claude a check to run#

Claude stops when the work looks done. Give it something that returns pass or fail — a test, a build exit code, a linter, a fixture diff, a screenshot next to the mockup — and it closes the loop itself.

Strictness How Who decides
In the prompt “run the auth tests after, and keep going until they pass” Claude
As a goal /goal all tests in tests/auth pass and lint is clean A separate evaluator model, after every turn
As a Stop hook Script exits 2 → Claude must keep working The harness
By a fresh reviewer /code-review, or a read-only reviewer sub-agent A context that never saw the reasoning
By running the app /verify builds, runs and observes the change Claude, with real evidence
{
  "hooks": {
    "Stop": [{ "hooks": [{ "type": "command", "command": "pnpm tsc --noEmit 1>&2 || exit 2" }] }]
  }
}
  • Ask for evidence: the command it ran and its output. “All tests pass” alone tells you little.
  • Review against the spec, and say “skip style” — a reviewer asked to find problems always finds something.
  • A Stop hook that blocks 8 stops in a row with no tool call between is overridden; raise it with CLAUDE_CODE_STOP_HOOK_BLOCK_CAP.

3. Enforce rules that can’t have exceptions#

Rule Enforce with
Never read .env or secrets deny: ["Read(./.env)", "Read(./secrets/**)"] + /sandbox
Always format after editing PostToolUse hook on Edit|Write
Never touch migrations/ or src/gen/ PreToolUse hook that exits 2 for those paths
Never push without review ask: ["Bash(git push *)"], branch protection
Scan commits for secrets, even if the scanner is down command hook with onFailure: "block"
Org-wide security policy Managed settings
  • Deny rules hold in every mode, including auto and bypassPermissions.
  • Rules match tool calls, not intent: a Read deny catches cat .env but not a script that opens it; a WebFetch deny doesn’t stop curl unless the sandbox is on. For security, use both deny rules and the sandbox.
  • prompt and agent hooks are not deterministic — use command or http hooks for enforcement.
  • Ask Claude to write the hook: “write a hook that blocks edits to the migrations folder”, then check /hooks.
  • Keep the enforced set small. At forty hooks and deny rules, most are preferences.
File Applies to
~/.claude/settings.json, .claude/settings.local.json You only
.claude/settings.json (committed) Everyone in the repo (allow rules and hooks after workspace trust)
Managed settings The organisation; cannot be overridden

4. Change a default only with evidence#

Run /usage first — it shows where time, tokens and prompts went, by skill, sub-agent, plugin and MCP server.

Default Change it when How
Auto mode You want to see every action → Manual; classifier blocks routine work → tune it Shift+Tab; autoMode.environment / allow in ~/.claude/settings.json (keep "$defaults"); /auto-mode-setup
Medium effort Easy-to-miss cases (unfamiliar code, flaky test, schema change) → high/xhigh; fast back-and-forth → low; hard unattended problem → max /effort, or ultrathink for one prompt
Opus 5.5 Routine work → Sonnet; hardest problems → Fable; simple sub-agents → Haiku /model, model: haiku in an agent file
Auto sub-agents They cost more than they save Short summaries back, model: haiku, read-only tools:, check /usage
Auto compaction A long session is paying for stale history /clear between tasks; /compact <focus>

5. Steer the session#

  • Watch the first minute. Press Esc the moment Claude drifts; work so far is kept.
  • Rewind freely: Esc Esc or /rewind rolls back code, conversation or both — so try the bold approach first. Checkpoints don’t cover files changed only by Bash; keep using Git.
  • Two failed corrections → /clear and one better prompt that folds in what you learned.
  • Side questions: /btw answers without adding to history.
  • Multi-day work: /rename oauth-migration, later claude --resume oauth-migration.

6. Run it unattended — five questions first#

  1. Does it know what done looks like? A goal, a spec, or a failing test.
  2. Can it check its own work? Test suite, Stop hook, review step.
  3. What may it touch? Permission rules, dontAsk, sandbox, worktree, one branch.
  4. What stops it? --max-turns, --max-budget-usd, a spend limit.
  5. Where does the result go, and who signs off? A PR and a human merge.
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

Try three files, fix the prompt, then run the rest. See Automation and parallel work for CI, schedules, worktrees and teams.

Old advice you can stop following#

Old advice Why it’s gone
Manage the context window aggressively 1M-token windows and auto-compaction make running out rare. Still /clear between tasks for focus and cost.
IMPORTANT / ALL CAPS on missed rules Current models follow plain wording; emphasis causes over-application. Shorten the file or make it a hook.
Sub-agents to protect context Use them for parallelism, noisy output and independent review — and pay knowingly.
Delegate for a better answer Same or smaller model, less context. A fresh reviewer helps; plain delegation doesn’t.
“think hard”, “be thorough” Effort is the control. ultrathink still works for one turn.
“Keep going, don’t be lazy” Causes over-work. Give a check to pass; for unattended runs use /goal or a Stop hook.
Describe architecture in CLAUDE.md Claude reads the repo. Write only what isn’t there.

Common mistakes#

Review questions#

A rule in CLAUDE.md is ignored once in twenty sessions. What do you do? If it is a guideline, accept it or shorten the file so the line isn’t lost. If it can have no exceptions, move it to a hook or deny rule.

What is the difference between /goal and a Stop hook? /goal is session-scoped and judged by a separate model reading the transcript; a Stop hook lives in settings, applies to every session in scope, and can run a deterministic script.

When should you raise effort, and when lower it? Raise for work where overlooked cases matter (unfamiliar code, flaky tests, schema changes); lower for quick iterative work you review each step; reserve max for hard unattended problems.

Summary#

  • Write down only what Claude can’t find; keep CLAUDE.md short; use rules, skills and MCP for the rest.
  • Give Claude a pass/fail check and ask for evidence.
  • Enforce zero-exception rules with hooks, deny rules, the sandbox and managed settings.
  • Change defaults only after /usage shows a reason; /clear between tasks.
  • Before going unattended: define done, a check, a scope, a cap and a human sign-off.

References#