CLAUDE.md
The CLAUDE.md File, Explained
Claude Code's standing instructions, written in Markdown. Where each file goes, the order they load in, a copy-ready example, and the few pieces of Markdown that mean something different inside this file.
Short answer
Put a CLAUDE.md at your repo root (run /init to generate one) and list, in plain Markdown, what Claude can't work out from the code: the build and test commands, your conventions, and the gotchas. Keep it under 200 lines. Claude Code reads it at the start of every session, together with your personal ~/.claude/CLAUDE.md. It is guidance, not enforcement: rules that must never break belong in a hook.
What a CLAUDE.md File Is
Every Claude Code session starts with an empty context window. A CLAUDE.md is the Markdown file Claude Code loads into that window first, so the things you would otherwise re-explain each session are already there: how to build and test, how the code is organised, and what your team does differently from the defaults.
There is no schema and no required section. It is ordinary headings, bullet lists and inline code, and Anthropic's guidance is to use exactly that: group related instructions under headings, one instruction per bullet, rather than dense paragraphs.
permissions.deny setting.A CLAUDE.md Example
A realistic project file. Each line is something Claude could not reliably infer by reading the repo. The HTML comment is a note for humans: Claude Code strips it before Claude sees the file.
# Acme Web
<!-- Owners: platform team. Keep under 200 lines; move
area-specific rules to .claude/rules/. -->
See @README.md for the project overview and
@package.json for scripts.
## Commands
- `pnpm dev` starts the app on :3000
- `pnpm test` runs Vitest; run it before every commit
- `pnpm lint` must pass clean, no eslint-disable
## Conventions
- TypeScript, 2-space indent, no default exports
- API handlers live in `src/api/handlers/`
- Use the `Result` type in `src/lib/result.ts`, never throw
## Gotchas
- Integration tests need Redis: `docker compose up redis`
- Never edit `src/generated/`; run `pnpm codegen`Concrete
“Run pnpm test before every commit” can be checked. “Test your changes” cannot, and gets followed less.
Short
Anthropic's target is under 200 lines per file. Longer files use more context and lower adherence.
Consistent
If two instructions contradict each other, Claude may pick either. Review nested files and rules for conflicts.
Where the CLAUDE.md File Goes
There are four locations, from broadest to most specific. Claude Code loads all that exist; none replaces another.
| Scope | Path | Shared with | Use it for |
|---|---|---|---|
| Managed policy | macOS: /Library/Application Support/ClaudeCode/CLAUDE.md Linux/WSL: /etc/claude-code/CLAUDE.md Windows: C:\Program Files\ClaudeCode\CLAUDE.md | Everyone on the machine | Deployed by IT. Cannot be excluded by user settings. |
| User | ~/.claude/CLAUDE.md | Only you, every project | Personal style and tooling preferences. |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Your team, via git | Build commands, conventions, architecture. |
| Local | ./CLAUDE.local.md | Only you, this project | Add it to .gitignore. Sandbox URLs, test data. |
Working across several git worktrees? A gitignored CLAUDE.local.md only exists in the worktree you created it in. Keep the personal file in your home directory and import it instead: @~/.claude/my-project.md.
The Order CLAUDE.md Files Load In
Claude Code walks from the filesystem root down to the folder you launched in and concatenates every CLAUDE.md and CLAUDE.local.md it finds. Nothing overrides anything; the closest file is simply read last.
1. Managed policy CLAUDE.md ← org-wide, always first
2. ~/.claude/CLAUDE.md ← you, every project
3. ~/code/acme/CLAUDE.md ← repo root
4. ~/code/acme/CLAUDE.local.md ← you, this repo
5. ~/code/acme/apps/web/CLAUDE.md ← read last at launch
Later, on demand:
~/code/acme/apps/web/src/payments/CLAUDE.md
← loads the first time Claude reads or edits
a file in src/payments/Subfolders load lazily
A CLAUDE.md below your working directory is not listed in /context at launch. It loads when Claude first touches a file in that folder, and the terminal prints a Loaded line.
Survives /compact
After compaction Claude Code re-reads the project-root CLAUDE.md from disk. Nested files and path-scoped rules come back the next time a matching file is touched.
In a monorepo where other teams' files get picked up, skip them with claudeMdExcludes, a list of globs matched against absolute paths, ideally in .claude/settings.local.json. The managed policy file can't be excluded.
Markdown That Behaves Differently in CLAUDE.md
CLAUDE.md is ordinary Markdown with a few additions. These are the pieces that do something in Claude Code that they would not do in a README.
| You write | In a normal .md file | In CLAUDE.md |
|---|---|---|
| @path/to/file.md | Plain text (or a mention on GitHub) | Imports that file into context at launch. Relative to the CLAUDE.md, up to four hops deep. |
| `@README` | Inline code | Stays literal. Imports are skipped inside code spans and fenced code blocks. |
| @Design\ Docs/api.md | A backslash-escaped space | Imports a path containing a space. Without the backslash the path ends at the space; a quoted path is not imported at all. |
| <!-- note --> | Hidden in rendered output, still in the file | Block-level comments are stripped before Claude sees the file, so they cost no tokens. Comments inside code blocks are kept. |
| --- paths: ... --- | Front matter (often rendered as a table) | Only read in .claude/rules/ files, and only the paths field. It is removed before the rule is loaded. |
@imports
An @path anywhere in the text pulls that file into context at launch, alongside the CLAUDE.md that names it. Paths are relative to the importing file, not your working directory. Absolute and ~ paths work, and imported files can import others, up to four hops.
See @README.md for the overview and @package.json for scripts.
## More instructions
- Git workflow: @docs/git-instructions.md
- API style: @Design\ Docs/api-conventions.md
To mention a file without loading it, use backticks: `@docs/old.md`Two things to know. Imports organise a long file but don't shrink it, because everything imported still loads at launch. And an import that resolves outside the project shows a one-time approval dialog; decline it and those imports stay off for that project.
HTML comments are free
A block-level Markdown comment (<!-- ... --> on its own lines) is stripped before the file is injected, so you can leave notes for the humans who maintain the file without spending a single token on them. A comment inside a code block is kept. If Claude opens the file with its Read tool, it sees the comments.
Splitting It Up With .claude/rules/
For larger projects, put one topic per Markdown file in .claude/rules/ (subfolders are fine). A rule with no front matter loads at launch like .claude/CLAUDE.md. Add a paths field and it only loads when Claude reads, writes or edits a matching file, which is how you shrink the context cost.
---
paths:
- "src/api/**/*.ts"
- "tests/api/**/*.test.ts"
---
# API rules
- Validate every request body with zod
- Return errors in the shape from src/api/errors.tspaths is the only field Claude Code reads; any other key is ignored. Globs support ** and brace expansion like src/**/*.{ts,tsx}. If the YAML doesn't parse, the rule loads as if it had no paths. Personal rules for every project go in ~/.claude/rules/ and load before the project's.
CLAUDE.md vs AGENTS.md
AGENTS.md is the cross-tool version of the same idea, read by Codex, Cursor, Copilot and others. Since v2.1.277 Claude Code reads it too, but by default only as a fallback:
| Your repo has | Claude Code reads |
|---|---|
| AGENTS.md, no CLAUDE.md or CLAUDE.local.md | AGENTS.md |
| AGENTS.md and a CLAUDE.md or CLAUDE.local.md | CLAUDE.md files only |
| A CLAUDE.md containing @AGENTS.md | CLAUDE.md, with AGENTS.md pulled in by the import |
If your team uses several agents, keep AGENTS.md as the shared file and make the CLAUDE.md a thin wrapper:
@AGENTS.md
## Claude Code
Use plan mode for changes under src/billing/.Note that adding a personal CLAUDE.local.md to a repo that relies on AGENTS.md stops Claude reading AGENTS.md for you. To read both without an import, set Project instructions to claude-md-and-agents-md in /config.
Commands for Working With CLAUDE.md
| Command | What it does |
|---|---|
| /init | Writes a starter CLAUDE.md from your codebase, or suggests improvements to an existing one. Also folds in .cursorrules, .cursor/rules/ and .github/copilot-instructions.md. |
| /memory | Lists every CLAUDE.md, CLAUDE.local.md and memory location for this project and opens one in your editor, creating it if missing. Also toggles auto memory. |
| /context | Shows which CLAUDE.md and rules files actually loaded, under Memory files. The first thing to check when instructions seem ignored. |
| /doctor prompt-audit | Reports stale, contradictory or missing-file instructions across CLAUDE.md, AGENTS.md, rules and skills, with proposed edits. Needs v2.1.283+. |
Asking Claude to “remember” something saves it to auto memory, a separate, machine-local store under ~/.claude/projects/. To put it in CLAUDE.md where your team will see it, say “add this to CLAUDE.md”. Source for everything on this page: Claude Code memory docs.
Common Mistakes
The patterns that make a CLAUDE.md cost more context and get followed less.
Avoid
A 600-line CLAUDE.md with the architecture, dependency list and directory tree
Do
Under 200 lines of things Claude can't work out from the code
Avoid
Splitting a long file into @imports to make it smaller
Do
Move area-specific rules into .claude/rules/ with a paths field
Avoid
"Format code properly" and "test your changes"
Do
"Use 2-space indentation" and "Run pnpm test before committing"
Avoid
Writing "NEVER push to main" in capitals and hoping
Do
Enforce hard rules with a hook or a permissions.deny setting
Avoid
Writing `@docs/setup.md` in backticks to import it
Do
Write @docs/setup.md as plain text
Frequently Asked Questions
What is a CLAUDE.md file for?
CLAUDE.md is a Markdown file of standing instructions that Claude Code reads at the start of every session: build and test commands, coding conventions, project layout, and the rules you would otherwise repeat in chat. Each session starts with an empty context window, so CLAUDE.md is how a project's knowledge carries over. Anthropic's own advice is to add to it when Claude makes the same mistake twice or a reviewer catches something Claude should have known.
Where does the CLAUDE.md file go?
For a project, at the repo root as ./CLAUDE.md or ./.claude/CLAUDE.md, committed to git. Personal instructions for every project go in ~/.claude/CLAUDE.md. Personal instructions for one project go in ./CLAUDE.local.md, which you should add to .gitignore. Organizations can also deploy a managed file to /Library/Application Support/ClaudeCode/CLAUDE.md on macOS, /etc/claude-code/CLAUDE.md on Linux and WSL, or C:\Program Files\ClaudeCode\CLAUDE.md on Windows.
In what order are CLAUDE.md files loaded?
Broadest first: managed policy, then your user file, then project files. Claude Code walks from the filesystem root down to your working directory and loads every CLAUDE.md and CLAUDE.local.md it finds, so the files closest to where you launched are read last. In each folder, CLAUDE.local.md comes after CLAUDE.md. The files are concatenated, not merged or overridden. CLAUDE.md files in subdirectories below your working directory load later, the first time Claude reads or edits a file in that folder.
Is CLAUDE.md really useful, or still needed?
Yes, for anything Claude cannot work out from the code: which command runs the tests, which directory is generated, which pattern your team prefers. It is less useful for things Claude can read itself, such as the directory tree or dependency list, and Claude Code's /doctor check proposes cutting exactly that. Claude Code also keeps an automatic memory of your corrections now, but that is per-machine and not shared, so team conventions still belong in a committed CLAUDE.md.
What's the difference between AGENTS.md and CLAUDE.md?
AGENTS.md is the cross-tool instructions file that Codex, Cursor, Copilot and others read. CLAUDE.md is Claude Code's own. Since v2.1.277 Claude Code reads AGENTS.md too, but only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in your working directory or above it. If you want one shared file plus Claude-only rules, put @AGENTS.md on the first line of your CLAUDE.md and add the Claude-specific instructions below it.
How long should a CLAUDE.md be?
Anthropic recommends under 200 lines per file. Claude Code warns at startup and in /status when a file is over the recommended length, or when several files add up past a combined limit. It will load a CLAUDE.md of up to 4 MiB and skips anything larger, but adherence drops well before that.
How do I make a CLAUDE.md file?
Run /init inside Claude Code. It reads your codebase and writes a starting CLAUDE.md with the build commands, test instructions and conventions it finds, or suggests improvements if you already have one. Then edit it by hand, or open it from /memory. A plain text editor works just as well: it is an ordinary Markdown file.
Does Claude always follow CLAUDE.md?
No. CLAUDE.md is delivered as a user message after the system prompt, and Claude treats it as context rather than enforced configuration. Vague or contradictory instructions are followed least reliably. Run /context to confirm the file loaded at all, make instructions specific, and move anything that must never be broken into a hook or a permissions setting.
Can CLAUDE.md include other files?
Yes, with @path imports written anywhere in the text, for example See @README.md for an overview. Paths are relative to the file containing the import, absolute paths and ~ work, and imports can nest up to four hops. Imports inside backticks or code blocks are ignored. Imports that point outside the project trigger a one-time approval prompt.