Skip to main content
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
Omit:
  • 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
The test: would removing this line cause Claude to make a mistake on your codebase? If not, cut it.

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).
.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.
1

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.
2

User memory

~/.claude/CLAUDE.md and ~/.claude/rules/*.md — your personal global instructions for all projects.
3

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).
4

Local memory

CLAUDE.local.md in each directory from root to CWD. Same traversal order. Gitignored by default.

The @include directive

Memory files can include other files using @ notation. Included files are processed recursively and inserted before the file that references them.
Supported path formats: Behavior:
  • 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
  • @include inside code blocks is not processed
External includes (files outside the project directory) require explicit approval the first time they are loaded. Claude will prompt you to confirm before fetching content from outside your project.

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.
Rules without frontmatter apply unconditionally. Rules 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.
The generated file is a starting point. Review it, trim anything that isn’t genuinely useful, and add project-specific knowledge that Claude couldn’t infer from the code.

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.
Changes take effect immediately — Claude reloads the updated file and applies the new instructions to the current 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:
Patterns are matched against absolute paths using picomatch. Only User, Project, and Local memory types can be excluded — Managed (administrator) files are always loaded. See Settings for full documentation on the claudeMdExcludes option.