Where Claude Code looks for instructions
Every Claude Code session starts with an empty context window. CLAUDE.md files are what carry knowledge from one session to the next: build commands, conventions, where things live, the rules the team has agreed. Claude reads them at the start of a session and treats them as context. That last point matters, and the Claude Code memory docs say it plainly: CLAUDE.md is guidance, not enforced configuration.
Instructions can live at several levels. The docs list them from the broadest scope to the most specific, and load them in that order, so a project's lines come after a user's:
| Level | Location | Who it is for |
|---|---|---|
| Managed policy | /etc/claude-code/CLAUDE.md on Linux and WSL, /Library/Application Support/ClaudeCode/CLAUDE.md on macOS, C:\Program Files\ClaudeCode\CLAUDE.md on Windows | The whole organization, deployed by IT: security and compliance reminders |
| User | ~/.claude/CLAUDE.md | One person, every project: personal preferences |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | The team, committed to git: commands, structure, conventions |
| Local | ./CLAUDE.local.md, listed in .gitignore | One person, one project: a sandbox URL, preferred test data |
| Subdirectory | CLAUDE.md in a folder below where Claude started | One module; loaded when Claude reads or edits a file in that folder |
Files in the directories above the working directory load at launch; files in subdirectories load on demand. They are concatenated rather than overriding one another, so a contradiction between two levels reaches the model as two rules, and the docs warn that Claude may then pick either. Two details are useful for teams: block-level HTML comments in a CLAUDE.md are stripped before it reaches the model, so maintainers can leave notes for each other at no cost in context; and in a large monorepo, the claudeMdExcludes setting skips other teams' files.
CLAUDE.md and AGENTS.md in one repository
Most teams have more than one agent in use, and AGENTS.md is the shared file the others read. Recent Claude Code versions read it too. The docs describe the default this way:
| The repository has | Claude reads |
|---|---|
| AGENTS.md and no CLAUDE.md | AGENTS.md |
| Both AGENTS.md and CLAUDE.md | CLAUDE.md only |
| A CLAUDE.md that imports AGENTS.md | CLAUDE.md, with AGENTS.md included through the import |
The default can be changed in /config under Project instructions, for example to read both files. A personal CLAUDE.local.md counts as a CLAUDE.md for this check, so adding one quietly stops Claude from reading AGENTS.md for that developer, which is one more reason to prefer the import.
The setup that works everywhere is one shared file and one short Claude-specific file next to it:
@AGENTS.md
## Claude Code
- Search the codebase with the Explore subagent; do not read whole folders yourself.
- Run tests with `pnpm test:summary`, which prints only the failures.
- Use plan mode for any change under `src/billing/`.
The @path syntax imports a file: relative paths resolve from the importing file, imports can nest up to four hops, and a path in backticks stays literal text. An import is not a saving, though. The imported file loads in full alongside the CLAUDE.md that names it, every session. For a long document that only some tasks need, write its path as plain text and let Claude open it when the task calls for it.
Path-scoped rules in .claude/rules
Some rules matter only in one corner of the codebase: how money is rounded, how migrations are written, how the design system is used. Loading them into every session wastes context on tasks that never touch that corner. Claude Code's answer is the .claude/rules/ directory: one Markdown file per topic, discovered recursively.
A rule without frontmatter loads at launch like the project CLAUDE.md. A rule with a paths field loads only when Claude reads, writes or edits a matching file:
---
paths:
- "services/subscriptions/**"
- "packages/money/**/*.ts"
---
# Money and renewals
- Amounts are integer cents (`bigint`). Never `number` with decimals.
- Round only once, at the end, with `roundCents()` from `packages/money`.
- Renewal dates are computed in `customer.tz`, then stored in UTC.
- A change here adds a test at a month boundary (28th, 30th, 31st).
The patterns are globs relative to the folder that holds .claude, and brace expansion such as src/**/*.{ts,tsx} works. paths is the only field Claude Code reads from a rule; others are ignored. If the YAML does not parse, the rule loads as if it had no paths, so a broken pattern costs context rather than failing silently in the other direction.
For instructions that are not facts but procedures, such as how to cut a release or write a migration, the docs point to skills instead: a skill loads only when invoked or when Claude judges it relevant, so a long procedure costs nothing on days it is not used.
What to write, and how much
The content is the same as a good AGENTS.md: exact commands with their flags, how to run one test, where each kind of code lives, conventions a linter cannot check, what not to touch, and where deeper knowledge is kept. The docs suggest adding a line when Claude makes the same mistake twice, when a review catches something Claude should have known, or when you type the same correction you typed last session.
Three properties decide whether Claude follows a line:
- Concrete. "Run
pnpm testbefore committing" works; "test your changes" does not. "API handlers live insrc/api/handlers/" works; "keep files organized" does not. - Short. The docs recommend under 200 lines per CLAUDE.md file: longer files cost more context and are followed less reliably. Move module-specific rules into path-scoped rules and procedures into skills.
- Consistent. Two contradicting instructions leave Claude to choose. Review CLAUDE.md, nested files and rules together from time to time; recent versions offer
/doctor prompt-auditto find outdated or conflicting lines.
/init drafts a CLAUDE.md from the repository. Treat the draft as raw material: keep what Claude could not have worked out by reading the code, and cut the rest.
What CLAUDE.md cannot guarantee
A model follows instructions most of the time. For a rule that must hold every time, most of the time is not enough. The docs say so directly: to block an action whatever Claude decides, use a hook; to enforce a rule across an organization, use managed settings such as permissions.deny. Each kind of rule has a better home:
| Rule | Where it belongs |
|---|---|
| Formatting, import order, naming style | Formatter and linter, in a pre-commit hook and in CI |
| Architecture layers ("handlers never query the database") | An architecture test or a lint rule |
| Forbidden commands, folders an agent may not write | Claude Code permissions and a PreToolUse hook |
| "Run the tests before you finish" | A hook at the end of the turn, and CI on the pull request |
| Repeatable procedures: release, migration, review | Skills and commands |
| Judgement a tool cannot check: domain rules, trade-offs, when to ask | CLAUDE.md |
The last row is what CLAUDE.md is for. Everything above it is a rule you can make true without asking. See harness engineering for the environment that makes this practical.
Other tools' rule files
Teams rarely use one agent. The others have their own files:
- GitHub Copilot reads repository-wide instructions from
.github/copilot-instructions.mdand path-specific ones from.github/instructions/NAME.instructions.md, scoped with anapplyToglob in the frontmatter. Its documentation also describes AGENTS.md files anywhere in the repository, with the nearest one taking precedence. - Cursor keeps project rules under
.cursor/rules/and is listed among the agents that read AGENTS.md.
In a mixed team, make AGENTS.md and the knowledge base the source of truth, and keep each tool's own file to what is specific to that tool, pointing back to the shared file rather than copying it. Copies drift, and a rule fixed in one file stays wrong in the other three.
Keeping CLAUDE.md as a team
- It lives in gitThe project CLAUDE.md and
.claude/rules/change through pull requests, reviewed like code. - It has ownersOne or two people review changes and say no to rules added "just in case".
- Rules come from casesEach new line answers a mistake that happened, ideally twice. A line with no story behind it is a guess.
- It is prunedEvery month or so, remove lines a linter or hook now enforces, and lines the code no longer matches.
Questions
Where should CLAUDE.md go?
The team's file at the repository root, as CLAUDE.md or .claude/CLAUDE.md, committed. Personal preferences go in ~/.claude/CLAUDE.md, or CLAUDE.local.md for one project. Module rules go in that module's folder or in .claude/rules/ with paths.
Does Claude Code read AGENTS.md?
Recent versions do, when the repository has no CLAUDE.md. If you have both, put @AGENTS.md at the top of CLAUDE.md so Claude sees the shared rules too.
Why does Claude ignore a rule in CLAUDE.md?
Usually the file is too long, the rule is vague, or another file says something different. Shorten, make the rule concrete, and check nested files and rules for contradictions. If the rule must hold every time, move it to a hook, a permission or CI.
How is CLAUDE.md different from Cursor or Copilot rules?
Same purpose, different file formats and scoping syntax. Keep the shared content in AGENTS.md and let each tool's file add only what is specific to it.
Take your team there, step by step
A 13-week pilot on one team: a baseline, a harness built around your process, real backlog tasks through the whole cycle, and the numbers before and after.