Claude Code Best Practices

Anthropic's Claude Code best practices come down to three things: tell Claude what it cannot see in the code, give it a check to run that passes or fails, and enforce rules that cannot have exceptions with hooks and deny rules instead of CLAUDE.md lines.

Anthropic's best practices for Claude Code, as rewritten for its current models, reduce to three habits: tell Claude what it cannot learn from the repository, give it a check it can run that comes back pass or fail, and enforce any rule that must never bend with a hook or deny rule rather than a line in CLAUDE.md (Best practices for Claude Code, read Nov 6, 2026). The same page starts from the claim that a plain first prompt in a fresh session usually works with no setup, because sessions start in auto mode, delegate to subagents and compact on their own; the advice is for when those defaults are not enough.

Quick facts

Main rule Give Claude a pass/fail check (tests, build, linter)
CLAUDE.md Short; under 200 lines; start with /init
Between tasks /clear
Steering Esc to stop, /rewind (or Esc twice) to roll back
Effort Default medium on Opus 5.5; raise for tricky bugs
Parallel work claude -w <name> worktrees, the desktop app, cloud sessions
Unattended runs claude -p with --max-turns or --max-budget-usd

Sources for the table: Best practices for Claude Code, Anthropic, read Nov 6, 2026.

When sessions go wrong

Anthropic names four failure patterns, each with its own fix (Best practices for Claude Code, read Nov 6, 2026):

  1. Claude built the wrong thing, or rediscovers the same fact every session: it is missing information. Tell it.
  2. Claude said "done" and was not: it had no way to check. Give it a check.
  3. Claude did something forbidden or skipped a required step: a prompt cannot guarantee either. Enforce it.
  4. It worked but cost too much time, tokens or prompts: change a default (mode, model, effort).

Tell Claude what it cannot see

Write a specific prompt: name the file, describe the symptom and say what fixed looks like. Anthropic's example turns "fix the login bug" into a request to look at token refresh in src/auth/, write a failing test that reproduces the timeout and then fix it. Hand over what you have instead of describing it: @path to include a file, a pasted screenshot, or piped output (cat error.log | claude -p "what's going on here"). Phrases like "think step by step" are ordinary text, not switches; "be ambitious" helps when you want the full version with edge cases rather than the smallest thing that works (Best practices for Claude Code, read Nov 6, 2026).

When you do not know yet what you want, brainstorm first: ask Claude to interview you until it could write the spec, save it to SPEC.md, then start a fresh session to build from it. Plan mode (Shift+Tab or /plan) does the same for a known task, Claude exploring and writing a plan before touching code; see Claude Code Permissions and Modes.

Keep CLAUDE.md short

CLAUDE.md loads into every session, so every line costs a little attention on every task. Anthropic's test for each line: could Claude find this by reading the code, and would it actually look? If both answers are yes, leave it out. What belongs: the exact test, typecheck and lint commands, places where the code misleads, team decisions that are not in the repository, and anything you have corrected twice. /init writes a first draft; the memory guide recommends staying under 200 lines; /doctor suggests cuts. Personal preferences go in CLAUDE.local.md, rules for one part of the code in .claude/rules/ with a paths: filter, and team procedures such as cutting a release in a skill, which loads only when used (Best practices for Claude Code, read Nov 6, 2026).

Give Claude a check to run

This is the page's central advice: give Claude something it can run that returns pass or fail, and it can keep going on its own. A test file, a build's exit code, a linter, a script that diffs output against a fixture or a browser screenshot all count. The check can be enforced at rising strength: say it in the prompt ("run the auth tests after, and keep going until they pass"), set a /goal that a separate model checks after every turn, add a Stop hook that refuses to let Claude finish while the check fails, or have a reviewer who did not write the code run /code-review. Whatever the method, ask for evidence: the command Claude ran and its output, not "all tests pass" (Best practices for Claude Code, read Nov 6, 2026). When asking for a review against a spec, Anthropic adds "skip style", since a reviewer asked to find problems always finds something.

Enforce rules that cannot have exceptions

CLAUDE.md is guidance Claude may judge not to apply. For "never read .env", "always run the formatter" or "do not touch migrations", use configuration Claude Code itself applies: a PostToolUse hook to format, a PreToolUse hook to block a folder, and deny rules such as Read(./.env), which hold in every mode. Turn on the Bash sandbox (/sandbox) for an operating-system limit on files and network. Anthropic's own warning sign: if you keep adding IMPORTANT to a CLAUDE.md line and Claude still misses it, it belongs in a hook. The reverse also holds: hooks for mere preferences should go, and forty enforced rules usually means most were preferences (Best practices for Claude Code, read Nov 6, 2026).

Context, cost and steering

  • /clear between unrelated tasks: it costs nothing and stops the next task paying for the last one's history.
  • /compact with a focus ("keep the API changes and the test commands") on long sessions, knowing it is itself a large request.
  • /usage shows where usage went, by skill, subagent, plugin and MCP server, on paid plans.
  • Watch the first minute, press Esc the moment Claude drifts, and after two failed corrections /clear and write a better prompt instead of a third correction.
  • /rewind (or Esc twice) rolls code and conversation back to an earlier prompt, which makes it cheap to try the bold approach first; checkpoints do not cover files changed only by shell commands, so keep using git.

Source: Best practices for Claude Code, read Nov 6, 2026. The prompt cache lasts about an hour on a subscription and five minutes on an API key, so a long idle pause makes the next turn of a big session cost more. See How to Make Claude Usage Limits Last.

Model, effort and subagents

The default is Claude Opus 5.5 at medium effort. Raise effort (/effort high or xhigh) for bugs in code you did not write, flaky tests or schema changes with many readers; lower it for quick back-and-forth; keep max for hard unattended problems such as security hunts, since it tends to overthink ordinary work. Type ultrathink for one deeper turn (Best practices for Claude Code, read Nov 6, 2026). Subagents pay off for parallel work, noisy output and independent review, but each one spends tokens from the same budget and does not make the answer smarter; set model: haiku on simple ones.

Parallel sessions and worktrees

For separate pieces of work at once, give each its own checkout: claude -w feature-auth starts a session in a new git worktree, the desktop app runs several side by side, and cloud sessions run them off your machine. A worktree lacks gitignored files such as .env; list them in .worktreeinclude and Claude Code copies them in. /batch splits one large mechanical change into 5 to 30 units, each in its own worktree with its own pull request. A second session reviewing the first one's work is the cheapest independent reviewer (Best practices for Claude Code, read Nov 6, 2026).

What you can stop doing

Anthropic lists advice that its current models made unnecessary: managing context aggressively (most models now have a 1M-token window and compact on their own, though /clear between tasks still helps); IMPORTANT or all-caps emphasis, which makes Claude over-apply rules; subagents just to save context; delegating to a subagent for a better answer; "think hard" phrases, replaced by effort; "keep going, don't be lazy" lines, which cause over-work; and describing the architecture in CLAUDE.md, since Claude reads the repository itself (Best practices for Claude Code, read Nov 6, 2026). Older guides and videos from 2025 often recommend several of these, so check a tip's date before following it.

Frequently asked questions

What are the best practices for Claude Code? Anthropic's guide says to tell Claude what it cannot see in the repository, give it a test or other pass/fail check to run, enforce must-follow rules with hooks and deny rules, keep CLAUDE.md short, and /clear between tasks.

How long should CLAUDE.md be? Anthropic's memory guide recommends under 200 lines, holding only what Claude cannot work out from the code: commands to verify work, misleading spots, team decisions and repeated corrections.

Should I use /clear or /compact in Claude Code? Use /clear between unrelated tasks, since it is free and keeps old history from being re-sent; use /compact with a focus when a long task should continue with a summary. Claude Code also compacts on its own near the context limit.

Does saying "think hard" still work in Claude Code? Not as a switch: effort level controls how hard Claude thinks, and phrases like "think hard" are ordinary text. The keyword ultrathink still asks for deeper reasoning on one turn.

How do I run several Claude Code sessions at once? Start each in its own git worktree with claude -w <name>, or use the desktop app's parallel sessions or cloud sessions, so their edits cannot collide.

Sources

Moments

Context Management in Claude Code

Claude

  1. Write a specific prompt: name the file, describe the symptom and say what fixed looks like. Anthropic's example turns…

The Explore → Plan → Code → Commit workflow in Claude Code

Claude

  1. When you do not know yet what you want, brainstorm first: ask Claude to interview you until it could write the spec…

What are skills?

Claude

  1. CLAUDE.md loads into every session, so every line costs a little attention on every task. Anthropic's test for each…

Building verification loops in Claude Code

Claude

  1. This is the page's central advice: give Claude something it can run that returns pass or fail, and it can keep going…

Using Claude Opus 5.5 as your daily driver

Claude

  1. The default is Claude Opus 5.5 at medium effort. Raise effort (/effort high or xhigh) for bugs in code you did not…

See also

About this page

Last updated Nov 6, 2026 by the Vi.ki team. Page text CC BY-SA 4.0.

Edit History

Hotkeys

/
Jump to the search box
? or Ctrl + /
Open this list
Esc
Close this list, the photo viewer, or the account menu

Video

Space or K
Play or pause
← →
Back or forward 5 seconds
J L
Back or forward 10 seconds
0 to 9
Go to 0% to 90% of the video
, .
Previous or next frame, while paused
M
Mute or unmute
C
Captions on or off
F
Full screen on or off
A D
Previous or next moment

Photo viewer

← → or A D
Previous or next photo
↑ ↓ or W S
Previous or next photo
Home End
First or last photo
I
Show or hide the photo's info
Z
Clickless on or off: a pointer over a thumbnail shows it
N
Compare with the last photo: back to the one shown before this, and N again comes back
Q
Move the thumbnails to the next edge: top, bottom, left and round
, or Ctrl + ,
Open or close the viewer's settings
V
Clickless pan: a zoomed photo follows the pointer, rather than being dragged
Shift
Browse on or off
B
Show or hide the button bar
T
Show or hide the thumbnails
1
100% zoom on or off
0
Rate the photo as no opinion; again takes the answer back
+ -
Rate the photo a step higher or lower
F
Full screen: the photo alone. F again puts everything back.
Back to top