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.
Write CLAUDE.md in your project, or run /memory. Auto memory lives in ~/.claude/projects/<project>/memory/.
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 loads 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: An official docs page names this item. | Organization instructions | / (macOS), / (Linux and WSL), C: (Windows). It loads first, then ~/., then project files. claude cannot exclude it, not even by its absolute path. We checked this. See Probes | Machine |
claude setting | Documented: An official docs page names this item. | Managed CLAUDE. text inside managed settings | It has the same precedence as the managed file. Claude Code honors it only from managed settings | managed- |
~/. | Documented: An official docs page names this item. | Personal instructions | It loads for all projects. Imports in it need no approval dialog | User |
~/. | Documented: An official docs page names this item. | Personal rules | They load before project rules. Neither set overrides the other | User |
./ or ./. | Documented: An official docs page names this item. | Project instructions | Files in the working directory and each directory above it load at launch | Project |
./ | Documented: An official docs page names this item. | Private project notes | Claude Code appends it after CLAUDE. in the same directory. Add it to . | Project |
Subdirectory CLAUDE. | Documented: An official docs page names this item. | Lazy instructions | Loads once after Claude reads, writes, or edits a file in that subdirectory | Project |
AGENTS., . | Documented: An official docs page names this item. | Read when no CLAUDE. or CLAUDE. is in or above the working directory | Needs 2.. AGENTS., AGENTS., and . are not read | Project |
. | Documented: An official docs page names this item. | Project rules | Claude Code finds them recursively. Rules without paths load at launch with the priority of . | Project |
-- directories | Documented: An official docs page names this item. | Extra directories | Memory files load only when CLAUDE_. These files load: CLAUDE., ., ., and CLAUDE. | CLI |
Imports and Rule Files
| Item | Status | What it does | How it works | Where to set it |
|---|---|---|---|---|
@path/ | Documented: An official docs page names this item. | Imports a file at launch | Relative paths resolve from the importing file. The maximum depth is four hops. Put a backslash before each space in the path. Quoted paths do not import. Claude Code skips code spans and fenced blocks | Any memory file |
| External import | Documented: An official docs page names this item. | An import that resolves outside the working directory | A dialog asks once per project. If you decline, the imports stay off. User-scope files skip the dialog | Project files |
paths frontmatter in a rule | Documented: An official docs page names this item. | Scopes a rule to files | The value is a YAML list or comma string of globs. The rule loads when Read, Write, or Edit (or a Bash read such as cat) touches a match. The brace expansion budget is 1,000 patterns and 4 MiB per rule | . |
| Other rule frontmatter keys | Documented: An official docs page names this item. | Ignored | Claude Code reads only the paths key. Bad YAML loads the rule without paths | . |
| HTML block comments | Documented: An official docs page names this item. | Claude Code strips them before injection | Comments in code blocks stay | Any CLAUDE. |
Symlinks in . | Documented: An official docs page names this item. | Shares rules across projects | A target outside the working directory counts as an external import. Network paths do not load | . |
claude | Documented: An official docs page names this item. | Skips files by glob | It matches absolute paths with picomatch. Arrays merge across scopes. It applies only to user, project, and local files | Any settings scope |
Project instructions (/) | Documented: An official docs page names this item. | 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: An official docs page names this item. | Removes built-in commit and PR instructions | The default is true. The environment variable CLAUDE_ wins | Settings |
CLAUDE_ | Documented: An official docs page names this item. | Keeps CLAUDE. files out of 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: An official docs page names this item. | Turns auto memory on or off | The default is on in local sessions. The / toggle writes it to user settings | Any settings scope |
CLAUDE_ | Documented: An official docs page names this item. | An environment switch | 1 disables auto memory. 0 forces it on, even with -- or auto | Env |
auto | Documented: An official docs page names this item. | Sets the memory location | The value is an absolute path or ~/. The default is ~/.. The schema text says checked-in project settings ignore it. The docs say project scope works after trust | Settings |
auto scope | Differs: The official docs and the program disagree. The row says how. | The schema says Claude Code ignores the setting in project settings. How Claude Remembers Your Project says project and local scopes work under workspace trust | Docs and schema text differ | Settings |
MEMORY. | Documented: An official docs page names this item. | Index file | The first 200 lines or 25KB load at each session start. Topic files load on demand | Memory directory |
| Memory types | Documented: An official docs page names this item. | user, feedback, project, reference in the type frontmatter | Claude writes a modified ISO 8601 field (since 2.) | Memory files |
/ | Documented: An official docs page names this item. | Lists memory files, toggles auto memory, opens the folder | The editor opens a file | Interactive |
auto | Undocumented: Only the program shows this item. It can change without notice. | Background memory consolidation (auto-dream) | It overrides the server default | Settings |
/ | Undocumented: Only the program shows this item. It can change without notice. | Pauses memory for the session | Only the user can turn it back on. The text is memory access blocked by / | Interactive |
CLAUDE_, CLAUDE_, CLAUDE_, CLAUDE_ | Undocumented: Only the program shows this item. It can change without notice. | Cloud, Cowork, and post-turn memory | CLAUDE_: in a remote session (CLAUDE_), auto memory is off unless you set this variable. It sets the memory folder. The value is a full path outside Claude temp folders. CLAUDE_ is a JSON list of {"name","path"} objects. The built-in memory section stays. Claude Code names each store as a memory/ folder marked "(shared with all users of this project)". Claude Code also adds a 4 KB limit note per memory file. A list of strings, [], or text that is not JSON changes nothing. Set to 1, it drops the MEMORY. pointer rule and adds the 4 KB note. No memory_ tool was added. CLAUDE_ needs CLAUDE_ (JSON with a required instruction). Without a valid config, the pass is off. The pass also needs a cloud memory server. In a local run, the debug log says skipping (mcp) -. For this reason its live effect is not verified. The CLAUDE_ variables take text. _ names the memory folder. It is an absolute path, and it lets auto memory stay on in a remote session. _ replaces the built-in memory instructions. _ adds to them. _ replaces the MEMORY. text. An empty string turns the index read off. We ran the four CLAUDE_ variables in - | Env |
Subagent memory field | Documented: An official docs page names this item. | 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: An official docs page names this item. | Claude Code skips files over 4 MiB | A warning shows for files over 200 lines and for a combined size | Instruction files |
MEMORY. size | Documented: An official docs page names this item. | The limit is 200 lines or 25KB | A write over the limit succeeds but returns an error. The error asks for a rewrite | Memory |
| Compaction | Documented: An official docs page names this item. | Claude Code re-reads the project-root CLAUDE. 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: An official docs page names this item. | Absolute path of the file | String | Hook input |
memory_ | Documented: An official docs page names this item. | Scope | User, Project, Local, Managed | Hook input |
load_ | Documented: An official docs page names this item. | Why it loaded | session_, nested_, path_, include, compact | Hook input |
globs, trigger_, parent_ | Documented: An official docs page names this item. | Extra context | globs appears only for path_. parent_ appears for include | Hook input |
Instruction | Undocumented: Only the program shows this item. It can change without notice. | Tiers managed, user, project, local, memory | The Mod API uses it | Mod API |
How It Works
Instruction files do not go into the system prompt.
Claude Code reads them at launch. It walks up from the working folder. It adds the text as a user message.
Nested CLAUDE.md files and paths rules load later, when Claude reads a matching file.
After /compact, Claude Code reads the project-root CLAUDE.md again.
See The System Prompt and Context and Compaction.
Source: the program (read), and a probe of the interactive screen (2.1.305, local stub, fake key). See Interactive Probes. The warning shows in two places: a banner line under the header at start, and the Status screen (/status). It does not show in -p, in claude doctor, or in the get_status control reply (checked with a 45,000-character CLAUDE.md).
-
We saw this live at start on Sonnet 4.5:
CLAUDE.md is over the 40.0k-char limit (45.6k chars) · /memory to free up context. A 45.6k file on Opus 5.5 gave no warning. In/status, we saw:Large CLAUDE.md will impact performance (45.6k chars > 40.0k). -
We saw the warning for the total live. Four files of 34.4k characters each (all under 40k) gave a banner
4 instruction files add up to 137.6k chars, over the 120.0k-char total limit, with the largest files named./statussaidInstruction files will impact performance: 4 files, 137.6k chars in total > 120.0k. -
We saw this live on Opus 5.5 (1M window). A 156.0k-character file gave
CLAUDE.md is over the 150.0k-char limit (156.0k chars). A 116k file gave no warning. That checks 3 characters per token for that model. -
The one-file limit is the larger of 40,000 characters and 5% of the context window, turned into characters. Claude Code uses 4 characters per token for Claude 3 models, Opus 4.0 to 4.6, Sonnet 4.0 to 4.6, and Haiku 4.5. It uses 3 per token for every other model (Opus 4.7 and later, Sonnet 5 and later, Haiku 5.5, Fable, Mythos, and unknown names).
-
For a 200k window, 200,000 x 0.05 x 4 = 40,000. Also 200,000 x 0.05 x 3 = 30,000. The 40,000 floor applies to both.
-
For a 1M window, 1,000,000 x 0.05 x 4 = 200,000 for the 4-per-token models. For the rest, 1,000,000 x 0.05 x 3 = 150,000.
-
The total limit is the larger of 120,000 characters and the one-file limit. Only files under the one-file limit add to the total.
-
User,Project,Local, andManagedinstruction files count, including the files they import.MEMORY.mddoes not count. -
The messages are
Large <file> will impact performance (<n> chars > <limit>)for one file, andInstruction files will impact performance: <n> files, <total> chars in total > <limit>for the total. -
Since
2.1.309, a nestedCLAUDE.mdover the size limit loads only its start, so reading files under it no longer makes the session compact again and again (v2.1.309 release notes). Which limit applies is unconfirmed.
Errors
Each row is a family of messages. The backticked text is the start that every message in the family shares. A row marked Various gathers the messages of one feature that do not share one start.
| Start of Message | Status | What It Means | Cases |
|---|---|---|---|
| Various | Undocumented: Only the program shows this item. It can change without notice. | Memory stores. Claude Code refused a memory store key, mount, or sync. | A key escapes the memory directory (a null byte, backslash, absolute path, traversal, or symlink). A key is reserved. A key targets an excluded subtree. A mount name cannot be derived. CLAUDE_ is not valid JSON. A store listing returned an error. |
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.