What you will be able to do
- Decide what belongs in a CLAUDE.md and what to leave out
- Place guidance at the right scope: managed, user, project, local, subdirectory or path-scoped rule
- Keep CLAUDE.md accurate as the code, conventions and models change
1.What CLAUDE.md should contain
CLAUDE.md is the implementation guidance Claude Code reads for itself. It is a plain markdown file that Claude reads automatically at the start of every session in that directory. You never attach it or mention it in a prompt. Think of it as the briefing you would give a capable new teammate on their first morning: how the team works, what to avoid, and where the important pieces live.
The test for every line is whether Claude could work it out from the code alone. Bash commands it can't guess, style rules that differ from the defaults, and architectural decisions specific to the project all earn a place. File-by-file descriptions and standard conventions do not. Instructions should also be concrete enough to check. "Use 2-space indentation" can be followed, and "Format code properly" cannot.
| Include | Leave out |
|---|---|
| Bash commands Claude can't guess | Anything Claude can figure out by reading code |
| Code style rules that differ from defaults | Standard language conventions Claude already knows |
| Testing instructions and preferred test runners | Detailed API documentation (link to docs instead) |
| Architectural decisions specific to your project | Information that changes frequently |
| Developer environment quirks (required env vars) | File-by-file descriptions of the codebase |
| Common gotchas or behaviors that aren't self-evident | Self-evident practices like "write clean code" |
# Code style
- Use ES modules (import/export) syntax, not CommonJS (require)
- Destructure imports when possible (eg. import { foo } from 'bar')
# Workflow
- Be sure to typecheck when you're done making a series of code changes
- Prefer running single tests, and not the whole test suite, for performanceTwo more items are easy to get wrong. Hard constraints, such as never writing to the production database from tests, belong in the file. Aspirational rules the team does not actually follow do not, because Claude will follow them even though the team doesn't.
Checkpoint 1 of 3· Check yourself
A team is drafting the project CLAUDE.md for a new repository. Which of these candidate lines belongs in the file?
Ask of each line whether Claude could work it out from the code alone. Claude can't infer a required setup step like the .env copy, so that line belongs in the file. The others are a self-evident practice, a file-by-file description and a standard language convention, and the lesson says to leave all three out.
“Developer environment quirks (required env vars)”Source: code.claude.com
2.Choosing the scope for each instruction
CLAUDE.md files exist at several scopes, and Claude merges them from broad to specific. Put each instruction at the narrowest scope that still reaches everyone who needs it. Team conventions go in the project file, committed to source control. Personal habits go in the user file, and sandbox URLs go in CLAUDE.local.md.
| Scope | Location | Use for | Shared with |
|---|---|---|---|
| Managed policy | /etc/claude-code/CLAUDE.md (Linux and WSL) | Company coding standards, security policies, compliance requirements | All users in organization |
| User instructions | ~/.claude/CLAUDE.md | Code styling preferences, personal tooling shortcuts | Only you (all projects) |
| Project instructions | ./CLAUDE.md or ./.claude/CLAUDE.md | Project architecture, coding standards, common workflows | Team members via source control |
| Local instructions | ./CLAUDE.local.md | Your sandbox URLs, preferred test data | Only you (current project) |
Timing matters as much as location. Files at and above the working directory load when the session starts. A subdirectory's CLAUDE.md loads only later, when Claude reads files in that subdirectory. In a monorepo, that makes the root file the place for rules that apply everywhere, such as commit conventions, and each package's own file the place for its stack.
Conventions for one area can live in two places. A per-directory CLAUDE.md sits next to the code, so its owners maintain it and it is versioned with that code. A path-scoped rule lives in .claude/rules/ at the root, with a paths: glob, and loads only when Claude works with a matching file. It is the better choice when you want every convention in one place, or when one rule covers many scattered paths. To keep another team's files out of a session, use claudeMdExcludes.
{
"claudeMdExcludes": [
"**/packages/web/**"
]
}A CLAUDE.md can also import other files. Writing @ followed by a path, as in - git workflow @docs/git-instructions.md, makes Claude load that file at launch along with the main one. Imports are a way to split a long file into pieces, which raises the question of whether the pieces cost less.
Checkpoint 2 of 3· Match them up
An architect is deciding where each of these instructions should live. Match each CLAUDE.md location to the instruction that belongs there.
Tap a term, then the definition that fits it.
Put each instruction at the narrowest scope that still reaches everyone who needs it. Organization-wide policy goes in the managed file and team conventions go in the committed project file. Personal habits that apply to every project go in the user file, and personal details for one project go in CLAUDE.local.md.
“Personal project-specific preferences; add to .gitignore | Your sandbox URLs, preferred test data | Only you (current project)”Source: code.claude.com
3.Keeping CLAUDE.md accurate
A stale CLAUDE.md does more harm than having none, because Claude follows it with confidence. Running /init gives you a first draft: Claude explores the codebase and writes up build commands, test commands, a structure overview and the conventions it detects. Someone still has to review that draft, delete anything inaccurate and commit it. Keep the file under about 200 lines. Longer files use more context and Claude follows them less reliably.
Several triggers should prompt an edit:
- Claude gets the same thing wrong twice, which means a rule is missing, so add one line.
- Conventions change, for example a new framework, test runner or set of lint rules.
- A major model release lands, because rules that worked around an older model's limitation may now be overhead.
- A quarterly skim turns up stale lines, which should be deleted.
Contradictions are the quiet failure. When two instructions conflict, Claude may pick either one, so periodically review the root file, nested CLAUDE.md files and .claude/rules/ together. Treat CLAUDE.md edits like any other documentation change and review them in pull requests, so conventions keep up with the code. A Stop hook receives the session transcript path when Claude finishes responding, so a script can propose updates while the gap is still fresh.
An edit made mid-session does not take effect straight away. Claude doesn't re-read the file from disk each turn, so a change is picked up only after /compact, after opening the file through /memory, or in the next session.
Checkpoint 3 of 3· Check yourself
Partway through a Claude Code session, a developer adds the line "Never edit a migration after it has merged" to the project CLAUDE.md and saves the file. On the next turn, Claude edits a merged migration anyway. What explains this, and what will make the new rule apply?
CLAUDE.md is read when the session starts and is not re-read on each turn, so an edit made mid-session waits until /compact, a /memory open, or a new session. The 200-line guideline is about context cost and adherence, not truncation. Pull-request review keeps conventions current but does not control loading.
“If you edit the file mid-session, the change is picked up the next time you run /compact or open it via /memory”Source: support.claude.com
Practise it for real
Create a reviewed project CLAUDE.md and scope one area's conventions so they load only where needed.
1.In a repository, run /init.
Why: Claude explores the codebase and drafts build commands, test commands, a structure overview and the conventions it detects.
You should see: A draft CLAUDE.md at the project root.
2.Review the draft. Delete anything Claude could infer from the code, any file-by-file descriptions, and anything inaccurate.
Why: Every line costs context, and inaccurate or obvious lines lower adherence.
You should see: A file well under 200 lines, grouped under markdown headers.
3.Move instructions that only apply to one area (for example API handlers) into a file under .claude/rules/ with a paths: glob.
Why: Path-scoped rules load only when Claude works with matching files.
You should see: The root file gets shorter, and the rule applies only when Claude touches files that match the glob.
4.Commit CLAUDE.md and .claude/rules/ so changes go through pull-request review.
Why: Reviewing edits like any other documentation keeps conventions in step with the code.
You should see: Teammates who clone the repository get the same guidance.
Stuck? Get a nudge
If Claude ignores an edit you just made, run /compact or open the file through /memory. Mid-session edits aren't picked up until you do.
Sources
(5)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://support.claude.com/en/articles/14553240-give-claude-context-claude-md-and-better-promptsOfficial docs
“Think of it as the briefing you would give a capable new teammate on their first morning”
↩︎ What CLAUDE.md should contain“Aspirational rules the team does not actually follow.”
↩︎ What CLAUDE.md should contain“Subdirectory CLAUDE.md files are loaded on demand later, when Claude reads files in that subdirectory.”
↩︎ Choosing the scope for each instruction“When Claude gets something wrong twice — that is the signal a rule is missing.”
↩︎ Keeping CLAUDE.md accurate“Quarterly skim — delete anything stale, since outdated instructions are worse than none.”
↩︎ Keeping CLAUDE.md accurate“If you edit the file mid-session, the change is picked up the next time you run /compact or open it via /memory”
↩︎ Keeping CLAUDE.md accurate“Subdirectory CLAUDE.md files are loaded on demand later, when Claude reads files in that subdirectory.”
↩︎ Exam trap 2“If you edit the file mid-session, the change is picked up the next time you run /compact or open it via /memory”
↩︎ Exam trap 3 - 2.https://code.claude.com/docs/en/best-practicesOfficial docs
“Architectural decisions specific to your project”
↩︎ What CLAUDE.md should contain“Developer environment quirks (required env vars)”
↩︎ Checkpoint - 3.https://code.claude.com/docs/en/memoryOfficial docs
““Use 2-space indentation” instead of “Format code properly””
↩︎ What CLAUDE.md should contain“Move instructions that matter for only part of the codebase into path-scoped rules, which load only when Claude works with matching files.”
↩︎ Choosing the scope for each instruction“Longer files consume more context and reduce adherence.”
↩︎ Keeping CLAUDE.md accurate“Consistency: if two instructions contradict each other, Claude may pick one arbitrarily.”
↩︎ Keeping CLAUDE.md accurate“Imports help you organize a long file but don’t reduce its context cost, because imported files also load at launch.”
↩︎ Exam trap 1“Imports help you organize a long file but don’t reduce its context cost, because imported files also load at launch.”
↩︎ Prediction“Personal project-specific preferences; add to .gitignore | Your sandbox URLs, preferred test data | Only you (current project)”
↩︎ Checkpoint - 4.https://code.claude.com/docs/en/large-codebasesOfficial docs
“Directory owners maintain their own conventions; instructions are versioned with the code”
↩︎ Choosing the scope for each instruction“You want all conventions in one place, or the same rule applies to many scattered paths”
↩︎ Choosing the scope for each instruction“instructions that worked around an older model’s limitation may become overhead once a newer model handles the case on its own”
↩︎ Keeping CLAUDE.md accurate“Review in pull requests: treat CLAUDE.md edits like any other documentation change so conventions track the code”
↩︎ Keeping CLAUDE.md accurate“a Stop hook receives the path to the session transcript when Claude finishes responding”
↩︎ Keeping CLAUDE.md accurate - 5.https://code.claude.com/docs/en/changelogOfficial docs
“CLAUDE.md files can now import other files. Add @path/to/file.md to ./CLAUDE.md to load additional files on launch”
↩︎ Choosing the scope for each instruction