CLAUDE.md files let you encode project knowledge that Claude loads at the start of every session. Instead of explaining your project’s conventions, build system, and architecture every time, you write them once and Claude reads them automatically.
What belongs in CLAUDE.md
Write instructions that would cause mistakes if missing. Everything else is noise. Include:- Build, test, and lint commands (exact invocations, not just tool names)
- Architecture decisions that affect how code should be written or organized
- Coding conventions specific to your project (naming patterns, file structure rules)
- Environment setup requirements (required env vars, expected services)
- Common pitfalls or patterns Claude should know to avoid
- Monorepo structure and which packages own which responsibilities
- Things Claude already knows (standard TypeScript syntax, common library APIs)
- Obvious reminders (“write clean code”, “add comments”)
- Sensitive data — API keys, passwords, tokens, or secrets of any kind
- Information that changes frequently and will become stale
File locations
Claude discovers memory files by traversing from your current directory up to the filesystem root. Files closer to your current directory have higher priority (they are loaded later, so the model pays more attention to them).| File | Type | Purpose |
|---|---|---|
/etc/claude-code/CLAUDE.md | Managed | System-wide instructions for all users, set by administrators |
~/.claude/CLAUDE.md | User | Your personal global instructions, applied to every project |
~/.claude/rules/*.md | User | Modular global rules, each file loaded separately |
CLAUDE.md (project root) | Project | Shared team instructions, checked into source control |
.claude/CLAUDE.md (project root) | Project | Alternative location for shared project instructions |
.claude/rules/*.md (project root) | Project | Modular project rules, organized by topic |
CLAUDE.local.md (project root) | Local | Your private project-specific instructions, not checked in |
.claude/rules/ directories support subdirectories. All .md files found recursively are loaded as separate memory entries.Loading order and priority
Files are loaded in the following order. Because the model attends more to content that appears later in context, later files have higher effective priority.Managed memory
/etc/claude-code/CLAUDE.md and /etc/claude-code/rules/*.md — global policy set by administrators. Always loaded; cannot be excluded by users.User memory
~/.claude/CLAUDE.md and ~/.claude/rules/*.md — your personal global instructions for all projects.Project memory (root-to-CWD)
CLAUDE.md, .claude/CLAUDE.md, and .claude/rules/*.md files in each directory from the filesystem root down to your current directory. Files in directories closer to your CWD are loaded later (higher priority).The @include directive
Memory files can include other files using@ notation. Included files are processed recursively and inserted before the file that references them.
| Syntax | Resolves to |
|---|---|
@filename | Relative to the current file’s directory (same as @./filename) |
@./relative/path | Relative to the current file’s directory |
@~/path/in/home | Path under your home directory |
@/absolute/path | Absolute filesystem path |
- Paths with a fragment (
#heading) have the fragment stripped before resolving - Non-existent files are silently ignored
- Circular references are detected and prevented
- Includes nest up to 5 levels deep
- Only text file formats are supported — binary files (images, PDFs) are skipped
@includeinside code blocks is not processed
Frontmatter path targeting
Files in.claude/rules/ can use YAML frontmatter to restrict which file paths they apply to. This lets you load rules conditionally based on the file Claude is working with.
paths frontmatter only apply when Claude is working in files matching the glob patterns.
Example CLAUDE.md for a TypeScript project
Generating CLAUDE.md with /init
Run/init in any Claude Code session to automatically generate a CLAUDE.md for your project. Claude analyzes your codebase and produces a file containing the commands and context most relevant to the project.
Editing CLAUDE.md with /memory
Run/memory to open the memory editor, which lists all currently loaded memory files and lets you edit them directly within the session.
Excluding files
If you have CLAUDE.md files you want to prevent Claude from loading (for example, in vendored dependencies or generated code), add exclusion patterns to your settings:claudeMdExcludes option.