Skip to main content

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.

Context, not configuration. Claude Code delivers CLAUDE.md as a user message after the system prompt. Claude reads it and tries to follow it, but nothing enforces it. To block an action no matter what, use a PreToolUse hook or a 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.

CLAUDE.md
# 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.

CLAUDE.md file locations, from broadest to most specific scope
ScopePathShared withUse it for
Managed policymacOS: /Library/Application Support/ClaudeCode/CLAUDE.md Linux/WSL: /etc/claude-code/CLAUDE.md Windows: C:\Program Files\ClaudeCode\CLAUDE.mdEveryone on the machineDeployed by IT. Cannot be excluded by user settings.
User~/.claude/CLAUDE.mdOnly you, every projectPersonal style and tooling preferences.
Project./CLAUDE.md or ./.claude/CLAUDE.mdYour team, via gitBuild commands, conventions, architecture.
Local./CLAUDE.local.mdOnly you, this projectAdd 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.

Launched in ~/code/acme/apps/web
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.

Markdown syntax with special meaning inside CLAUDE.md
You writeIn a normal .md fileIn CLAUDE.md
@path/to/file.mdPlain 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 codeStays literal. Imports are skipped inside code spans and fenced code blocks.
@Design\ Docs/api.mdA backslash-escaped spaceImports 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 fileBlock-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.

CLAUDE.md
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.

.claude/rules/api.md
---
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.ts

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

Which instruction files Claude Code reads by default
Your repo hasClaude Code reads
AGENTS.md, no CLAUDE.md or CLAUDE.local.mdAGENTS.md
AGENTS.md and a CLAUDE.md or CLAUDE.local.mdCLAUDE.md files only
A CLAUDE.md containing @AGENTS.mdCLAUDE.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:

CLAUDE.md
@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

Claude Code commands for creating and checking CLAUDE.md
CommandWhat it does
/initWrites 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.
/memoryLists 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.
/contextShows which CLAUDE.md and rules files actually loaded, under Memory files. The first thing to check when instructions seem ignored.
/doctor prompt-auditReports 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

Anthropic's target is under 200 lines per file; longer files cost context and lower adherence. Claude can read your directory tree itself. Write down the pitfalls, the rationale, and the conventions that differ from tool defaults.

Avoid

Splitting a long file into @imports to make it smaller

Do

Move area-specific rules into .claude/rules/ with a paths field

Imported files load at launch with the file that imports them, so they save nothing. A path-scoped rule only loads when Claude touches a matching file.

Avoid

"Format code properly" and "test your changes"

Do

"Use 2-space indentation" and "Run pnpm test before committing"

Claude treats CLAUDE.md as context, not configuration. The more concrete and checkable an instruction, the more consistently it is followed.

Avoid

Writing "NEVER push to main" in capitals and hoping

Do

Enforce hard rules with a hook or a permissions.deny setting

CLAUDE.md arrives as a user message after the system prompt, and there is no guarantee of strict compliance. Anything that must always or never happen belongs in a PreToolUse hook or settings.

Avoid

Writing `@docs/setup.md` in backticks to import it

Do

Write @docs/setup.md as plain text

Import parsing skips code spans and fenced blocks on purpose, so you can mention a path without loading it. Backticks turn an import into a mention.

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.