A CLAUDE.md file is a markdown file that Claude Code reads at the start of every session. You write down what youâd otherwise repeat every time, like test commands or project conventions. Claude treats it as context and tries to follow it. You put it at your repository root and commit it.
Where is CLAUDE.md? Claude Code file locations and @imports
Thomas Poulain · · Updated
What does a good CLAUDE.md file look like?
Here is an example for a TypeScript API. Each line is an instruction Claude can act on and check.
# Billing API
Project overview: @README.md
## Commands
- All tests: `pnpm test` (starts a local Postgres with Docker)
- One test: `pnpm test -- src/invoices/total.test.ts`
- Lint before every commit: `pnpm lint`
## Conventions
- 2-space indentation, single quotes
- Amounts are integers in cents, never floats
## Gotchas
- Never edit a migration already released in `migrations/`, add a new one
- `src/generated/` is built by `pnpm codegen`, don't edit it by hand
<!-- Owned by the platform team. This comment is not sent to Claude. -->
Block-level HTML comments, like the last line, are stripped before the content reaches Claude. They work as notes for your team and cost no context.
The docs recommend instructions concrete enough to verify. âUse 2-space indentationâ works better than âformat code properlyâ. Group them under headings and bullets. Aim for fewer than 200 lines per file, since longer files are followed less reliably.
Where do you put CLAUDE.md?
Claude Code looks for instruction files at four levels. The table follows load order, from broadest to most specific.
| Level | Location | Who itâs for |
|---|---|---|
| Organization | macOS: /Library/Application Support/ClaudeCode/CLAUDE.md. Linux and WSL: /etc/claude-code/CLAUDE.md. Windows: C:\Program Files\ClaudeCode\CLAUDE.md | Every user on the machine |
| User | ~/.claude/CLAUDE.md | You, across all your projects |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Your team, through git |
| Local | ./CLAUDE.local.md | Only you, on this project. Add it to .gitignore |
In what order does Claude Code load the files?
Files donât override each other. Claude Code concatenates them into context. It reads every CLAUDE.md and CLAUDE.local.md in your working directory and in each parent directory. The top-most one comes first. Within a directory, CLAUDE.local.md comes after CLAUDE.md.
A CLAUDE.md in a subdirectory loads later, once Claude reads, writes or edits a file in that subdirectory. Here is what loads when you start Claude Code in api/.
~/code/shop/CLAUDE.md # at launch
~/code/shop/api/CLAUDE.md # at launch
~/code/shop/api/CLAUDE.local.md # at launch, after api/CLAUDE.md
~/code/shop/api/src/db/CLAUDE.md # when Claude touches a file in src/db/
Since nothing overrides anything, two conflicting instructions both stay in context. Claude may then follow either one.
In a large repository shared by several teams, claudeMdExcludes skips other teamsâ files. Patterns are globs matched against absolute paths. Put the key in .claude/settings.local.json so it stays on your machine. The organizationâs CLAUDE.md canât be excluded.
{
"claudeMdExcludes": ["**/shop/CLAUDE.md"]
}
How do you import other files with @?
An @path/to/file mention in CLAUDE.md pulls that file into context. A relative path resolves from the file that contains the import, not from your working directory. Imported files can import others, up to four hops deep.
API conventions: @docs/api-conventions.md
Path with a space: @Design\ Docs/style-guide.md
Plain mention, not imported: `@README.md`
A space in a path needs a backslash before it. A path in quotes isnât imported at all. Inside backticks, the mention stays plain text.
When a project CLAUDE.md imports a file outside your working directory, Claude Code asks for approval. If you decline, those imports stay off and the dialog doesnât come back.
Imports help you organize a long file. They donât shrink its context cost, because an imported file loads together with the CLAUDE.md that imports it.
How do you check that your CLAUDE.md loaded?
Run /context all and look at the Memory files list. If a file is missing there, Claude canât see it. Subdirectory CLAUDE.md files arenât listed, since they load later. When one loads, a Loaded line with its path shows up.
/memory also lists your instruction files and opens the one you pick in your editor.
When a permission rule blocks a file from being read, Claude Code says so in the conversation.
Instruction file not loaded (a Read deny rule covers it):
path: .claude/rules/shared.md
The text in parentheses gives the reason. Here, remove or narrow the Read deny rule, then start a new session.
To test whether your setup causes a problem, claude --safe-mode starts without CLAUDE.md, skills, plugins, hooks or MCP servers.
Why isnât Claude following my CLAUDE.md?
CLAUDE.md is delivered as a user message after the system prompt. Claude tries to follow it, with no guarantee of strict compliance. The docs list these common causes.
- Vague or conflicting instruction. Make it more specific, then look for an opposite instruction in your other files.
- Commit instructions. Claude Code adds its own git guidance. Turn it off with the
includeGitInstructionssetting. - Something that must happen at a fixed point, such as before every commit. Write a hook instead, since it runs every time.
- File too long. Over the recommended length, you get a warning at startup and in
/status. A file over 4 MiB is skipped. - End of a subdirectory CLAUDE.md ignored. Over a per-file size limit, Claude only gets the start of it. With a 200K-token context window, that limit is 40,000 characters.
After /compact, Claude re-reads the project-root CLAUDE.md from disk. An instruction you only gave in the conversation can be lost. Add it to CLAUDE.md to keep it.
Watch the word ârememberâ too. If you say âremember that the tests need Redisâ, Claude saves it to auto memory. To target the file, ask âadd this to CLAUDE.mdâ. The # shortcut that older tutorials mention was removed in v2.0.70.
What belongs in CLAUDE.md, and what goes elsewhere?
The docs give a rule of thumb. Add a line when Claude makes the same mistake twice, or when you type the same correction as last session.
Keep in CLAUDE.md what matters in every session. A multi-step procedure belongs in a skill. An instruction for one part of the codebase goes in .claude/rules/. A paths field at the top of that file limits loading to matching files.
The /doctor checkup also proposes trims for a checked-in CLAUDE.md. It targets what Claude can work out from the code, such as directory layouts or dependency lists. To catch outdated or conflicting instructions, run /doctor prompt-audit, covered in the post on prompt audit.
How do you create a CLAUDE.md with /init?
/init analyzes your codebase and drafts a CLAUDE.md with the commands and conventions it finds. If the file already exists, it suggests improvements instead of overwriting it. It also pulls in Cursor rules (.cursorrules, .cursor/rules/) and Copilot instructions (.github/copilot-instructions.md).
For a guided flow, set the CLAUDE_CODE_NEW_INIT variable before you run /init.
CLAUDE_CODE_NEW_INIT=1 claude
/init then asks which of CLAUDE.md, skills and hooks to set up. It explores the code with a subagent, asks follow-up questions, and shows a proposal before it writes anything.
Does your repository already have an AGENTS.md? Since v2.1.277, Claude Code reads it when the project has no CLAUDE.md. The Project instructions row in /config changes that, as the post on AGENTS.md explains.
What changed in recent versions?
This reference is current as of Claude Code v2.1.330.
- v2.1.283:
/doctor prompt-auditarrived, to audit your CLAUDE.md files, skills, agents and commands. - v2.1.288: subdirectory CLAUDE.md files also load when Claude creates or edits a file in their folder. Before, only reads loaded them.
- v2.1.293: same when Claude views a single file with
cat,head,tail,sed -norgrep. - v2.1.309: an oversized subdirectory CLAUDE.md now loads only its start.
- v2.1.330: link reference definitions are no longer dropped from a CLAUDE.md that contains an HTML comment.
The official memory docs cover every case. Module 2 of the course walks through the four CLAUDE.md levels and rules files.