Memory and Rules
Claude Code remembers your project in two ways.
CLAUDE.md files hold instructions that you write. Auto memory holds notes that Claude writes.
Rules in .claude/rules/ split instructions by topic and by file path.
Claude treats all of these as context, not as enforced configuration. The text arrives as a user message after the system prompt.
At a Glance
| Question | Answer |
|---|---|
| Can you use it? | ✅ Yes. Write CLAUDE. in your project, or run /. |
| Can you change it? | ✅ Yes. Edit the files, or set auto, auto, and claude. |
| Can you turn it on or off? | auto, CLAUDE_, and CLAUDE_. |
| Where does it live? | ~/., ./, ., and ~/.. |
| Status | Documented Undocumented Differs |
Example
# Project Notes
Use bun, not npm.
Run `bun test` before you say a task is done.
@docs/architecture.md
---
paths:
- "src/api/**/*.ts"
---
Every handler returns a typed error object. Never throw a plain string.
The first file loads in every session and imports docs/architecture.md. The second loads only after Claude touches a file that matches src/api/**/*.ts.
Instruction File Locations
The list runs in load order, broad scope first. A later file sits later in the context. Official page: How Claude Remembers Your Project.
| Item | Status | What it does | How it works | Where to set it |
|---|---|---|---|---|
Managed CLAUDE. | Documented | Organization instructions | / (macOS), / (Linux and WSL), C: (Windows). Cannot be excluded | Machine |
claude setting | Documented | Managed CLAUDE. text inside managed settings | Same precedence as the managed file. Honored only from managed settings | managed- |
~/. | Documented | Personal instructions | Loads for all projects. Imports in it need no approval dialog | User |
~/. | Documented | Personal rules | Load before project rules. No override between the two sets | User |
./ or ./. | Documented | Project instructions | Files in the working directory and each directory above it load at launch | Project |
./ | Documented | Private project notes | Appended after CLAUDE. in the same directory. Add it to . | Project |
Subdirectory CLAUDE. | Documented | Lazy instructions | Loads once after Claude reads, writes, or edits a file in that subdirectory | Project |
AGENTS., . | Documented | Read when no CLAUDE. or CLAUDE. is in or above the working directory | Needs 2.. AGENTS., AGENTS., and . are not read | Project |
. | Documented | Project rules | Found recursively. Rules without paths load at launch with the priority of . | Project |
-- directories | Documented | Extra directories | Memory files load only when CLAUDE_. Loads CLAUDE., ., ., CLAUDE. | CLI |
Imports and Rule Files
| Item | Status | What it does | How it works | Where to set it |
|---|---|---|---|---|
@path/ | Documented | Imports a file at launch | Relative paths resolve from the importing file. Maximum depth is four hops. Put a backslash before each space in the path. Quoted paths do not import. Code spans and fenced blocks are skipped | Any memory file |
| External import | Documented | An import that resolves outside the working directory | A dialog asks once per project. If declined, they stay off. User-scope files skip the dialog | Project files |
paths frontmatter in a rule | Documented | Scopes a rule to files | YAML list or comma string of globs. Loads when Read, Write, or Edit (or a Bash read like cat) touches a match. Brace expansion budget: 1,000 patterns and 4 MiB per rule | . |
| Other rule frontmatter keys | Documented | Ignored | paths is the only key read. Bad YAML loads the rule without paths | . |
| HTML block comments | Documented | Stripped before injection | Comments in code blocks stay | Any CLAUDE. |
Symlinks in . | Documented | Share rules across projects | A target outside the working directory counts as an external import. Network paths do not load | . |
claude | Documented | Skips files by glob | Absolute paths with picomatch. Arrays merge across scopes. User, project, and local files only | Any settings scope |
Project instructions (/) | Documented | Chooses claude- (default), claude-, claude-, or managed- | Stored in plugin. Read from user, --, and managed settings. agents- also works from 2. | User, managed |
include | Documented | Removes built-in commit and PR instructions | Default true. Env CLAUDE_ wins | Settings |
CLAUDE_ | Documented | No CLAUDE. files in context | 1 disables user, project, and auto memory files | Env |
Auto Memory
Auto memory is a folder of notes that Claude writes for itself. MEMORY.md is the index.
| Item | Status | What it does | How it works | Where to set it |
|---|---|---|---|---|
auto | Documented | Turns auto memory on or off | Default on in local sessions. / toggle writes it to user settings | Any settings scope |
CLAUDE_ | Documented | Env switch | 1 disables. 0 forces on even with -- or auto | Env |
auto | Documented | Memory location | Absolute path or ~/. Default ~/.. Ignored in checked-in project settings in the schema text. The docs say project scope works after trust | Settings |
auto scope | Differs | The schema says project settings are ignored. How Claude Remembers Your Project says project and local scopes work under workspace trust | Docs and schema text differ | Settings |
MEMORY. | Documented | Index file | The first 200 lines or 25KB load at each session start. Topic files load on demand | Memory directory |
| Memory types | Documented | user, feedback, project, reference in the type frontmatter | Claude writes a modified ISO 8601 field (since 2.) | Memory files |
/ | Documented | Lists memory files, toggles auto memory, opens the folder | Editor opens a file | Interactive |
auto | Undocumented | Background memory consolidation (auto-dream) | Overrides the server default | Settings |
/ | Undocumented | Pauses memory for the session | Only the user can turn it back on. Text memory access blocked by / | Interactive |
CLAUDE_, CLAUDE_, CLAUDE_, CLAUDE_ | Undocumented | Cloud, Cowork, and post-turn memory | Use not verified | Env |
Subagent memory field | Documented | A separate memory directory for a subagent | See Subagents | Agent frontmatter |
Limits
| Item | Status | What it does | How it works | Where to set it |
|---|---|---|---|---|
CLAUDE. size | Documented | Files over 4 MiB are skipped | A warning shows for files over 200 lines, and for a combined size | Instruction files |
MEMORY. size | Documented | 200 lines or 25KB | A write over the limit succeeds but returns an error that asks for a rewrite | Memory |
| Compaction | Documented | Project-root CLAUDE. is re-read after / | Nested files and paths rules load again on demand. Instructions shows load_ compact | Context |
The InstructionsLoaded Hook
The hook fires when an instruction file enters context.
It runs async and has no decision control.
It does not fire for an AGENTS.md that loads through the Project instructions setting.
The matcher runs on load_reason. Official page: Hooks Reference.
| Item | Status | What it does | How it works | Where to set it |
|---|---|---|---|---|
file_ | Documented | Absolute path of the file | String | Hook input |
memory_ | Documented | Scope | User, Project, Local, Managed | Hook input |
load_ | Documented | Why it loaded | session_, nested_, path_, include, compact | Hook input |
globs, trigger_, parent_ | Documented | Extra context | globs only for path_. parent_ for include | Hook input |
Instruction | Undocumented | Tiers managed, user, project, local, memory | Used by the Mod API | Mod API |
How It Works
Instruction files do not go into the system prompt.
Claude Code reads them at launch, walks up from the working folder, and adds the text as a user message.
Nested CLAUDE.md files and paths rules load later, when Claude reads a matching file.
After /compact, the project-root CLAUDE.md is read again.
See The System Prompt and Context and Compaction.
The size at which the combined-size warning for instruction files appears.
The use of the cloud, Cowork, and post-turn memory variables (CLAUDE_CODE_REMOTE_MEMORY_DIR, CLAUDE_CODE_POST_TURN_MEMORY).
Related Pages
- Environment Variables for the memory variables.
- Output Styles for answer style, which is separate from project facts.
- The System Prompt
- Captured CLAUDE.md Prompt
- Hook Events for the
InstructionsLoadedevent and Subagent Frontmatter for the subagentmemoryfield.