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):
- Claude built the wrong thing, or rediscovers the same fact every session: it is missing information. Tell it.
- Claude said "done" and was not: it had no way to check. Give it a check.
- Claude did something forbidden or skipped a required step: a prompt cannot guarantee either. Enforce it.
- 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
/clearbetween unrelated tasks: it costs nothing and stops the next task paying for the last one's history./compactwith a focus ("keep the API changes and the test commands") on long sessions, knowing it is itself a large request./usageshows where usage went, by skill, subagent, plugin and MCP server, on paid plans.- Watch the first minute, press
Escthe moment Claude drifts, and after two failed corrections/clearand write a better prompt instead of a third correction. /rewind(orEsctwice) 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
- Best practices for Claude Code, Anthropic, read Nov 6, 2026
- Model configuration, Anthropic, read Nov 6, 2026
- Checkpointing, Anthropic, read Nov 6, 2026
- Context Management in Claude Code, Claude, May 18, 2026 (video)
- The Explore → Plan → Code → Commit workflow in Claude Code, Claude, May 17, 2026 (video)
- What are skills?, Claude, Feb 26, 2026 (video)
- Building verification loops in Claude Code, Claude, Sep 25, 2026 (video)
- Using Claude Opus 5.5 as your daily driver, Claude, Sep 23, 2026 (video)
Moments
Context Management in Claude Code
Claude
The Explore → Plan → Code → Commit workflow in Claude Code
Claude
What are skills?
Claude
Building verification loops in Claude Code
Claude
Using Claude Opus 5.5 as your daily driver
Claude
See also
-
Claude CodeClaude Code is Anthropic's agentic coding tool. It reads a codebase, edits files, runs commands and opens pull requests from the terminal, VS Code, JetBrains IDEs, the Claude desktop app, the browser and Slack, and it comes with every paid Claude plan or a pay-as-you-go Console account. -
Claude Code HooksClaude Code hooks are shell commands (or HTTP calls, MCP tools or model checks) that Claude Code runs at fixed points such as before a tool call, after an edit or when Claude stops, configured under "hooks" in a settings.json file.
-
Claude Code Permissions and ModesClaude Code has six permission modes (Manual, Accept edits, Plan, Auto, Don't ask and Bypass permissions), cycled with Shift+Tab; since v2.1.283 interactive sessions start in auto mode, and --dangerously-skip-permissions turns every check off and belongs only in a container or VM.
-
CLAUDE.md and MemoryCLAUDE.md is a Markdown file of instructions that Claude Code loads at the start of every session, from your user folder (~/.claude/CLAUDE.md), the project (./CLAUDE.md) and a private CLAUDE.local.md; /init writes one. Claude Code also keeps an auto memory of what it learns, indexed in MEMORY.md, and reads AGENTS.md when there is no CLAUDE.md.
-
SkillsA Claude skill is a folder with a SKILL.md file of instructions, plus optional scripts and files, that Claude loads when a task needs it. Skills are on every Claude plan, Free included, and the same skill runs in the Claude app, Claude Code and the API. -
Claude Code CheckpointsClaude Code saves a checkpoint of your files before every prompt, so /rewind or Esc pressed twice can restore the code, the conversation or both to an earlier point. Checkpoints cover Claude's own file edits, not changes made only by shell commands or most subagents, so Git is still needed.