CLAUDE.md files inject persistent context into every Claude Code session. They are read at startup and at every tool-use boundary, so changes take effect immediately without restarting.
Claude Code loads CLAUDE.md files in order from broadest to narrowest scope. Each layer can add, specialize, or override guidance from the layer above it.
Narrower scopes do not replace broader ones — all applicable CLAUDE.md files are concatenated and injected together. Conflicts are resolved in order: inline > subdir > project > global.
Use @import to split a large CLAUDE.md into focused files without losing coverage.
# CLAUDE.md @import docs/testing-conventions.md @import docs/api-style-guide.md ## Project Overview This is the payments service...
Effective CLAUDE.md rules are specific, testable, and explain the why.
# Good: specific, testable, explains why ## Testing - Always use `pytest` (not `unittest`) — project uses fixtures that require pytest plugins. - Run `pytest -x` to stop on first failure during development. - Test files go in `tests/` mirroring `src/` structure: `src/auth.py` → `tests/test_auth.py`. # Why: comment pattern for non-obvious rules - Do NOT import from `src/internal/` in tests. # Why: internal/ is scheduled for deletion in Q3; tests that use it will break at the rename. # Bad: vague, untenable ## Testing - Write good tests. - Be careful with internal modules.
Prefix rules with a glob pattern to make them apply only when Claude is working on matching files.
# For src/api/**:
- All handlers must validate input with Zod before accessing req.body.
- Return errors as { error: string, code: string } — never throw.
# For migrations/**:
- Migrations are append-only. Never modify an existing migration file.
- Always add a comment with the date and author on line 1.
On Linux filesystems the filename is case-sensitive. The file MUST be named exactly CLAUDE.md (all caps). claude.md, Claude.md, and CLAUDE.MD will not be loaded. macOS is case-insensitive by default, so this only bites teams who dev on Mac and deploy/test on Linux.