Context Management Best Practices
These are the patterns that make Claude Code's context management tools actually work for you across a project, from the first CLAUDE.md to a long-running, multi-session codebase.
Search across all documentation pages
These are the patterns that make Claude Code's context management tools actually work for you across a project, from the first CLAUDE.md to a long-running, multi-session codebase.
/init rather than a blank file. Let Claude Code draft the structural first pass (stack, folder layout, existing commands) so you're only writing what it couldn't infer.zod to validate all external input" is followable; "write clean code" is not - specificity is what makes a rule actually get obeyed.main") from general conventions so they're impossible to miss.src/repositories/OrderRepository.ts" is easier to apply correctly than the same rule stated in the abstract./init when the project's structure has shifted meaningfully. It updates the file based on current state rather than duplicating it, giving you a fresh structural baseline to review./compact when a task is still active but the conversation has grown long. It preserves the gist while freeing up space, so you can keep momentum on in-progress work./clear when switching to something unrelated. Dragging even a summarized version of a finished or unrelated task forward just adds noise to the next one./compact run earlier in a long session tends to produce a cleaner, more useful summary than one run under pressure./clear as a routine habit between tasks, not just a recovery move. Clearing when you finish a task, the way you'd close a browser tab, keeps sessions focused by default.@mentions, and verbose tool output are the recurring culprits worth noticing before they pile up.Writing CLAUDE.md with concrete, checkable rules rather than vague generalities. Nearly everything else in this list (mentions, resets, nesting) works better once the project's baseline memory is specific and accurate.
No. Nesting earns its keep once a codebase has genuinely distinct areas - a small, single-stack project usually does fine with a well-written root file alone.
Neither is inherently "more often" - they fit different situations. /compact for an in-progress task in a long session, /clear for switching to something unrelated. Building the habit of choosing correctly matters more than favoring one.
Reflexively @mentioning files "just in case" rather than because a task genuinely needs them. It's an easy habit to fall into and a straightforward one to catch once you're aware of it.
If you can't picture Claude Code checking its own output against the rule, it's probably too vague. "Write clean code" fails that test; "use zod to validate all external input" passes it.
For short, one-off sessions, yes - the audit is most valuable on long-running or frequently reused projects where bloat can accumulate quietly over many sessions.
CLAUDE.md is context the agent reads and reasons over, not a technical guardrail. For anything genuinely critical, a CI check or branch protection rule closes the gap that a missed or deprioritized instruction could leave open.
No - repeating them adds redundant context cost on every session in that area. Nested files should assume the root file already applies and add only what's specific to their own scope.
Ask whether every section still changes what Claude Code would actually do differently. If parts are restated ideas, generic advice, or stale references, that's padding worth trimming regardless of overall length.
The core practices (concrete rules, careful mentions, deliberate resets) apply either way. Team projects add more weight to reviewing CLAUDE.md changes and keeping nested files consistent, since more people are relying on the same shared memory.
Whenever a project's structure changes meaningfully, a new team member joins, or a session starts feeling heavier than expected - it's meant as a recurring habit check, not a one-time setup task.
Stack versions: Written against the Claude model lineup current as of ~June 2026 - Claude Fable 5, Claude Opus 4.8, Claude Sonnet 5 (the default), and Claude Haiku 4.5. Model names, pricing, and product features move quickly - verify current specifics at platform.claude.com/docs before relying on them.
Reviewed by Chris St. John·Last updated Jul 16, 2026