# Rules that wait and memory that stays

Path-scoped rules load only when a matching file is touched, and auto memory is notes Claude writes for itself. Each one has a different answer to the question of what survives.

## Two ways to keep instructions out of the way

CLAUDE.md loads in full, every session. That is right for what applies everywhere, and wasteful for the rest. Claude Code gives you two other places for text, and they behave very differently.

**Rules** are topic files in `.claude/rules/`, found recursively. **Auto memory** is notes that Claude writes itself. One you author and one it authors, and the question to ask of each is the same: when does it load, and what happens to it later?

## Rules, and the paths filter

A rule file with no frontmatter loads at launch, exactly like CLAUDE.md. The interesting case is a rule with a `paths:` field.

```markdown
---
paths:
  - "src/api/**/*.ts"
---

Every endpoint validates its input with the shared schema helper.
Return errors through `ApiError`, never a bare string.
```

This rule costs nothing until Claude reads or edits a file that matches the glob. Then it appears. A frontend session never pays for backend rules, and the rule shows up at the moment it can matter.

Only the `paths` field is read. Any other frontmatter field is silently ignored, so a `description:` you add for yourself does nothing.

> **The price of arriving late**
Path-scoped rules, and nested CLAUDE.md files in subdirectories, arrive as part of the conversation history. That means compaction can summarize them away. If a rule must survive, remove its `paths:` frontmatter or move it to the root CLAUDE.md.


**Question:** A path-scoped rule disappears after a long session was compacted. Why?

- Rules expire after an hour
- It arrived as conversation history, which compaction can summarize
- paths: rules only work in new projects
- Compaction deletes all rules

**Answer:** It arrived as conversation history, which compaction can summarize. Unscoped rules and the root CLAUDE.md are part of the project context. Scoped rules arrive mid-conversation, so a summary can absorb them.


## Auto memory

Auto memory is a folder of notes under `~/.claude/projects/<project>/memory/`. It has a `MEMORY.md` index and topic files beside it, in four kinds: user, feedback, project and reference.

At startup only the first 200 lines or 25KB of `MEMORY.md` load. The topic files are read on demand. So the index is the part that costs you, and a short index is the discipline.

Three facts decide how it behaves:

- It is shared by all worktrees and subdirectories of the same git repo.
- It is machine-local. It does not sync to other machines or into cloud sessions.
- It is not loaded into subagents. A fork is the exception, because it inherits the whole conversation.

Memory files are excluded from the transcript retention sweep. They stay until you edit or delete them.

```terminal
$ /memory
* Opens the CLAUDE.md files and the auto memory toggle
# To switch it off in settings: autoMemoryEnabled. In the shell: CLAUDE_CODE_DISABLE_AUTO_MEMORY=1
```

## What survives what

This is the table worth carrying away.

```flow
CLAUDE.md edited mid-session: applies after /clear, /compact or restart
Root CLAUDE.md: stays through compaction
Scoped rules and nested CLAUDE.md: can be summarized away
Auto memory files: stay until you edit or delete them
```

Read it as a question about where the text lives. Text in the project context is reloaded. Text that arrived during the conversation is conversation, and conversation is what compaction rewrites.

> **When user and project rules disagree**
User-level rules load before project rules. When they conflict, neither wins, and Claude may follow either. If a rule matters, do not leave it contradicted somewhere else.


## Choosing the place

A short guide that follows from the above:

- Applies to everything, no exceptions needed: CLAUDE.md, or a hook if it must be enforced.
- Applies to one kind of file: a rule with `paths:`, accepting that compaction may absorb it.
- A learning Claude made about you or the project: auto memory, which you can read and edit like any file.
- A multi-step procedure: a skill.

**Question:** Where does auto memory live, and who else sees it?

- In the project repo, shared with teammates through git
- In ~/.claude/projects/<project>/memory/, local to your machine
- In the cloud, synced to every device
- Inside CLAUDE.md

**Answer:** In ~/.claude/projects/<project>/memory/, local to your machine. Auto memory is machine-local. It is shared across worktrees of the same repo on that machine, but not synced elsewhere.


> **Read what Claude wrote**
Run `/memory` and open the auto memory folder. Read `MEMORY.md` as a stranger would. Anything wrong or stale is yours to correct, since these are ordinary files.
