CLAUDE.md best practices I follow, taken from my own file
A good CLAUDE.md is short, kept at the right level, and every rule in it carries its reason. My global one is 159 lines: principles that hold on every project. Each project has its own, between 20 and 97 lines, which points to the files that are the source of truth instead of copying them. And anything that must never happen leaves the file and becomes a hook, because Claude reads this file as context, not as a rule it executes.
The problem: a file that is read, not executed
Claude Code loads CLAUDE.md files at the start of every session. The documentation is clear about their status: they are treated as context, not as enforced configuration. The model weighs each instruction against everything else in front of it.
Two practical consequences. A long file dilutes every rule: the documentation recommends staying under 200 lines per file, because a longer file uses more context and is followed less reliably. And two instructions that contradict each other leave the model to pick one, without telling you.
I have seen it happen: my file forbids any AI mention in commits, and an agent still added one to four commits in a row, because another instruction said the opposite. I tell that story, and the hook that fixed it, in the article on hooks.
The method: three levels, each with its own content
Claude Code reads several instruction files, from the broadest to the most specific. I use three:
- `~/.claude/CLAUDE.md`, loaded in all my projects. It holds only universal principles: how to answer me, the order of work (tests first, checks before calling anything done), the rules for delegation and review, naming, security.
- The project's `CLAUDE.md`, versioned with the code. The stack, the paths, the scripts, the rules specific to the app. Almost all of them name the file that is the source of truth instead of copying it, for example "
DESIGN.mdis the authority for the whole UI". - `~/.claude/rules/`, for a whole topic that applies everywhere. That is where I keep the instructions for the tool that drives my mobile simulators. The documentation confirms that rules in this folder apply to every project on the machine.
My global file ends with a line that sums up the split: universal principles at the root, and in the project the stack, paths, tables, scripts and environment variables.
Another rule in the global file keeps it from aging badly: never write a value that can change there, like a color or a setting, but point to the source file. A color copied into CLAUDE.md always ends up lying.
Every rule carries its reason
An instruction on its own gets argued with. An instruction with its reason gets understood, and the model can apply it to cases I did not foresee. Here is one line of my file, as is:
- **No `Workflow` tool on React Native projects.** Simulator, Metro, and native build state are single, shared, and stateful (...) parallel agents fight over one device and one bundler. Sequential work in the main thread instead.I learned the cost of parallelism the hard way. On one of my apps, four agents launched in parallel each ran the full suite of about 1,000 tests. The machine's load climbed to around 7 and the computer was overheating. Since then my pipeline runs one agent at a time, and the CLAUDE.md spells out where parallelism is still allowed: for reading, never for driving a device. What happens when several sessions share the same repository is told in the article on parallel sessions.
Same logic for review: "no numeric score as an exit gate", because a good average hides a blocker and invites cosmetic edits just to clear the bar. The exit condition is zero blockers.
Some rules remove work instead of adding it. This one, for example: the checks are the verification, no extra pass re-reading your own diff. It avoids paying twice for the same control.
A real example: what changed in my file
The first saved version of my global CLAUDE.md dates from February 2026. It said "Ask before committing". The current version says the opposite: commit without asking once the feature is done and all checks pass. The question was there so I could control the result; the "everything is green" condition now does that control.
In between, the file gained 41 lines, almost all of them new sections: scope (deliver what was asked, no more, no less), corrections (only go back on a mistake if it changes a decision), delegation and review.
The criterion the documentation gives describes this evolution well: add a line when Claude makes the same mistake a second time, or when you type the same clarification you typed in the previous session.
What still costs too much
My global file stays under the 200-line target. But it imports another file with @RTK.md, and the ~/.claude/rules/ folder holds a 198-line rule about driving simulators. In total, close to 390 lines are loaded in every session, including on this Next.js site where no simulator ever runs.
An import does not fix this: the documentation states that an imported file is loaded together with the file that imports it, so its context cost stays the same. The real fix is a rule limited to certain paths, with a paths field in its header, which only loads when Claude reads or edits a matching file. That is the next thing I am changing.
Last limit: this file guarantees nothing. What calls for judgment stays in it, what must never happen becomes a hook.
How to get started
Run /init in your project: Claude analyzes the code and writes a first CLAUDE.md with the build and test commands and the conventions it finds. If one already exists, /init suggests improvements instead of overwriting it. Then keep three habits:
- One line per repeated correction. If you type the same instruction twice in the chat, it goes into the file.
- One reason per rule. Half a sentence is enough: "because agents fight over a single simulator".
- The right level. Your preferences in
~/.claude/CLAUDE.md, the project's facts in the repository'sCLAUDE.md, long procedures in a skill.
If your repository already uses an AGENTS.md for other tools, Claude Code reads it instead when no CLAUDE.md exists. That is the case for this site: it only has an AGENTS.md, generated by Next.js.
Article written with the help of AI, from my daily practice and my projects.
The whole notebook