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 |
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 ambitiousstill helps — it tells Claude about scope, which only you know.think step by stepandbe thoroughdo 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
Stophook that blocks 8 stops in a row with no tool call between is overridden; raise it withCLAUDE_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
Readdeny catchescat .envbut not a script that opens it; aWebFetchdeny doesn’t stopcurlunless the sandbox is on. For security, use both deny rules and the sandbox. promptandagenthooks are not deterministic — usecommandorhttphooks 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
Escthe moment Claude drifts; work so far is kept. - Rewind freely:
Esc Escor/rewindrolls 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 →
/clearand one better prompt that folds in what you learned. - Side questions:
/btwanswers without adding to history. - Multi-day work:
/rename oauth-migration, laterclaude --resume oauth-migration.
6. Run it unattended — five questions first#
- Does it know what done looks like? A goal, a spec, or a failing test.
- Can it check its own work? Test suite,
Stophook, review step. - What may it touch? Permission rules,
dontAsk, sandbox, worktree, one branch. - What stops it?
--max-turns,--max-budget-usd, a spend limit. - 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.mdshort; 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
/usageshows a reason;/clearbetween tasks. - Before going unattended: define done, a check, a scope, a cap and a human sign-off.
References#
- Anthropic, Best practices for Claude Code.
- Anthropic, How Claude remembers your project and Extend Claude Code.
- Anthropic, Keep Claude working toward a goal and Hooks reference.
- Anthropic, Configure permissions, Sandboxing and Manage costs effectively.