CLAUDE.md best practices: what to put in, what to leave out
Keep CLAUDE.md short: commands Claude can't guess, rules that differ from defaults, pointers to docs. What to cut, and where must-hold rules go.
Contents
CLAUDE.md best practices come down to one test from Anthropic: keep a line only if Claude would get something wrong without it. That leaves the commands it can't guess, rules that differ from the defaults and your project's gotchas, in under about 200 lines, because the file loads into every session. Docs get a pointer, not a copy, and rules that must always hold go in hooks or permissions.
The one test: would Claude get this wrong without it?#
Anthropic's best practices give a single question for every line: "Would removing this cause Claude to make mistakes?" If not, cut it. The same page warns: "Bloated CLAUDE.md files cause Claude to ignore your actual instructions!"
Their include and exclude lists, in short:
| Put in | Leave out |
|---|---|
| Commands Claude can't guess (build, test, lint) | Anything Claude can work out by reading the code |
| Style rules that differ from the defaults | Standard conventions Claude already knows |
| How to run tests, which runner you prefer | Detailed API docs (link to them instead) |
| Branch naming, PR conventions | Things that change often |
| Architecture decisions specific to your project | Long explanations and tutorials |
| Environment quirks, required env vars | File-by-file tours of the codebase |
| Gotchas that aren't obvious | "Write clean code" and similar |
How long should CLAUDE.md be?#
Under 200 lines per file. Anthropic's memory docs give the reason: "Longer files consume more context and reduce adherence."
Both halves matter. Context: CLAUDE.md is part of what Claude Code sends with every request, so every line rides along on every turn of every session. Our guide on why Claude Code uses so many tokens shows how that adds up. On a subscription, /usage will even flag it, with rows like Trim ~/code/api/CLAUDE.md · 49k tokens per request. Adherence: the more rules there are, the more each one gets lost. If Claude keeps breaking a rule that's in the file, Anthropic's guess is that "the file is probably too long and the rule is getting lost."
@imports don't change the context cost. An imported file loads at launch along with the file that imports it, so @docs/conventions.md costs the same as pasting that file in.
Write commands as commands#
"Run the tests" leaves Claude to pick between npm test, npx vitest run and npx jest. The command itself, in a code block, leaves nothing to pick. Four lines from the Quick start block in our own root file:
npm run typecheck # Always run after changes
npm run lint # Always run after changes
npm run format # Auto-format with Biome
npm run format:check # Check formatting without writing
Its test rule names the command too: npx vitest run <file> --bail=1, and never npm run test for a whole workspace.
Rules need the same precision. Anthropic's example is "API handlers live in src/api/handlers/" in place of "Keep files organized". If one rule keeps getting skipped, mark that one line IMPORTANT; mark many lines and none of them stands out. Our file has no IMPORTANT, but five of the 12 rules in its Critical rules section open with a bold NEVER, which is the many-lines case.
Pointers, not copies#
Detail that lives somewhere else gets one line in the root file and stays where it is.
- A doc. "Architecture:
docs/architecture.md" is one line; pasting the architecture doc is a hundred, and it goes stale in two places. .claude/rules/api.mdwith apaths:list ("src/api/**/*.ts") holds rules for one area, and they load only when Claude touches a matching file.- A
CLAUDE.mdinpackages/server/loads when Claude works in that folder, not at startup. - A skill takes a workflow you need now and then, a release checklist or a migration recipe. Anthropic's cost guide says skills "load on-demand only when invoked."
One catch: path-scoped rules and subfolder files are summarised away by /compact and come back only when Claude touches a matching file again. A rule that must survive a compact goes in the root file. More on that in /compact vs /clear.
Rules that must hold go in hooks and permissions#
In the memory docs' words, Claude treats CLAUDE.md "as context, not enforced configuration." "Never edit migrations" in the file is a strong hint, not a lock. Anything that must happen every time, or must never happen, needs something that runs.
- A
PreToolUsehook can block a command or an edit before it runs, whatever Claude decided. - A permission deny rule in
.claude/settings.jsonstops a tool or a path outright. - A hook on edits or on
Stopruns the formatter or the tests every time, instead of asking nicely. - A test in your suite turns a team rule into a red build. Our repo does this for one naming rule: a line in CLAUDE.md explains it, and a test script under
scripts/refuses any change that breaks it.
Where CLAUDE.md files live#
From the memory docs:
| File | Scope | Shared? |
|---|---|---|
~/.claude/CLAUDE.md |
You, in every project | No |
./CLAUDE.md or ./.claude/CLAUDE.md |
The project | Yes, commit it |
./CLAUDE.local.md |
You, in this project | No, add it to .gitignore |
CLAUDE.md in a subfolder |
That folder, loaded on demand | Yes |
| Managed policy file | Everyone in an organisation | Set by IT |
Files above your working directory load at launch and are joined, not overridden; the one closest to where you started is read last.
If you also use Codex, it reads AGENTS.md (Codex docs). Since v2.1.277, Claude Code reads AGENTS.md too, but only when there's no CLAUDE.md. The simplest way to keep one source of truth: make one file a link to the other, or import @AGENTS.md from your CLAUDE.md.
The Shuriken app sets up that import for you. When you add a project, it offers to make AGENTS.md the one instruction file. With a single CLAUDE.md, it moves the content to AGENTS.md and leaves CLAUDE.md with the line @AGENTS.md. If the project already has several instruction files, one call on a helper model merges them; the app shows that call's cost first, and you review the merged file before anything is written. The originals are copied to a backup folder.
Our own file, as it is today#
We write this as people who haven't got it right either. As of 22 October 2026, the root CLAUDE.md in the Shuriken repo is 287 lines, well over Anthropic's target. Two commits on 23 October took it to 298: a nine-line section on moderating blog comments, and two more rows in the docs table. Its sections at 298 lines:
| Section | Lines | What's in it |
|---|---|---|
| Read this first | 51 | What the product is in one paragraph, where the plan and the request register live, and the working rules for agents that share the tree (touch only your own paths, kill processes by exact id, never the full test suite) |
| Bug reports | 16 | How to triage user reports before a build |
| Blog comments | 13 | Moderating the blog's comment queue |
| A second title and the old intro | 6 | See below |
| Repository map | 10 | One line per package |
| Docs | 97 | A table pointing to the docs folder, one row per doc (64 rows), and how to write docs |
| Quick start | 18 | The dev, typecheck, lint and format commands in a code block |
| Release branches | 7 | Which branch a pull request targets |
| Critical rules | 29 | The "never" list, such as never restarting the main background service without permission and never running the full test suite locally |
| Platform gating and debugging | 51 | Which check to use for desktop, web or phone-only code, and where the logs are |
AGENTS.md is a link to CLAUDE.md, so Codex reads the same file. The server package has its own 196-line CLAUDE.md that loads only when Claude works there.
While checking it for this guide, we found a second top-level title a quarter of the way down, over an old intro that still calls Shuriken a mobile app and lists five supported agents (it supports 67). That's Anthropic's "information that changes frequently" failure, in our own repo. What we'd cut first: the stale intro, the docs table (one pointer to the docs index does the job) and any rule a test already enforces.
Keep it fresh#
/initwrites a starter CLAUDE.md from your project. Treat it as a draft./memoryopens your CLAUDE.md files and auto memory for editing./doctor prompt-audit(Claude Code v2.1.283 or later) looks for outdated instructions, references to files that don't exist and rules that contradict each other, and proposes edits without changing anything.- Auto memory is the notes Claude keeps itself. Only its first 200 lines or 25KB load, so it needs pruning too.
Treat CLAUDE.md like code, as Anthropic puts it: "review it when things go wrong, prune it regularly." The same habit makes sense in any agent harness you run Claude Code in, because every agent reads the file on every start.
Sources
- Best practices for Claude Code: write an effective CLAUDE.md (Claude Code docs) (accessed 22 October 2026)
- How Claude remembers your project: CLAUDE.md files (Claude Code docs) (accessed 22 October 2026)
- Manage costs effectively: move instructions from CLAUDE.md to skills (Claude Code docs) (accessed 22 October 2026)
- AGENTS.md (Codex docs) (accessed 22 October 2026)
Frequently asked questions
How long should a CLAUDE.md file be?
Anthropic's target is under 200 lines per file. It loads into every session, and longer files use more context and are followed less consistently. Move rules for one part of the code into path-scoped rules.
Should I commit CLAUDE.md to git?
Yes, Anthropic recommends checking it in so the team shares it. Personal preferences for one project go in CLAUDE.local.md, which you add to .gitignore.
What is the difference between CLAUDE.md and AGENTS.md?
Claude Code reads CLAUDE.md; Codex and other agents read AGENTS.md. Since v2.1.277 Claude Code also reads AGENTS.md when no CLAUDE.md exists. To keep one file, import AGENTS.md from CLAUDE.md or make one a link to the other.
Does Claude always follow CLAUDE.md?
No. Anthropic calls it context, not enforced configuration. For anything that must happen every time, or must never happen, use a hook or a permission rule.
Does an edit to CLAUDE.md apply to the running session?
No. The root and user files are read once at session start. The edit loads on the next /clear, /compact or restart.