CLAUDE.md only helps if Claude actually follows it, and adherence drops as the file grows or goes stale. Treat it like code: add to it on evidence, keep it short, and clean it up regularly.
When to use it
When you start a CLAUDE.md, every time you are about to add a line to one, and every few weeks on a project you work on often.
How to do it
- Add a rule when you have a reason. Good triggers: Claude makes the same mistake a second time; a code review catches something Claude should have known about the codebase; you type the same correction you typed last session; a new teammate would need the same context.
- Write rules you can check. “Run
npm testbefore committing”, not “test your changes”. “API handlers live insrc/api/handlers/”, not “keep files organized”. Group related rules under headings and bullets. - Leave out what Claude can see in the code. Directory trees, dependency lists and architecture overviews cost context and go stale; Claude can read the repo. Keep what the code does not tell it: pitfalls, the reason behind a rule, conventions that differ from the tool defaults.
- Keep each file under about 200 lines. Longer files cost more context and get followed less reliably. Splitting a file into
@imports does not help here, because imported files load at startup too. - Move the rest out. A multi-step procedure becomes a skill, which loads only when needed. Rules for one part of the codebase become a rule in
.claude/rules/with apaths:glob, which loads only when Claude touches matching files. - Audit it regularly. Contradictory rules make Claude pick one arbitrarily, and stale rules point it at files that no longer exist. Run
/doctor prompt-audit: Claude checks your CLAUDE.md, CLAUDE.local.md, AGENTS.md and the rules, skills and other files under.claude/and~/.claude/for outdated wording, references to missing files and contradictions, and proposes edits. Nothing changes until you ask it to apply them. - Keep personal instructions out of the shared repo (see below).
Keeping personal instructions out of the repo
| You want | Put it in |
|---|---|
| Your habits, in every project | ~/.claude/CLAUDE.md or ~/.claude/rules/ |
| Your notes for one project | CLAUDE.local.md in the project root, listed in .gitignore |
| The same notes across several git worktrees of one repo | A file in your home directory, imported with @~/.claude/my-project-instructions.md; a gitignored CLAUDE.local.md exists only in the worktree where you created it |
A personal file in the repo folder without touching the shared .gitignore | List it in .git/info/exclude, git’s per-repository ignore file that is never committed |
Two things to know. The first time a project’s CLAUDE.md imports a file from outside the project (like the home-directory import above), Claude Code asks you to approve it. And .git/info/exclude, like .gitignore, has no effect on files git already tracks.
Example
An audit of a real side project’s instruction files: a 14-line CLAUDE.md that imports a 292-line rules file. /doctor prompt-audit found, among other things:
- hard-coded counts and line numbers that had drifted within weeks (“24 of the 60 handlers” when there were 62;
database.ts:60that had moved to line 68; a directory described as empty that no longer existed); - a rule naming one migration file when the folder held eight;
- a reminder added after one session’s mistake, next to a list that was already correct;
- five skills saved as flat files in
.claude/skills/instead of<name>/SKILL.md, so none of them ever loaded.
Each finding came with a confidence level and a proposed diff, and nothing was applied automatically. The lesson that generalizes: counts, line numbers and single file names rot with every commit. State the rule, and give the command that checks it (for example a grep), instead of the current number.
Common mistakes
- Using CLAUDE.md as documentation. A full project tour is context Claude pays for in every session. Link to docs or let Claude read the code.
- Assuming the running session sees your edit. Changes apply after
/clear,/compactor a restart. - Relying on it for hard limits. CLAUDE.md is guidance. Use hooks or permission rules for things that must never happen.
- Adding
CLAUDE.local.mdto a repo that relies onAGENTS.md. It stops Claude from readingAGENTS.mdunless Project instructions is set toclaude-md-and-agents-md.
Related
- CLAUDE.md: where the files live, how they load, imports, rules and AGENTS.md.
- Auto memory: the notes Claude keeps for itself, next to CLAUDE.md.
- Managing context: keeping the whole session lean, not just CLAUDE.md.
- Verifying agent output: the check commands worth making a standing rule.