Claude Code Best Practices From Anthropic’s Own Docs

The one habit that pays off most in Claude Code is managing context. Anthropic’s best-practices page says it plainly: “Claude’s context window fills up fast, and performance degrades as it fills.”

Published:

Updated:

Claude Code Best Practices From Anthropic's Own Docs

The one habit that pays off most in Claude Code is managing context. Anthropic’s best-practices page says it plainly: “Claude’s context window fills up fast, and performance degrades as it fills.”

Almost every other tip follows from that: give Claude a way to verify its work, plan before coding, write specific prompts, keep your CLAUDE.md short, clear the session between unrelated tasks, and send investigation to subagents. This guide condenses the documented advice with the exact commands, and lists the failure patterns Anthropic names.

Quick answer

  1. Give Claude a way to verify: tests, a build or a screenshot to compare against.
  2. Explore, plan, then code, then commit.
  3. Prompt specifically: scope the task, point to sources, reference existing patterns, describe the symptom.
  4. Keep CLAUDE.md short and run /init to start it.
  5. Manage the session: /clear between unrelated tasks, /compact to summarize, /rewind to undo.

Do I need any setup at all?

Often no. Anthropic says a plain first prompt in a fresh session usually does the right thing. New terminal and VS Code sessions start in auto mode, where a classifier reviews risky commands before they run. Conversations are compacted automatically before the context window fills.

Setup pays off when your project holds knowledge Claude cannot see in the code: a deploy process that lives in someone’s head, a file that must never be read, or a check that must pass before work counts as done. The sections below cover those cases.

How do I let Claude check its own work?

The docs list several ways: tell Claude which tests to run, set a /goal condition, add a Stop hook as a deterministic gate, or use a verification subagent. A task with a pass/fail check is easier to finish than one judged by eye. That is the cheapest quality gain on this list.

Why explore, plan, code, commit?

Plan mode is entered with Shift+Tab or claude –permission-mode plan, and Ctrl+G opens the plan for editing. Planning costs a few minutes and saves rewrites on big changes. The docs say you can skip planning if “you could describe the diff in one sentence.”

What does a specific prompt look like?

Do Example from the documented approach
Scope the task Name the file, behavior and constraints
Point to sources Use @file, paste images or URLs
Reference patterns “Follow the pattern in an existing file”
Describe the symptom Pipe errors in: cat error.log | claude -p “explain this error”

How do I set up CLAUDE.md?

Run /init to generate a starting file, then cut it down. Anthropic suggests testing each line with: “Would removing this cause Claude to make mistakes?” If not, delete the line, because bloated files get ignored. Check the file into git and use /context to confirm it loaded. Anthropic’s memory page suggests targeting under 200 lines per file.

Which permissions, tools and extensions matter?

  • /permissions manages allowlists; /sandbox enables OS-level isolation.
  • Command-line tools such as gh and aws work well. Add MCP servers with: claude mcp add –transport http notion https://mcp.notion.com/mcp
  • Use hooks for actions that must always happen, skills in .claude/skills/<name>/SKILL.md, subagents in .claude/agents/ and plugins via /plugin.

How do I manage a session?

Need Command or key
Stop Claude Esc
Rewind Esc twice or /rewind
Fresh start between tasks /clear
Summarize with focus /compact <instructions>
Side question /btw
Continue or resume claude –continue, claude –resume

The docs add a firm rule: after two failed corrections, run /clear and rewrite the prompt with what you learned. A third patch on a polluted context rarely works.

When should I use subagents and automation?

Use subagents for investigation so exploration does not fill the main context. For scripts, claude -p “…” –output-format json runs non-interactively. The /batch command splits work into 5 to 30 subagents in worktrees. See our subagents and agent teams guide.

Which mistakes does Anthropic warn about?

  • The kitchen-sink session that mixes unrelated tasks. Fix: /clear between tasks.
  • Repeated corrections instead of a clean restart. Fix: restart after two misses.
  • An over-specified CLAUDE.md. Fix: delete lines that change nothing.
  • The trust-then-verify gap, which means accepting output without checking. Fix: add a test or a screenshot.
  • Infinite exploration with no stopping point. Fix: scope the search or hand it to a subagent.

What should I do first?

  1. Run /init, then trim CLAUDE.md to the lines that prevent real mistakes.
  2. Pick one recurring task and attach a test command to it.
  3. Start the next feature in plan mode.
  4. Use /clear when you switch topics.

Questions and answers about Claude Code

What is the single most important Claude Code tip?

Treat context as the key resource. Keep sessions focused and give Claude a way to verify results.

How long should CLAUDE.md be?

Anthropic’s memory page says to target under 200 lines per file.

When should I use /clear?

Between unrelated tasks, and after two failed corrections on the same problem.

How do I give Claude a check to run?

Name the tests in your prompt, set a /goal condition, add a Stop hook, or use a verification subagent. Anything with a clear pass or fail works.

How do I undo a bad change?

Press Esc twice or run /rewind.

Can I skip plan mode?

Yes, when you could describe the diff in one sentence.

Sources

Facts last checked on 19 October 2026; the auto mode and compaction notes were re-checked on 29 October 2026. Not benchmarked by us. Commands change between versions.

All sections All articles

Latest articles