Chapter 02 · Section II · 12 min read
2.2 Memory: CLAUDE.md hierarchy and content
CLAUDE.md is how a project tells Claude Code what it should know before doing anything. Where the files live, what belongs in each, and how the hierarchy composes.
Every non-trivial project has invariants — conventions, sharp edges, hidden gotchas — that a new contributor has to learn. CLAUDE.md is where you write them down so Claude Code reads them at the start of every session in the repo. It is a README.md for the model.
The file hierarchy
Claude Code looks in five places, from broad to narrow:
~/.claude/CLAUDE.md— user-global. Your personal conventions across every project.<repo>/CLAUDE.md— repo root. Team defaults for this project.<repo>/<subdir>/CLAUDE.md— subdirectory-scoped memory. Applies when work is happening inside that subtree.<cwd>/CLAUDE.md— the current working directory, if different.- Imports — a
CLAUDE.mdcan import others via@path/to/another.md.
All applicable files are loaded into the session’s context on start. Nested files add specificity; they do not override the parent.
What belongs in CLAUDE.md
Good candidates:
- Directory map. “The frontend lives in
apps/web. The design system lives inpackages/ui. Do not touchlegacy/.” - Conventions. “We use tabs. Tests use
vitest. HTTP handlers throw, never return errors.” - Common commands. “Tests:
pnpm test. Type check:pnpm typecheck.” - Sharp edges. “The auth token in
.env.exampleis a real dev-only token; do not swap it for a placeholder.” - Non-obvious file relationships. “Every route in
src/pageshas a matching entry insrc/nav.ts.”
Bad candidates:
- Things a
README.mdalready says. Reference it instead:@README.md. - Long prose.
CLAUDE.mdshould be a checklist, not an essay. - Anything that changes weekly. It will rot; contributors will not update it.
Imports and composition
# Project conventions
Frontend patterns: @packages/ui/CLAUDE.md
API patterns: @apps/api/CLAUDE.md
## Sharp edges
- `apps/legacy` is frozen; do not modify.
- The webhook secret in `.env.example` is intentional.
Imports are resolved relative to the file that mentions them. Circular imports are ignored. Depth is bounded to avoid infinite loops.
Editing memory from a session
The /init command bootstraps a CLAUDE.md from the current repo. The /memory command opens the resolved memory in an editor for quick edits.
Check your understanding
Quick check
—