You drop Claude Code into your repo and ask for a small change. It picks the wrong package manager, scaffolds a component that ignores your folder conventions, and re-asks which test runner you use — again. Nothing is wrong with the model; it just has no idea what “the way we do things here” means. A CLAUDE.md file fixes that: it is the persistent project brief Claude reads at the start of every session, so it stops guessing and starts matching your stack.
CLAUDE.md is a special file that Claude Code automatically loads into context. Think of it as persistent memory that helps Claude understand your project’s specific needs, coding standards, and common workflows.
Key Benefits:
Persistent context across sessions
Shareable team knowledge, checked into source control
Review and customize
Claude will analyze your project and generate a tailored CLAUDE.md file
/init gives you a starting point, but it tends to be generic. The fastest way to get a CLAUDE.md that actually reflects your project is to make Claude audit the repo and write it from evidence:
Topic-specific, source-controlled rules that keep the root CLAUDE.md lean. Each file can target the paths it applies to with a paths frontmatter field — a YAML list of glob patterns:
---
paths:
- "src/app/api/**"
---
- Validate every request body with a Zod schema
- Return errors as { error: string } with the right status code
Use these for language- or area-specific guidelines so they only load when Claude touches matching files. Rules without a paths field load unconditionally.
When you keep catching Claude breaking the same convention in one area of the codebase, encode it as a scoped rule instead of repeating yourself:
For large projects, keep the root CLAUDE.md small and pull in focused files with the @path/to/import directive. Plain bullet lists with bare paths do nothing — only the @ prefix actually imports a file.
CLAUDE.md with @path imports
# Main Project Configuration
See @README.md for the project overview and @package.json for available commands.
## Architecture
High-level system design and principles live here...
## Detailed Conventions
- Frontend conventions @frontend/CLAUDE.md
- Backend conventions @backend/CLAUDE.md
- Infrastructure runbooks @infra/CLAUDE.md
- Testing rules @tests/CLAUDE.md
Imports accept both relative and absolute paths. Relative paths resolve against the file doing the importing, not your working directory, and @ directives inside fenced code blocks are ignored so examples like this one stay inert. For personal instructions you want shared across git worktrees, import from your home directory (for example @~/.claude/my-conventions.md).
Once a root CLAUDE.md grows past a few hundred lines, let Claude do the splitting for you:
Remember: A well-crafted CLAUDE.md file is like having perfect documentation that never gets lost and is always available exactly when Claude needs it.