CLAUDE.md: what to put in it, where it lives, and examples
CLAUDE.md is the instruction file Claude Code reads at the start of every session. Where each copy lives, how they combine, what to write and what to leave out, imports, path-scoped rules, /init, /memory and example files, checked against Anthropic's docs.
Last checked: 2026-11-20, against Anthropic's Claude Code docs: How Claude remembers your project, Best practices, Extend Claude Code and the commands reference. The newest release in the Claude Code changelog that day was 2.1.329, dated November 19, 2026. Version numbers below mark when a behavior started; the example files are ours, not Anthropic's.
What is CLAUDE.md?
CLAUDE.md is a plain markdown file of instructions that Claude Code loads into every session, so you do not have to repeat your build commands and conventions each time. Claude reads it as context, delivered as a user message after the system prompt, not as enforced configuration: it usually follows the file, but nothing guarantees it.
It is one of two memory systems. You write CLAUDE.md; auto memory is a set of notes Claude writes for itself from your corrections and preferences. Both load at the start of every conversation.
Where does CLAUDE.md live?
In four scopes, from broadest to most specific. All of them can be active at once:
| Scope | Location | Shared with |
|---|---|---|
| Managed policy | macOS: /Library/Application Support/ClaudeCode/CLAUDE.md; Linux and WSL: /etc/claude-code/CLAUDE.md; Windows: C:\Program Files\ClaudeCode\CLAUDE.md | Everyone on the machine (set by IT) |
| User | ~/.claude/CLAUDE.md | Only you, all projects |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Your team, through git |
| Local | ./CLAUDE.local.md (add it to .gitignore) | Only you, this project |
Claude Code also reads CLAUDE.md and CLAUDE.local.md from every directory above the one you launch it in. Files in subdirectories below it load on demand, once Claude reads, writes or edits a file in that subdirectory.
Which CLAUDE.md wins when there are several?
None of them: Claude Code concatenates every file it finds instead of letting one override another. Content runs from the filesystem root down to your working directory, so instructions closest to where you launched are read last, and in each directory CLAUDE.local.md comes after CLAUDE.md.
If two files contradict each other, the docs warn that Claude may pick one arbitrarily, so remove conflicts instead of relying on order. In a monorepo, the claudeMdExcludes setting skips other teams' files by path or glob; it cannot skip a managed CLAUDE.md.
What should you put in CLAUDE.md?
Only what Claude cannot work out from the code itself. Anthropic's best-practices page lists four kinds of content:
- How to check work in this repo: the exact test, typecheck and lint commands, and how to run a single test file.
- Places where the code misleads: an old pattern that is everywhere but must not be copied, or a folder that looks unused but is not.
- Decisions that are not in the repo: which error helper the team chose, how deploys work, what needs a migration review.
- Anything you have had to correct twice.
Write each line so it can be checked. The docs contrast "Use 2-space indentation" with "Format code properly", and "Run npm test before committing" with "Test your changes". Group lines under markdown headings and bullets.
What should you leave out of CLAUDE.md?
Leave out anything Claude can read from the repository, and anything that is not needed in every session. Anthropic's best-practices page lists describing your architecture and file layout as old advice, because Claude reads the repo itself, and /doctor proposes cutting directory layouts and architecture overviews from a checked-in CLAUDE.md. Other doc pages still mention project layout as CLAUDE.md content, so treat this as a judgment call.
- Multi-step procedures, such as a release checklist: put them in a skill: Claude sees its name and description each session but reads the full text only when a task calls for it.
- Rules for one part of the codebase: put them in a path-scoped rule (below).
- Rules that can have no exceptions, such as never editing .env: use a hook or a permission deny rule, which Claude Code enforces.
- Personal preferences: put them in CLAUDE.local.md.
- IMPORTANT or ALL CAPS emphasis: the docs say current models follow plain wording, and extra emphasis mostly makes Claude over-apply the rule.
How long should CLAUDE.md be?
Aim for under 200 lines per file. Longer files use more context and, per the docs, reduce how reliably Claude follows them. Claude Code warns at startup and in /status when a file is over the recommended length, or when several files together pass a combined limit.
- A file that loads at launch is read in full up to 4 MiB; a larger file is skipped entirely.
- Files that load on demand (subdirectory CLAUDE.md files and path-scoped rules) are cut at 40,000 characters in a 200K context window, and with 1M context at 200,000 characters on Claude Opus 4.6 and Sonnet 4.6 or 150,000 on later models. This limit applies since v2.1.309.
- Splitting a file with imports does not save context, because imported files load with the file that imports them.
- Block-level HTML comments are stripped before loading, so you can leave notes for people at no context cost.
How do @imports work in CLAUDE.md?
Write @path anywhere in the file and Claude Code loads that file alongside it. Relative paths resolve from the importing file, not your working directory, and imported files can import others up to four hops deep.
Put a backslash before each space in a path; a quoted path is not imported. Paths inside backticks or code blocks stay literal. The first time a project-level file imports one outside your working directory, such as one in your home folder, Claude Code shows an approval dialog; if you decline, those imports stay disabled.
How do .claude/rules and paths frontmatter work?
Every .md file in .claude/rules/, including subfolders, is a rule file. A rule without a paths field loads at launch with the same priority as .claude/CLAUDE.md; a rule with a paths field loads only when Claude reads, writes or edits a matching file.
paths is the only frontmatter field Claude Code reads from a rule. It takes glob patterns, including brace expansion such as src/**/*.{ts,tsx}. If the YAML does not parse, the rule loads as if it had no paths. Personal rules in ~/.claude/rules/ apply to every project and load before project rules.
Does Claude Code read AGENTS.md?
Yes, since v2.1.277, but by default only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in your working directory or above it. Your ~/.claude/CLAUDE.md and .claude/rules/ files do not count for that check and keep loading.
To change it, open /config and set Project instructions to claude-md-and-agents-md (read both), claude-md (CLAUDE.md only) or managed-only (only your organization's managed CLAUDE.md and auto memory at launch). A CLAUDE.md that starts with an @AGENTS.md import also works, including in sessions that cannot read AGENTS.md directly.
What does /init do?
/init writes a starting CLAUDE.md for you: Claude analyzes the codebase and records the build commands, test instructions and conventions it finds. If a CLAUDE.md already exists, it suggests improvements instead of overwriting it.
/init also reads Cursor rules (.cursor/rules/ or .cursorrules) and Copilot instructions (.github/copilot-instructions.md). Set CLAUDE_CODE_NEW_INIT=1 for an interactive version that asks whether to set up CLAUDE.md files, skills and hooks, explores the code with a subagent, asks follow-up questions and shows a proposal before it writes anything. The best-practices page says the remaining work is mostly deleting lines.
What does /memory do?
/memory lists your CLAUDE.md, CLAUDE.local.md and other memory files across user and project scopes and opens the one you pick in your editor, creating it if it does not exist. It also turns auto memory on or off and opens the auto memory folder.
Auto memory lives in ~/.claude/projects/<project>/memory/, shared by all worktrees of a repository and kept on that machine only. The first 200 lines or 25KB of its MEMORY.md index load each session. Saying "remember that the API tests need a local Redis" saves to auto memory; to change CLAUDE.md, say "add this to CLAUDE.md" or edit it through /memory.
CLAUDE.md examples
Our example project CLAUDE.md for a Python web app. Every line is something Claude could not infer from the code:
# Commands
- Install: uv sync
- One test file: uv run pytest tests/test_orders.py
- Lint: uv run ruff check .
# Conventions
- Store money as integer cents, never as floats
- app/legacy_api/ still serves old clients; do not copy its patterns
# Gotchas
- Tests need the local Postgres from docker-compose.ymlOur example path-scoped rule, saved as .claude/rules/tests.md. It loads only when Claude touches Python files under tests/:
---
paths:
- "tests/**/*.py"
---
- Build test data with the factories in tests/factories.py
- Mark tests slower than a second with the pytest slow markerOur example CLAUDE.md for a repo that already keeps its shared instructions in AGENTS.md for other coding tools. Claude reads the imported file first, then the lines below it:
@AGENTS.md
## Claude Code only
- Ask before changing anything in app/payments/Why is Claude ignoring my CLAUDE.md?
First check that it loaded: run /context all and look under Memory files. If the file is missing there, Claude cannot see it; a subdirectory CLAUDE.md does not appear because it loads on demand.
- Make the instruction more specific, and remove instructions in other files that contradict it.
- If something must happen every time, such as before each commit, write it as a hook.
- Since v2.1.283, /doctor prompt-audit reports outdated, broken or contradictory instructions with proposed edits, and changes nothing until you agree.
- After /compact, the project-root CLAUDE.md is re-read from disk. Instructions you only gave in chat may not survive compaction, so add them to the file.
Frequently asked questions
- Should I commit CLAUDE.md to git? Commit the project CLAUDE.md so your team shares it. Keep CLAUDE.local.md out of git.
- Is CLAUDE.md the same as a system prompt? No. It arrives as a user message after the system prompt. For system-prompt-level text in scripts, the docs point to --append-system-prompt.
- Do subagents read CLAUDE.md? Custom subagents load it like the main conversation unless they set omitClaudeMd. The built-in Explore and Plan agents skip it.
- Where do I put a rule Claude must never break? In a hook or a permission deny rule, not in CLAUDE.md.
Related on claudefox
- Claude Code hooks and subagents: a practical guide
- Claude Code not working? Fixes for common errors
- Best Claude Code MCP servers and skills (Nov 2026): 25 picks by job
- How to install Claude Code on Mac, Windows and Linux
- Claude Code version history: all 47 releases since Sep 18, 2026
Source: How Claude remembers your project: CLAUDE.md and auto memory (Claude Code docs), Best practices for Claude Code (Claude Code docs), Extend Claude Code: CLAUDE.md, rules, skills compared (Claude Code docs), Commands reference: /init, /memory, /context (Claude Code docs), Debug your configuration (Claude Code docs), Claude Code changelog