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.
---
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.
A path-scoped rule disappears after a long session was compacted. Why?
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.
$ /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.
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.
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.
Where does auto memory live, and who else sees it?
Chapter complete
You've finished chapter 3 of 6 in Context and memory.
Compaction swaps your history for a summary, then restores a few things by rule. Knowing which ones lets you steer it, and choose between /clear, /compact and rewind.
Next chapter