CLAUDE.md: what to put in it, where it goes, and examples
What CLAUDE.md is, where Claude Code looks for it, what to put in it and what to leave out, with an example file, imports, rules, AGENTS.md and auto memory.
CLAUDE.md is a Markdown file Claude Code reads at the start of every session: the commands to build and test, the conventions Claude would get wrong, the rules of the repository. Put it at the root of the repository, run /init to get a first draft, then cut it to what Claude cannot work out by reading the code.
What CLAUDE.md does
Claude Code finds every CLAUDE.md from your working directory up to the root, joins them, and hands the result to Claude as a message after the system prompt. Nothing overrides anything: your personal file comes first, the project's after it, and when two instructions contradict each other Claude may follow either. Files in subfolders load later, when Claude reads a file in that folder.
It is guidance, not configuration. Anthropic's permission docs say it plainly: instructions in CLAUDE.md "don't change what Claude Code allows". A rule that must hold every time — never edit .env, format after each write — belongs in a hook.
After /compact, Claude Code reads the project-root CLAUDE.md from disk again and puts it back, so a long session does not lose it.
Where CLAUDE.md files go
| Scope | Path | Who it is for |
|---|---|---|
| Organization | /Library/Application Support/ClaudeCode/CLAUDE.md (macOS) | set by IT, cannot be excluded |
| You, every project | ~/.claude/CLAUDE.md | your preferences |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | the team, in git |
| You, this project | ./CLAUDE.local.md | add it to .gitignore |
| A subfolder | ./packages/api/CLAUDE.md | loads when Claude reads files there |
How to create one: /init
/init reads the project and writes a CLAUDE.md with the commands and structure it found. If one exists, it suggests changes instead of overwriting it. It also reads .cursorrules, .cursor/rules/ and .github/copilot-instructions.md, so rules written for another tool carry over.
To add a line later, ask Claude to "add this to CLAUDE.md", or open the file with /memory. The # shortcut that used to do it was removed in 2.0.70.
What to put in CLAUDE.md
From Anthropic's best practices, include:
- Commands Claude cannot guess: how to build, run one test, lint.
- Style that differs from the default: "2-space indentation", not "format code properly".
- How to test, and what has to pass before a change is done.
- Repository etiquette: branch names, commit format, what never to commit.
- Decisions specific to this project, and the quirks of its environment.
- Gotchas: the thing every new contributor gets wrong.
And leave out:
- what Claude can learn by reading the code, file by file;
- standard conventions of the language it already knows;
- long API docs — link to them instead;
- anything that changes often;
- "write clean code" and other self-evident advice.
A CLAUDE.md example
A short project file, written for this page as an example. Every line is something Claude would otherwise get wrong:
# Acme API ## Commands - Install: pnpm install (never npm or yarn) - Test one file: pnpm vitest run path/to/file.test.ts - Before a commit: pnpm lint && pnpm typecheck ## Code - TypeScript strict; no `any`. Validate input with zod at the edge. - Database access only through src/db/repositories/. ## Workflow - Branch from main as feat/<topic>; Conventional Commits. - IMPORTANT: never edit migrations that are already merged; add a new one. ## Context - Architecture: @docs/architecture.md
Use emphasis such as "IMPORTANT" on the one line Claude keeps skipping. In Anthropic's words, "If you emphasize many lines, none of them stands out."
Keep it short: imports and rules
Anthropic's target is under 200 lines per file: "Longer files consume more context and reduce adherence." Two tools keep the root file short:
- Imports.
@docs/architecture.mdon a line pulls that file in, up to four levels deep. It organises a long file but does not save context: imported files load at launch too. The first time a project imports a file from outside it, Claude Code asks you to approve. - Rules. Markdown files in
.claude/rules/load like CLAUDE.md. Give one apaths:list in its frontmatter and it loads only when Claude reads or edits a matching file — the testing rules when it opens a test.
--- paths: ["src/**/*.test.ts"] --- - Use vitest; never jest. - One behaviour per test; no snapshots.
/doctor can trim checked-in CLAUDE.md files, and /context lists every memory file loaded in the current session.
CLAUDE.md and AGENTS.md
From Claude Code 2.1.277, a project with an AGENTS.md and no CLAUDE.md works as is: Claude Code reads AGENTS.md as the project's instructions. When the project has both, the default reads only CLAUDE.md. To share one file across agents, keep AGENTS.md as the source and make CLAUDE.md one line, @AGENTS.md, or change Project instructions in /config.
Instructions without editing CLAUDE.md
CLAUDE.md is shared: it is in the repository, so every teammate and every agent that reads it gets the same lines. For instructions that are only yours — a review style, "never push", how you like commits written — Claude Code has three places:
- Every project:
~/.claude/CLAUDE.md, in your home folder. - A local file:
CLAUDE.local.md, read with CLAUDE.md, in that project only; add it to.gitignoreso it stays yours. - A flag, for one launch:
--append-system-prompt; the text goes after Claude Code's own system prompt, which stays in place.
claude --append-system-prompt "Write commit messages in Conventional Commits"
A resumed conversation keeps the system prompt recorded on its first request, so new flag text reaches it only after the conversation is compacted, or in a new one. The flags, and how they differ from CLAUDE.md: Claude Code system prompt.
Caprock's desktop app keeps such instructions per project, so you do not retype the flag: every Claude Code session it starts in the project gets them through --append-system-prompt (since 0.81.0), and every Codex session as its developer instructions (since 0.82.0). They stay on your machine, not in the repository. Put the rules everyone needs in CLAUDE.md, and your own in project instructions.
CLAUDE.md and auto memory
Auto memory is the other half: notes Claude writes itself, on by default, in ~/.claude/projects/<project>/memory/. Its index, MEMORY.md, loads into each session up to 200 lines or 25 KB. Tell Claude to "remember" something and it goes there; tell it to add something to CLAUDE.md and it goes in the file you share. /memory turns auto memory off. How it loads, its limits and what neither of them keeps: Claude Code memory.
A real CLAUDE.md
Caprock's repository is public, and its CLAUDE.md is 93 lines at v0.70.1: what the product is in one paragraph, the folder layout, a pointer to the index of its design docs instead of their content, then numbered rules, each with the reason it exists. One of them:
The shim never breaks a user's Claude session. Every error path is silent exit 0 within 1s.
The pattern holds up: rules Claude would break without being told, and a map to where the detail lives, not the detail itself.
What CLAUDE.md does not carry: where you left off
CLAUDE.md holds what is always true. It does not hold what happened yesterday: the half-finished migration, the test you were about to fix. Caprock, the free app that records every agent session on your machine, keeps that. When a new session starts in a folder you have worked in, its hook hands Claude the last substantial passage the previous session there wrote, under this line (the age varies):
Where this repository was left, 3 hours ago (from Caprock's record of the previous session — the user has not said this to you, and it may be stale):
It is on by default; turn it off in settings. An opt-in setting holds it back from one new session in four, and Caprock's Memory screen compares the two groups, so you can measure whether it helps. The same screen searches everything Claude wrote across sessions, past Claude Code's 30-day cleanup — see Claude Code history.
Questions people ask
- What is CLAUDE.md?
- A Markdown file of instructions that Claude Code reads at the start of every session in a folder: build commands, code style, rules for the repository. It is guidance Claude reads, not a setting Claude Code enforces.
- Where should CLAUDE.md go?
- In the root of your repository, as ./CLAUDE.md or ./.claude/CLAUDE.md, to share it with the team. ~/.claude/CLAUDE.md applies to every project on your machine, and CLAUDE.local.md holds personal notes for one project.
- How long should CLAUDE.md be?
- Anthropic's docs suggest under 200 lines per file. Longer files take more context and Claude follows them less reliably.
- How do I create a CLAUDE.md?
- Run /init in Claude Code. It reads the project and writes a starting CLAUDE.md, or suggests improvements to one that exists. Then cut what Claude would do anyway.
- Does Claude Code read AGENTS.md?
- Yes, from version 2.1.277, when the project has no CLAUDE.md or CLAUDE.local.md. With both, add @AGENTS.md to CLAUDE.md, or change Project instructions in /config.
- Can I give Claude Code instructions without editing CLAUDE.md?
- Yes: claude --append-system-prompt adds text to the system prompt for one launch. Caprock's desktop app keeps instructions per project and passes them to every Claude Code session it starts there, and to Codex sessions as developer instructions.
- What happened to the # shortcut?
- It was removed in Claude Code 2.0.70. Ask Claude to add the line to CLAUDE.md instead, or open the file with /memory.
Sources
- Claude Code docs — How Claude remembers your project (CLAUDE.md, rules, auto memory), read 4 October 2026, re-read 21 October 2026
- Claude Code docs — Best practices, read 4 October 2026, re-read 21 October 2026
- Claude Code docs — Commands (/init, /memory, /context), read 4 October 2026, re-read 21 October 2026
- Claude Code docs — Configure permissions, read 4 October 2026, re-read 21 October 2026
- Claude Code docs — Context window, read 4 October 2026, re-read 21 October 2026
- Claude Code changelog — 2.0.70, the # shortcut removed
- Caprock's own CLAUDE.md, a public example
- Caprock source — the SessionStart handoff
- Caprock README — Pick up where you left off
- Claude Code docs — CLI reference: system prompt flags, and what a resumed conversation reuses, read 7 October 2026, re-read 21 October 2026
- Caprock docs — project instructions in the desktop app (docs/app.md)
- Caprock source — --append-system-prompt for Claude Code, developer_instructions for Codex (internal/agents/argv.go)
- Caprock source — instructions capped at 16 KB, kept with the project (internal/projects/projects.go)
- Caprock changelog — 0.81.0 project instructions; 0.82.0 for Codex too
Try it
The record of every coding agent you run, the sessions it did not start included. Free, open source; nothing leaves your machine.
Notarized by Apple. One file for Apple silicon and Intel, macOS 13 or later.
Or run it yourself:
Paste in Terminal: it installs Caprock and opens it.Or with Homebrew: brew install --cask dspv/tap/caprock-app