CLAUDE.md is a Markdown file Claude Code loads into context at the start of every session. It can live at four scopes: a managed policy path, ~/.claude/CLAUDE.md, the project root as ./CLAUDE.md or ./.claude/CLAUDE.md, and ./CLAUDE.local.md for personal notes. Every discovered file is concatenated rather than overridden, broadest scope first. Anthropic documents a target of under 200 lines per file, because longer files consume context and reduce adherence. Write only what a competent engineer new to the repository would get wrong.
- Loaded at the start of every session. Length is a recurring cost, not a one-off.
- Files are concatenated, not overridden. Broadest scope first, your working directory last.
- Target under 200 lines per file (Anthropic docs, August 2026). Past that, adherence drops.
- Bloat has a proper fix:
.claude/rules/with apaths:glob loads only when it is relevant. - Claude Code reads
CLAUDE.md, neverAGENTS.md. Import or symlink it if you carry both.
Where the files live and how they load
Four scopes, listed here in load order from broadest to most specific. A project instruction therefore appears in context after a user instruction.
CLAUDE.md scopes, in the order they enter context. Verified against Anthropic docs, August 2026.
| Scope | Location | Commit it? |
|---|---|---|
| Managed policy | macOS /Library/Application Support/ClaudeCode/CLAUDE.md, Linux and WSL /etc/claude-code/CLAUDE.md, Windows C:\Program Files\ClaudeCode\CLAUDE.md | Deployed by IT |
| User | ~/.claude/CLAUDE.md | No, it is personal |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Yes |
| Local | ./CLAUDE.local.md | No, gitignore it |
Files in subdirectories below your working directory are found too, but they are not loaded at launch. They enter context when Claude reads a file in that subdirectory. Within any one directory, CLAUDE.local.md is appended after CLAUDE.md, so your personal notes are the last thing read at that level.
# in a session: lists Memory files that are in context right now
/context
# open or create any memory file across user and project scope
/memory
# generate a starting CLAUDE.md from the codebase
/init
What belongs in it
One test for every line: would a competent engineer new to this repository get this wrong? If no, delete it. Anthropic’s own guidance is to add an entry when Claude makes the same mistake a second time, or when you type the same correction you typed last session.
Include, and the reason.
| Include | Why |
|---|---|
| Build, test, and lint commands | Not discoverable; the agent will guess wrong |
| How to run one test | Stops it running the whole suite and paying for the output |
| Conventions that contradict the ecosystem default | Exactly what it will otherwise get wrong |
| Directory map for a large or unusual repo | Saves many exploration turns |
| Known traps and their reasons | Prevents a reverted fix being re-reverted |
| Things it must never do | Cheap insurance |
Leave out, and the reason.
| Leave out | Why |
|---|---|
| What the language or framework does | It knows |
| Your full API documentation | It can read the code |
| Directory layouts and dependency lists | Derivable from the codebase; /doctor proposes cutting exactly these |
| Team process and ticket workflow | Not actionable in an edit |
| A multi-step procedure | That is a skill, and a skill loads only when used |
| Long prose about philosophy | Costs context every session, changes nothing |
A complete example
# Project context
TypeScript API on Fastify, Postgres via Drizzle. pnpm workspace.
<!-- Maintainer note: block HTML comments are stripped before this
file reaches the model, so notes like this cost no context. -->
## Commands
- `pnpm dev` - local server on :3000
- `pnpm test` - full suite, about 4 minutes
- `pnpm test src/routes/auth.test.ts` - ONE file. Prefer this.
- `pnpm lint --fix` - run before proposing a diff
- `pnpm db:migrate` - after any schema change
## Conventions
- **No default exports.** Named exports only, enforced by lint.
- Errors: throw `AppError` from `src/errors.ts`, never a bare `Error`.
- All money is integer minor units. Never a float.
- Dates cross the wire as ISO 8601 UTC strings, never Date objects.
## Traps
- `src/legacy/billing.ts` is load-bearing and untested. Ask before touching it.
- Drizzle migrations are NOT reversible here. Check the generated SQL first.
- The test suite needs Postgres running: `docker compose up -d db`.
## Never
- Never commit directly to `main`.
- Never add a dependency without asking.
- Never edit anything under `src/generated/`.
Keeping it under 200 lines
Anthropic documents a target of under 200 lines per CLAUDE.md file, and is explicit about why: longer files consume more context and reduce adherence. Splitting into @path imports helps organisation but does not reduce context, because imported files load at launch too. The mechanism that actually reduces context is path-scoped rules.
Move procedures out to skills
If an entry is a multi-step workflow rather than a fact, it belongs in .claude/skills/<name>/SKILL.md. A skill body loads only when it is invoked, so long reference material costs almost nothing until you need it.
Move file-specific rules to .claude/rules/
A Markdown file in .claude/rules/ with a paths: frontmatter glob loads only when Claude touches a matching file. Rules with no paths field load at launch with the same priority as .claude/CLAUDE.md.
---
paths:
- "src/api/**/*.{ts,tsx}"
---
# API rules
- Every endpoint validates input with the shared zod schema.
- Errors use the standard response envelope in `src/errors.ts`.
- Add an OpenAPI comment block above each handler.
Import only what has to be there
Use @path/to/file to pull in another file. Relative paths resolve against the file containing the import, imports may recurse to a maximum of four hops, and paths inside backticks are not treated as imports. An import in a project file that resolves outside your working directory triggers a one-time approval dialog.
Run the trim check
The /doctor setup checkup proposes trims for a checked-in CLAUDE.md. It cuts content Claude can derive from the codebase (directory layouts, dependency lists, architecture overviews) and keeps pitfalls, rationale, and conventions that differ from tool defaults.
CLAUDE.md, rules, skills, and auto memory
Claude Code now has four ways to carry knowledge into a session, and picking the wrong one is the most common cause of a file that is both long and ignored.
Which mechanism for which kind of knowledge. As of August 2026.
| Mechanism | Written by | Loads | Use for |
|---|---|---|---|
CLAUDE.md | You | Every session, in full | Facts true in every session: commands, conventions, traps |
.claude/rules/*.md | You | At launch, or on a paths: match | Rules that only apply to part of the tree |
.claude/skills/ | You | Only when invoked | Multi-step procedures and long reference material |
| Auto memory | Claude | Index only, every session | Learnings Claude picks up from your corrections |
Auto memory is on by default. Claude writes its own notes to ~/.claude/projects/<project>/memory/, keyed on the git repository so every worktree of the same repo shares one directory. Only MEMORY.md is loaded at session start, and only the first 200 lines or 25KB of it, whichever comes first. Topic files next to it are read on demand.
{
"autoMemoryEnabled": false
}
AGENTS.md, and repos that carry both
Claude Code reads CLAUDE.md. It does not read AGENTS.md, which is the cross-tool file Codex and several others use. If your repository already has one, do not duplicate it.
@AGENTS.md
## Claude Code
Use plan mode for changes under `src/billing/`.
ln -s AGENTS.md CLAUDE.md
# then confirm it loaded
claude
> /context
When the file is loaded and still ignored
CLAUDE.md is delivered as a user message after the system prompt. It is context, not enforced configuration, so there is no guarantee of compliance, particularly for vague or conflicting instructions.
Causes, in the order worth checking.
| Symptom | Likely cause | Fix |
|---|---|---|
| Nothing from the file is honoured | It never loaded | Run /context and check Memory files |
| Followed sometimes, not always | Instruction is vague | Rewrite it as something verifiable |
| Two behaviours alternate | Contradictory files in the tree | Reconcile ancestor and nested files; both are in context |
Instruction disappears after /compact | It was a nested or path-scoped file | Project-root CLAUDE.md is re-injected; nested files reload on next match |
| A rule must hold every time | Wrong mechanism entirely | Use a PreToolUse hook, which runs regardless of what Claude decides |
| Other teams’ files are pulling in noise | Monorepo ancestor discovery | Add claudeMdExcludes globs in .claude/settings.local.json |
Questions people ask
A Markdown file Claude Code loads into context at the start of every session. It is where you record project commands, conventions, and traps so the agent does not have to rediscover them each time.
At the repository root as ./CLAUDE.md or ./.claude/CLAUDE.md, committed to version control. Personal project notes belong in CLAUDE.local.md, gitignored, and machine-wide preferences in ~/.claude/CLAUDE.md.
Anthropic documents a target of under 200 lines per file as of August 2026. Longer files consume more context and reduce adherence, so move procedures into skills and file-specific rules into .claude/rules/ instead of growing the one file.
No. Every discovered file is concatenated, ordered from the filesystem root down to your working directory. Both are in context at once, so contradictory instructions across the tree are resolved arbitrarily rather than by proximity.
Run /context in a session and look at the Memory files list. If your file is not there, Claude cannot see it, and no amount of rewriting the content will change the behaviour.
Yes. It is documentation read by a machine, it benefits from code review, and one person working out a convention should benefit everyone. Keep personal overrides in the gitignored CLAUDE.local.md.
No. Claude Code reads CLAUDE.md and not AGENTS.md, which is the cross-tool file Codex and others read. Carry both by making CLAUDE.md a single @AGENTS.md import, or a symlink if you have nothing Claude-specific to add.
Auto memory is a second system where Claude writes its own notes to ~/.claude/projects/<project>/memory/ based on your corrections. It is on by default. Only MEMORY.md loads at session start, capped at the first 200 lines or 25KB.
Sources
Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.