Claude Code Best Practices: Anthropic's Checklist

Short answer
Use Claude Code well by giving it context, a pass-or-fail check and a few enforced rules. Put only facts it cannot see in CLAUDE.md. Give it a test, build or lint command and ask for the output. Use a hook, deny rule or managed setting when a rule cannot have exceptions. A hook runs an action automatically, a deny rule blocks listed actions, and a managed setting locks an organization policy.
Then steer the session. Watch the first minute, press Esc when Claude drifts, and run /clear after 2 failed corrections.
Before you start
You need Claude Code and a repository with a test or build command.
- You will create a short
CLAUDE.md. - You will add
.claude/settings.jsonwith a Stop hook and deny rules. - You will finish with a simple steering routine.
Imagine a developer whose Claude Code sessions end with “done” while tests still fail. Claude once edited a generated folder that the team never changes by hand. The problem is not a missing ALL CAPS warning. The instructions are in the wrong places.
Guidelines Claude weighs, rules Claude Code enforces
Anthropic separates written guidance from rules that Claude Code enforces. Claude reads and weighs prompts, CLAUDE.md and skills. Claude Code itself applies hooks, deny rules and managed settings every time.
Where each instruction belongs
Question | Claude weighs it (guideline) | Claude Code enforces it (every time) |
|---|---|---|
What should it do? | Prompt, | Hook when the action must happen |
What can it touch? | A plain-language boundary | Deny rule or managed setting |
When is it done? | Definition of done in the prompt | Stop hook that runs the check |
Source: Anthropic, Claude Code best practices, read 3 November 2026.
If Claude keeps missing an emphasized CLAUDE.md line, Anthropic says that line belongs in a hook.
Step 1: Tell Claude what it cannot see
Write down only what Claude cannot learn by reading the repository. A good prompt names the file, describes the symptom and says what fixed looks like. When you want a fuller version, Anthropic says “be ambitious” still helps.
If the goal is unclear, ask Claude to interview you. Save the result in SPEC.md, then start a fresh session so the build has clean context and a written definition of done.
Run /init for a starting CLAUDE.md, then remove anything the code already shows. Anthropic's memory guide recommends staying below 200 lines. Run /context to confirm the file loaded.
- Put personal preferences in
CLAUDE.local.mdand add it to.gitignore. - Put area-specific rules in
.claude/rules/with apaths:filter. - Put team procedures in
.claude/skills/<name>/SKILL.md. - Use a CLI when the outside system has one. Otherwise, connect it through MCP.
Claude only knows the facts you write down; in the same way, AI engines describe your company from published information, which Xtrusio tracks across ChatGPT and Gemini.
Step 2: Give Claude a check to run
Give Claude a command that returns pass or fail. If the repository already has one, Anthropic calls it the most useful line in CLAUDE.md.
Ask for evidence when the task ends: the command, its output or a screenshot. Run /code-review when you want a fresh subagent to review the diff without the conversation history.
A Stop hook can run the check before Claude stops. Exit code 2 blocks the stop.
Step 3: Enforce rules that cannot have exceptions
Use a hook for an action that must run. Use a deny rule for files or commands Claude must never touch. Deny rules hold in every permission mode, including auto and bypassPermissions.
If something has to happen every time, make it a hook, a deny rule, or a managed setting.
Official wording: Anthropic, Claude Code best practices, read 3 November 2026, code.claude.com.
For an operating-system limit on files or network access, turn on the sandbox with /sandbox. Keep the enforced set small.
Our example: a starter setup for 1 repository
Our example (illustrative): StarterRepo.
StarterRepo runs tests and type checks before work is done. Its generated client folder is never edited by hand.
CLAUDE.md
Start with the checks and the repository facts that Claude cannot infer from the code.
## Checks
- Tests: npm test
- Type check: npm run typecheck
## Convention
- Put shared validation in src/validation/
## Gotcha
- generated/client/ is generated. Never edit it by hand.This file gives Claude the checks, 1 team convention and 1 repository gotcha.
.claude/settings.json
Then enforce the rule that must hold even when the model forgets a written guideline.
{
"hooks": {
"Stop": [{
"hooks": [{
"type": "command",
"command": "npm test 1>&2 || exit 2"
}]
}]
},
"permissions": {
"deny": ["Edit(generated/client/**)", "Write(generated/client/**)"]
}
}The Stop hook prevents a clean finish when the tests fail. With exit code 2, the test output on stderr goes back to Claude as the reason it cannot finish, so it sees which tests failed. The deny rules protect the generated folder in every permission mode. Run /context to confirm Claude loaded the repository instructions.
When it does not work
Use these checks when the hook or deny rule behaves differently from what you expect.
- Claude keeps getting blocked: the hook input has a
stop_hook_activefield. Exit early when it is true, or fix the failing test yourself. - The hook never fires: check that
settings.jsonis inside.claude/at the repository root. - Claude still edits a protected folder: open
/permissionsand check the path pattern. CLAUDE.mdis missing in/context: check the file name and location.
Step 4: Steer the session
Watch the first minute. Press Esc as soon as Claude drifts. It stops the current action but keeps the work so far. After 2 failed corrections, run /clear and write a better prompt.
Use /clear between unrelated tasks. Run /usage when a task costs more time or tokens than expected. Anthropic says Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 default to medium effort.
For parallel sessions, start work in a new worktree with:
claude -w feature-authBefore you let Claude run on its own
Make sure Claude knows what done looks like and can check its work. Limit what it can touch. Set a cap on turns or spend, then have a person approve the result.
Tell Claude what it cannot see, give it a check to run, enforce the hard rules, and steer the session.

Advice you can stop following
Anthropic's current guide drops two habits that older guides still repeat.
Old advice | What to do now |
|---|---|
Describe the repository architecture in | Let Claude read the repository. Write only what it cannot find there. |
Add IMPORTANT or ALL CAPS to missed rules. | Write the rule plainly. If it must always hold, enforce it. |
Check what AI engines say about your company
Get your free AI visibility check to see where ChatGPT and Gemini mention your business and which competitors appear instead.
Sources
- Anthropic, Claude Code best practices, read 3 November 2026.
- Xtrusio product page, read 3 November 2026.
Frequently asked questions
How long should CLAUDE.md be?
Anthropic's memory guide recommends staying under 200 lines. Shorter is better when the repository already shows the answer.
When should a rule become a hook?
Use a hook when the action must happen every time or Claude keeps missing the written guideline.
How do I make Claude check its work?
Give it a test, build or lint command that returns pass or fail. Ask for the command and output as evidence.
What should I do when Claude drifts?
Press Esc immediately. After 2 failed corrections, run /clear and improve the prompt.
Which old tips can I drop?
Stop filling CLAUDE.md with repository architecture. Stop piling on ALL CAPS emphasis.
Topics
- claude code best practices
Xtrusio
AI visibility research
Xtrusio is the Perception Engine for B2B brands.
Free check
See how AI engines answer about you
Get your free AI visibility check
Keep reading
Technical SEO · Nov 4, 2026 · 6 min readRankscale: What It Tracks, What It Costs and Alternatives
See what Rankscale tracks, its current credit-based prices, how far 1,200 credits go and how Xtrusio, Peec AI and Profound compare.
Technical SEO · Nov 4, 2026 · 5 min readClaude Code Router: What It Is and How to Set It Up
Learn what Claude Code Router does and set up its current desktop or npm UI route with providers, local ports, profiles, logs and fallbacks.
Technical SEO · Nov 4, 2026 · 6 min read