Best practices for Claude Code
by Anthropic
Anthropic's own working patterns for agentic coding, organised around the one constraint that matters: the context window.
Overview
The guide opens by naming its organising constraint: Claude's context window holds the entire conversation, every file read and every command output, and model performance degrades as it fills. Everything after follows from that. "Give Claude a way to verify its work" argues that without a check it can run — a test suite, a build exit code, a linter, a screenshot diff — you become the verification loop, and it escalates through four enforcement levels: asking in the prompt, a /goal condition re-evaluated each turn, a Stop hook that deterministically blocks the turn from ending, and a fresh-context reviewer subagent. "Explore first, then plan, then code" documents the four-phase plan-mode workflow, with an explicit note on when planning is overhead you should skip. "Provide specific context in your prompts" gives before/after prompt rewrites for scoping tasks, pointing at sources, referencing existing patterns and describing symptoms. "Configure your environment" covers writing a CLAUDE.md that stays short enough to be obeyed (with an include/exclude table and the warning that a bloated file gets ignored), permission modes and sandboxing, CLI tools like gh, MCP servers, hooks, SKILL.md files, custom subagents in .claude/agents/ and plugins. "Communicate effectively" covers codebase questions and having Claude interview you via AskUserQuestion to produce a SPEC.md before implementation. "Manage your session" covers course-correcting with Esc, /clear between unrelated tasks, /compact, checkpoints and /rewind, and resuming named sessions. "Automate and scale" covers claude -p with JSON output, parallel sessions in git worktrees, a Writer/Reviewer pattern, fanning out across files with --allowedTools, auto mode and an adversarial review step. It closes with five named failure patterns and a section arguing you should develop your own intuition rather than follow the guide literally.
At a Glance
- Topic
- Agentic
- Level
- All Levels
- Format
- Guide
- Cost
- Free
- Duration
- ~45-60 min read; about a week of practice to internalise
- Provider
- Anthropic
- Hands-on
- Yes — code/exercises
- Certificate
- None
What You’ll Learn
- ✓Give an agent a verification signal so it can close its own iteration loop
- ✓Escalate enforcement from prompt to /goal condition to Stop hook to reviewer subagent
- ✓Run the explore, plan, implement, commit workflow using plan mode deliberately
- ✓Write a CLAUDE.md short enough that Claude actually follows every line
- ✓Manage context with /clear, /compact, checkpoints and targeted rewinds
- ✓Delegate research to subagents so exploration never pollutes your main context
- ✓Run non-interactive sessions with claude -p and scoped --allowedTools in CI
- ✓Parallelise work across git worktrees using a Writer and Reviewer split
- ✓Recognise five named failure patterns before they waste an entire session
Highlights
- •Derived from patterns used across Anthropic's own engineering teams, not speculation about the tool
- •Every recommendation traces back to one stated constraint, so the advice is coherent rather than a tip list
- •Explicitly names when NOT to use each technique — planning has overhead, vague prompts are sometimes right
- •Warns that a gap-hunting reviewer will always report gaps, and that chasing them causes over-engineering
- •Continuously revised as part of the product docs; an earlier revision drew 614 points and 257 comments on Hacker News
Who It’s For
Best For
- ✓Developers who already use Claude Code and keep hitting context limits
- ✓Teams standardising on agentic coding and writing shared CLAUDE.md conventions
- ✓Engineers automating code changes in CI or across large migrations
Prerequisites
- •Claude Code installed and used for at least a few real tasks
- •Comfort with a terminal, git and your project's test or build commands
FAQ
What is Best practices for Claude Code?
Anthropic's official guide to working effectively with Claude Code, drawn from patterns used across its internal engineering teams. Nearly every recommendation derives from one constraint — the context window fills fast and quality degrades as it does — and the guide turns that into concrete habits for verification, planning, configuration, session management and running many agents in parallel.
Is Best practices for Claude Code free?
Best practices for Claude Code is free to access.
What level is Best practices for Claude Code for?
Best practices for Claude Code is aimed at a all levels audience. Recommended background: Claude Code installed and used for at least a few real tasks, Comfort with a terminal, git and your project's test or build commands.
How long does Best practices for Claude Code take?
Expect roughly ~45-60 min read; about a week of practice to internalise. Most learners work through it at their own pace.
What will I learn from Best practices for Claude Code?
You'll learn: Give an agent a verification signal so it can close its own iteration loop; Escalate enforcement from prompt to /goal condition to Stop hook to reviewer subagent; Run the explore, plan, implement, commit workflow using plan mode deliberately; Write a CLAUDE.md short enough that Claude actually follows every line; Manage context with /clear, /compact, checkpoints and targeted rewinds; Delegate research to subagents so exploration never pollutes your main context; Run non-interactive sessions with claude -p and scoped --allowedTools in CI; Parallelise work across git worktrees using a Writer and Reviewer split; Recognise five named failure patterns before they waste an entire session.
Topics
Sources
This page was written from 3 sources, 2 on domains other than code.claude.com.