1. What Goes in a CLAUDE.md?
CLAUDE.md is a markdown file of instructions that Claude Code reads at the start of every session. Because it loads every time, each line takes a little attention on every task. Anthropic's docs say the file works best when it holds only what Claude could not work out from the code:
- • How to confirm work in this repo: the exact test, typecheck and lint commands, and how to run a single test file.
- • Places where the code is misleading: an old pattern that new code must not copy, or a directory that looks unused but is not.
- • Decisions that are not in the repo: which error helper the team settled on, how deploys work, what needs a migration review.
- • Anything you have had to correct twice.
That is why all four templates below use the same three headings: Commands, Conventions and Gotchas. The commands, paths and package names are examples. Replace every one with your own, and delete any line that is not true for your repo. A wrong line is worse than a missing one.
2. CLAUDE.md Template for a Python Service
For an API or backend service that uses uv, pytest, ruff and Alembic. Swap in your own tools if you use pip, poetry, mypy or Django migrations.
# Commands
- Install: uv sync
- Run the API locally: uv run uvicorn app.main:app --reload
- Run one test file: uv run pytest tests/test_orders.py -q
- Lint and types: uv run ruff check . && uv run pyright
- New migration: uv run alembic revision --autogenerate -m "describe change"
# Conventions
- Raise the errors in app/errors.py, never a bare Exception
- Database access goes through app/repositories/, not from route handlers
- Settings come from app/config.py; do not read os.environ elsewhere
- app/legacy/ is still in production: fix bugs there, do not copy its patterns
# Gotchas
- Integration tests need DATABASE_URL set, see .env.example
- Never edit a migration that is already merged; add a new one
- The orders table is large: any new query on it needs an index reviewNotice the "run one test file" line. Claude checks its own work as it goes, and running one file is faster than running the whole suite after every edit.
3. CLAUDE.md Template for a TypeScript Web App
For a React or Next.js app that uses pnpm, Vitest and Playwright.
# Commands
- Install: pnpm install
- Dev server: pnpm dev
- Run one test file: pnpm vitest run path/to/file.test.ts
- Typecheck: pnpm tsc --noEmit
- Lint: pnpm lint
- End-to-end tests: pnpm playwright test (needs the dev server running)
# Conventions
- Server data is fetched in src/lib/api/, never inside components
- Use the Button, Input and Dialog in src/components/ui/, do not add a new UI library
- Use the error helpers in src/lib/errors.ts, never throw raw strings
- Prefer named exports
- src/legacy/ is still live but do not copy its patterns into new code
# Gotchas
- Environment variables are validated in src/env.ts; add new ones there first
- Translations live in messages/*.json: every new string needs a key in en.json
- Do not change files under src/generated/, they are rebuilt by pnpm codegen"Prefer named exports" belongs here because it has exceptions and needs judgment. A rule with no exceptions, such as never editing src/generated/, is better enforced with a hook; the line above is the reminder, not the lock.
4. CLAUDE.md Template for a Monorepo
In a monorepo the root file stays small and points down. Each app or service gets its own CLAUDE.md with its own commands. Claude Code loads a subdirectory's CLAUDE.md only when it reads or edits a file in that directory, so a person working in apps/web does not pay for the API team's rules. This example uses pnpm workspaces and Turborepo.
# Layout
- apps/web (customer site), apps/admin, services/api, packages/ui, packages/config
- Each app and service has its own CLAUDE.md with its commands. Read it before working there.
# Commands (run from the repo root)
- Install: pnpm install
- Test one package: pnpm --filter @acme/api test
- Build one app: pnpm turbo run build --filter=@acme/web
- Lint everything: pnpm turbo run lint
# Conventions
- Shared code goes in packages/, never import from one app into another
- A change to packages/ui needs a changeset: pnpm changeset
- Keep a pull request inside one app or package where possible
# Gotchas
- services/api owns the database schema; other packages must not write SQL
- CI only runs tests for packages that changed, so run the affected package's tests yourselfIf another team's CLAUDE.md gets picked up and is not relevant to you, skip it with the claudeMdExcludes setting in .claude/settings.local.json:
{
"claudeMdExcludes": ["**/services/billing/CLAUDE.md"]
}5. CLAUDE.md Template for a Data or ML Project
Data and ML repos have two risks a web app does not: expensive jobs and sensitive data. The Gotchas section carries most of the value here. This example uses uv, pytest and DVC.
# Commands
- Install: uv sync
- Fast tests: uv run pytest -q -m "not slow"
- Lint: uv run ruff check .
- Smoke eval (about 2 minutes): uv run python -m evals.run --suite smoke
- Pull data and model files: dvc pull
# Conventions
- Notebooks in notebooks/ are for exploration; never import from them
- Reusable code lives in src/pipeline/ and has tests
- Every experiment is a config file in configs/, not edited constants in code
- Set the random seed through utils.seed_everything, never ad hoc
# Gotchas
- Do not start a full training run. Ask first; a full run takes hours and costs money
- data/raw/ is read-only. Write derived data to data/processed/
- Changing a prompt or a preprocessing step means re-running the smoke eval
- Never print or commit rows from data/raw/, they contain customer data"Do not start a full training run" and "never print rows from data/raw/" are lines where a mistake is costly. Keep them in the file, and back them with a deny rule or a hook as well. The file asks; the hook enforces.
Get the AI engineering newsletter
Practical, engineering-first breakdowns on AI agents, LLMs, and breaking into the field — plus the free roadmap PDF when you join. No spam.
By subscribing you agree to receive emails from AI Engineer Insights. Unsubscribe anytime. See our Privacy Policy.
6. What Should You Leave Out of CLAUDE.md?
Most CLAUDE.md files fail by being too long. Anthropic's guidance is to target under 200 lines per file, because longer files use more context and reduce how well Claude follows them. If you start from /init, the work is mostly removing lines.
| Leave out | Why | Where it goes instead |
|---|---|---|
| Folder layout, architecture overview, dependency list | Claude reads the repo itself. /doctor proposes cutting exactly these | Nowhere. Delete it |
| A multi-step procedure (release, migration, incident steps) | It costs attention on every unrelated task | A skill, which loads only when it is needed |
| Rules for one folder or file type | They load in every session, even when Claude never touches that code | A path-scoped file in .claude/rules/ |
| A rule that must never be broken | CLAUDE.md is context, not enforced configuration | A hook, a deny rule or a managed setting |
| Your personal preferences | The file is shared with the whole team through git | CLAUDE.local.md, added to .gitignore |
| IMPORTANT, NEVER and repeated emphasis | The docs say emphasis probably will not fix an ignored line | Shorten the file, or move the rule to a hook |
| Vague advice such as "write clean code" | Nothing in it can be checked | A specific line: "Use 2-space indentation" |
| Two lines that disagree | Claude may pick one arbitrarily | Remove one; /doctor prompt-audit finds them |
One more, which is our advice and not from the docs: never put secrets, tokens or customer data in CLAUDE.md. The file is committed to the repo and sent to the model in every session.
7. CLAUDE.md vs CLAUDE.local.md vs .claude/rules
All of these are instruction files that Claude Code loads into context. They differ in who sees them and when they load.
| File | Where it lives | Who it applies to | When it loads | Use it for |
|---|---|---|---|---|
| CLAUDE.md | ./CLAUDE.md or ./.claude/CLAUDE.md | The team, through git | At launch, in every session | Commands, conventions and gotchas for the whole project |
| CLAUDE.local.md | ./CLAUDE.local.md, in .gitignore | Only you, in this project | At launch, right after the CLAUDE.md beside it | Your sandbox URLs, preferred test data |
| .claude/rules/*.md | One topic per file, in .claude/rules/ | The team, through git | No paths field: at launch. With paths: when Claude works on a matching file | Rules for one part of the codebase |
| ~/.claude/CLAUDE.md | Your home directory | Only you, in every project | At launch, before project files | Personal style and tool preferences |
| Subdirectory CLAUDE.md | For example services/api/CLAUDE.md | The team, through git | When Claude reads or edits a file in that directory | Commands and rules for one package in a monorepo |
The files are joined together, not overridden. Claude Code loads CLAUDE.md and CLAUDE.local.md from your working directory and every directory above it, ordered from the top of the filesystem down, so the instructions closest to where you started are read last. Within one directory, CLAUDE.local.md comes after CLAUDE.md.
A path-scoped rule
A file in .claude/rules/ with a paths field loads only when Claude works on a matching file. paths is the only frontmatter field Claude Code reads from a rule.
---
paths:
- "src/api/**/*.ts"
---
# API rules
- Every endpoint validates its input
- Use the standard error response formatImports
A CLAUDE.md can pull in another file with @path/to/file. Imports help you organise a long file, but they do not make it cheaper: the imported file loads together with the CLAUDE.md that imports it. Imports can nest up to four levels deep.
8. Does Claude Code Read AGENTS.md?
Yes. From Claude Code v2.1.277, a repository that already has an AGENTS.md for other coding agents works without a CLAUDE.md, an import or a setting. What Claude reads by default:
| Your repository has | Claude reads |
|---|---|
| An AGENTS.md, and no CLAUDE.md or CLAUDE.local.md in your working directory or above it | Your AGENTS.md |
| An AGENTS.md and a CLAUDE.md or CLAUDE.local.md | Your CLAUDE.md files only |
| A CLAUDE.md that imports AGENTS.md | Your CLAUDE.md, with AGENTS.md included through the import |
The second row surprises people. If you add a CLAUDE.local.md for your own notes in a repo that relies on AGENTS.md, Claude stops reading AGENTS.md for you. To read both, type /config and set Project instructions to claude-md-and-agents-md.
To keep one shared file for every tool and still add Claude-specific lines, import it from a CLAUDE.md next to it:
@AGENTS.md
## Claude Code
Use plan mode for changes under src/billing/.- • Not read:
AGENTS.local.md,AGENTS.override.md, or anything under a.agents/directory. - • A symlink also works (
ln -s AGENTS.md CLAUDE.md), but Claude's edit tools refuse to write through a symlink, and symlinks are awkward on Windows. The docs recommend the import if anyone on the team uses Windows. - • Moving from another tool:
/initreads Cursor rules and Copilot instructions and folds the relevant parts into the CLAUDE.md it writes.
9. How Do You Check That CLAUDE.md Is Working?
| Command | What it does |
|---|---|
| /init | Writes a starting CLAUDE.md from your codebase. If one exists, it suggests improvements and does not overwrite |
| /context all | Lists what loaded under Memory files, so you can confirm your file is there |
| /memory | Opens your CLAUDE.md files for editing and shows auto memory |
| /doctor | Proposes trims for content Claude can work out from the code |
| /doctor prompt-audit | Flags instructions written for older models, references to missing files, and lines that contradict each other. Needs v2.1.283 or later |
Three behaviours worth knowing:
- • It survives compaction. After
/compact, Claude Code re-reads the project-root CLAUDE.md from disk. An instruction you gave only in conversation does not survive, so write it down. - • HTML comments are free. Block-level
<!-- notes -->comments are stripped before the file reaches Claude, so you can leave notes for teammates without spending context. - • Very large files are skipped. Claude Code skips an instruction file over 4 MiB, and warns at startup when a file is over the recommended length.
If Claude still ignores a line, the docs give the order to check: is the file listed under Memory files, is the line specific, does another file contradict it. If the line must hold every time, it is a hook. Our Claude Code best practices guide covers that split, and the Claude Code cheat sheet lists the commands above with the rest.
10. FAQ
What is a CLAUDE.md file?
CLAUDE.md is a markdown file of instructions that Claude Code reads at the start of every session. You write it in plain text, usually with the commands to test and lint the project, team conventions and known pitfalls. Claude treats it as context, so it guides behaviour but does not enforce it.
Where do I put CLAUDE.md?
Put the project file at ./CLAUDE.md or ./.claude/CLAUDE.md and commit it so the team shares it. Use ~/.claude/CLAUDE.md for personal preferences across all projects, and ./CLAUDE.local.md, added to .gitignore, for personal notes on one project.
How long should a CLAUDE.md be?
Anthropic's docs recommend under 200 lines per file. Longer files use more context and reduce how reliably Claude follows them. Move instructions for one part of the codebase into path-scoped rules in .claude/rules/, and multi-step procedures into skills.
What is the difference between CLAUDE.md and CLAUDE.local.md?
CLAUDE.md is shared with the team through version control. CLAUDE.local.md holds your personal preferences for that project, is added to .gitignore, and loads right after the CLAUDE.md in the same directory. Both are treated the same way once loaded.
Does Claude Code read AGENTS.md?
Yes, from Claude Code v2.1.277. By default it reads AGENTS.md only when there is no CLAUDE.md or CLAUDE.local.md in your working directory or above it. If you have both, add the line @AGENTS.md to your CLAUDE.md, or set Project instructions to claude-md-and-agents-md in /config.
Why is Claude ignoring my CLAUDE.md?
CLAUDE.md is context, not enforced configuration, so there is no guarantee of strict compliance. Run /context all to confirm the file loaded, make the instruction specific enough to verify, and remove conflicting lines. If it must happen every time, write it as a hook instead.
Can Claude Code write the CLAUDE.md for me?
Yes. Run /init and Claude analyses the codebase and writes a starting file with the build commands, test instructions and conventions it finds. If a CLAUDE.md already exists, /init suggests improvements and does not overwrite it. Then remove what Claude could have read from the code.
11. Sources
- • Claude Code docs — How Claude remembers your project (CLAUDE.md, rules, AGENTS.md)
- • Claude Code docs — Best practices (Keep CLAUDE.md short)
- • Claude Code docs — Hooks guide
- • Claude Code docs — Skills
Checked against Anthropic's Claude Code docs on November 23, 2026. The four templates are our own examples, and their commands, paths and package names are placeholders to replace. Version numbers and settings are as the docs state them; Claude Code changes weekly, so run /release-notes if something here does not match.