Materials / Practices

CLAUDE.md: Claude Code instructions in a team repository

CLAUDE.md is how a team tells Claude Code what it would otherwise explain again in every session. This guide covers where the files go, how they combine with AGENTS.md, and which rules should never rely on a Markdown file at all.

9 min read7 Oct 2026Ilia Poliakov

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:

LevelLocationWho 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 WindowsThe whole organization, deployed by IT: security and compliance reminders
User~/.claude/CLAUDE.mdOne person, every project: personal preferences
Project./CLAUDE.md or ./.claude/CLAUDE.mdThe team, committed to git: commands, structure, conventions
Local./CLAUDE.local.md, listed in .gitignoreOne person, one project: a sandbox URL, preferred test data
SubdirectoryCLAUDE.md in a folder below where Claude startedOne 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 hasClaude reads
AGENTS.md and no CLAUDE.mdAGENTS.md
Both AGENTS.md and CLAUDE.mdCLAUDE.md only
A CLAUDE.md that imports AGENTS.mdCLAUDE.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:

/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:

RuleWhere it belongs
Formatting, import order, naming styleFormatter 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 writeClaude 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, reviewSkills and commands
Judgement a tool cannot check: domain rules, trade-offs, when to askCLAUDE.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:

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

  1. It lives in gitThe project CLAUDE.md and .claude/rules/ change through pull requests, reviewed like code.
  2. It has ownersOne or two people review changes and say no to rules added "just in case".
  3. Rules come from casesEach new line answers a mistake that happened, ideally twice. A line with no story behind it is a guess.
  4. 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.