Claude Code Best Practices From Anthropic's Docs

Claude Code best practices from Anthropic's own docs: tell Claude what it can't see, give it a check to run, enforce hard rules, and drop outdated tips.

Josh Pocock8 min read

Claude Code tips cover

AI Coding

Claude Code tips

Stride AI Academy

Anthropic's Claude Code best practice advice comes down to four moves: tell Claude what it can't see in the code, give it a check that comes back pass or fail, enforce the rules that can't have exceptions with hooks and deny rules, and only change a default when a task costs more than it should. The docs open by saying that in most cases your first plain prompt in a fresh session already does the right thing. The practices are for when it doesn't.

This guide sums up that page, adds the exact commands and config, and lists the old tips the docs now say to drop. For the step-by-step loop of explore, plan, build and review, see our Claude Code workflow. Everything here was checked against Claude Code's guidance on getting good results, plus the /goal and sandboxing docs, on November 22, 2026.

The four reasons a session goes wrong

Anthropic's guidance page says that when a session doesn't go the way you expected, it's almost always one of these:

What happened What's missing The fix
Claude built the wrong thing, or rediscovers the same fact every session Information it can't get from the repo Tell Claude what it can't see
Claude said it was done and it wasn't A way to check its own work Give Claude a check to run
Claude did something that must never happen, or skipped a must-do step Enforcement. A prompt can't guarantee it Use hooks, deny rules or managed settings
It worked but took too long, too many tokens or too many prompts A better default Change the permission mode, model, effort or subagent use

Know which instructions Claude can ignore

The rest of the page builds on one idea. Every instruction is one of two kinds:

  • Non-deterministic: your prompt, CLAUDE.md, a skill. Claude reads it and decides what to do. It usually follows, but there's no guarantee.
  • Deterministic: a hook, a deny rule, a managed setting. Claude Code, the harness, applies it every time, whatever the model decides.

The docs map common jobs to both:

Job Claude decides Claude Code enforces
What to do Prompt, CLAUDE.md, skills Hooks
What it can touch Auto mode's classifier Deny rules, the sandbox in strict mode, managed settings
When it's done A request for evidence, /goal, /code-review Tests, typecheck, a Stop hook, CI
How much it spends Effort level --max-turns or --max-budget-usd with -p, a spend limit

Most of the time you want Claude to decide. The docs' tip: if you keep adding emphasis to a CLAUDE.md line and Claude still misses it, the line belongs in a hook.

Tell Claude what it can't see

Current models read code well, so don't describe your file layout or conventions. Before writing anything down, the docs suggest two questions: could Claude find this by reading the code, and would it actually go and look? If both answers are yes, leave it out.

Write specific prompts

Name the file, describe the symptom and say what fixed looks like. The docs contrast "fix the login bug" with a prompt that names the timeout symptom, the folder to look in, and asks for a failing test first.

Hand over what you have instead of describing it: @ a file, paste a screenshot, or pipe output in with cat error.log | claude -p "what's going on here". When you want the fuller version of something, say be ambitious. Claude tends to build the smallest thing that satisfies a request.

Keep CLAUDE.md short

CLAUDE.md loads into every session, so every line costs a little attention on every task. Keep only what Claude can't work out from the code: the exact test and lint commands, misleading spots, decisions that live outside the repo, and anything you've corrected twice. Run /init for a starting file, then mostly delete. The memory guide recommends staying under 200 lines, and /doctor prompt-audit flags instructions written for older models. Our CLAUDE.md examples show real files.

Use rules and skills for the rest

Rules that only matter in one folder go in .claude/rules/ with a paths: filter, so they load only when Claude works there. Our Claude Code rules guide covers the format. Team procedures, such as cutting a release, go in a skill. Claude sees only its name and description until the task calls for it. Add disable-model-invocation: true to a skill with side effects so it only runs when you type it.

In a typed language, a code intelligence plugin lets Claude jump to definitions instead of reading many files.

Give Claude a check to run

The docs call this out as the move that lets Claude work without you watching. Claude stops when the work looks done. With a test file, a build exit code, a linter or a screenshot to compare, it fixes its own mistakes before you see them.

You can set the check at four strengths:

  1. In the prompt: run the auth tests after, and keep going until they pass
  2. As a goal: /goal all tests in tests/auth pass and lint is clean. A separate model checks after every turn. Our Claude Code /goal guide covers it.
  3. As a Stop hook: enforced by Claude Code, so the turn doesn't end until your script passes.
  4. By a fresh reviewer: /code-review reviews the diff in a subagent that never saw your conversation.

Here's the docs' Stop hook for a typecheck. Exit code 2 sends Claude back to work with the compiler output:

JSON
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          { "type": "command", "command": "pnpm tsc --noEmit 1>&2 || exit 2" }
        ]
      }
    ]
  }
}

Whichever you use, ask for evidence: the command Claude ran and its output. "All tests pass" alone tells you very little.

Enforce the rules that can't have exceptions

If something has to happen every time, make it configuration. The docs' three examples: Never read .env, Always run the formatter after editing and Don't touch the migrations folder.

  • Hooks run your command at fixed points, such as after every Edit or Write. For real enforcement use a command, http or mcp_tool hook. A prompt or agent hook asks another model, so it isn't deterministic. Our hooks tutorial has examples.
  • Deny rules hold in every permission mode, including auto and bypassPermissions. See Claude Code permissions.
  • The sandbox adds an OS-level limit on shell commands. Strict mode turns off the retry outside it.

Keep the enforced set small. If you have forty hooks and deny rules, the docs say most are probably preferences Claude could have weighed itself.

Change a default only when it costs you

A new session starts in auto mode in the terminal and VS Code, runs Opus 5.5 at medium effort on most plans, delegates to subagents when it sees a reason, and compacts as it grows. When a task costs too much, run /usage to see where it went. Then:

  • Effort: /effort high or /effort xhigh for easy-to-miss cases like a flaky test, /effort low for quick back-and-forth. Save max for hard problems. Put ultrathink in one prompt for a one-off.
  • Model: Sonnet costs less on routine work, and Haiku suits simple subagent jobs.
  • Context: /clear between unrelated tasks costs nothing.

Before a run goes unattended

The docs give five questions to answer for the specific task:

  1. Does it know what done looks like? A goal, a spec or a failing test.
  2. Can it check its own work? Tests, a Stop hook or a review step.
  3. What can it touch? Permission rules, the sandbox, a worktree, one branch.
  4. What stops it? --max-turns, --max-budget-usd or a spend limit.
  5. Where does the result go, and who signs off? A pull request and a person approving the merge.

For timed runs, use /loop in an open session or routines in the cloud. For several sessions at once, give each a git worktree.

Old Claude Code tips you can stop following

The page ends with advice current models have made unnecessary:

Old tip What the docs say now
Manage the context window aggressively Most current models have a 1M-token window and compact on their own. Still /clear between tasks
Add IMPORTANT or ALL CAPS Plain wording works. Emphasis makes Claude over-apply the rule
Use subagents to protect context Use them for parallel work, noisy output and fresh review
Delegate for a better answer Same model, same task. A fresh reviewer helps, delegation doesn't
"think hard", "be thorough" Effort is the control. ultrathink still works for one turn
"keep going, don't be lazy" Give a check to pass instead, or use /goal
Describe your architecture in CLAUDE.md Claude reads the repo itself

Learn to build with Claude Code

The Stride AI Coding course teaches Claude Code and Codex for building client tools, written for non-programmers, with weekly live calls to review your builds. Many of the free guides cover Claude Code setups, and the Claude Code community is where members compare theirs.

FAQ

What are the best ways to use Claude Code?

Anthropic's docs boil them down to four: tell Claude what it can't see in the repo, give it a check that comes back pass or fail, enforce rules that can't bend with hooks and deny rules, and change a default only when a task costs too much.

What's the most useful Claude Code tip?

Give Claude a check to run. The docs say that with a test, build or linter to run, Claude can fix its own mistakes and keep going without you watching. Put the command that runs it in CLAUDE.md.

How long should CLAUDE.md be?

Short. The memory guide recommends under 200 lines. Keep only what Claude can't work out from the code: commands, misleading spots, decisions outside the repo and repeated corrections.

Why does Claude ignore a line in my CLAUDE.md?

The docs give two reasons: the file is long enough that the line gets lost, or the line is a rule with no exceptions. Shorten the file, or move the rule into a hook or deny rule.

Build it with us in Stride AI Academy

Four courses, weekly live calls and a community of people building and selling AI. Or start with 320+ free guides.

Keep reading

Free AI Coding guides