# CLAUDE.md — Persistent memory in Claude Code
> Specialized context for Claude Code. Use it to feed, review and audit a project's auto memory: the notes Claude accumulates from one session to the next, alongside CLAUDE.md.
---
## When to use this context
- ✅ After a long session: deciding what deserves to survive across sessions
- ✅ Memory that has drifted: stale notes, duplicates, an index that is too long
- ✅ Joining an existing project: understanding what is already remembered
- ✅ Torn between "put it in CLAUDE.md" and "Claude will remember it"
- ❌ Keeping the details of past sessions: `git log` is more reliable
- ❌ Enforcing a rule: neither memory nor CLAUDE.md can force anything, a hook can
---
## Section 1 : CLAUDE.md or auto memory
Every session starts with an empty context. Two mechanisms bring knowledge back into it, and they do different jobs.
| | CLAUDE.md | Auto memory |
|---|---|---|
| **Who writes it** | The human | Claude |
| **Content** | Instructions and rules | Preferences, corrections received, context the code doesn't tell |
| **Scope** | Project, user or organization | One repository, on one machine |
| **Versioned** | Yes, with the repository | No, outside the repository |
| **Loaded** | In full, every session | Only the start of the `MEMORY.md` index |
How to split things:
- "Remember that…" in conversation: Claude saves it to auto memory. To get it into CLAUDE.md, ask explicitly ("add this to CLAUDE.md").
- A lasting instruction (method, convention, prohibition) goes in a versioned file: CLAUDE.md, `.claude/rules/` or the relevant skill. Memory stays on the machine: a colleague, another workstation or a cloud session won't see it.
- A preference that applies to every project goes in `~/.claude/CLAUDE.md` or `~/.claude/rules/`. Auto memory is filed per repository.
- Both are context, not enforced configuration. Anything that must be blocked for certain goes through a `PreToolUse` hook or `permissions.deny`.
---
## Section 2 : Where memory lives and what gets loaded
```text
~/.claude/projects/<project>/memory/
├── MEMORY.md index, one line per note
├── user_role.md one note
├── feedback_testing.md one note
└── ...
```
- `<project>` is derived from the git repository: all worktrees and subfolders of the same repository share a single folder. Outside a git repository, the project root is used.
- At startup, only the first 200 lines or first 25 KB of `MEMORY.md` are loaded (whichever limit is hit first). Anything beyond is ignored: the index holds one line per note, the details go in the files.
- The note files are not loaded at startup. Claude opens them on demand: the index line is what makes it decide to read one.
- After `/compact`, auto memory is reloaded from disk, like the root CLAUDE.md.
- The main conversation's memory is not passed to subagents (except to a fork, which inherits the conversation).
- These are ordinary markdown files: you can read them, fix them, delete them.
Useful commands:
- `/memory`: lists the CLAUDE.md and memory files, opens the auto memory folder, turns auto memory on or off.
- `/context`: shows which CLAUDE.md and memory files are loaded, and what they cost.
- Disable for one project: `"autoMemoryEnabled": false` in its settings. Everywhere: the `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` environment variable.
- Change the location: the `autoMemoryDirectory` setting (absolute path, or starting with `~/`).
---
## Section 3 : The 4 types and the note format
Claude files each note under a type, written in the file header.
| Type | Content | Example |
|---|---|---|
| `user` | Role, level, way of working | "Experienced backend dev, new to React: explain the frontend by analogy with the backend" |
| `feedback` | Corrections received, approaches validated | "Integration tests against a real database, no mocks" |
| `project` | Ongoing work, deadlines, decisions that neither the code nor git shows | "Merge freeze from 2026-03-05, mobile release" |
| `reference` | Where to find information outside the project | "Pipeline bugs: INGEST project in the tracker" |
A `feedback` or `project` note carries the rule, its reason and where it applies. Without the reason, there is no way to judge later whether the rule still holds.
```markdown
---
name: integration-tests
description: Integration tests against a real PostgreSQL database, never mocks of the data layer
type: feedback
---
Tests that touch the database run against a real PostgreSQL 16 (container).
**Why:** a mock hid a broken migration, discovered in production on 2026-02-12.
**How to apply:** any test of a repository or an SQL query. Domain unit tests stay database-free. See also [[test-database]].
```
And its line in `MEMORY.md`:
```markdown
- [Integration tests](feedback_integration_tests.md) — real PostgreSQL database, no mocks of the data layer
```
Writing rules:
- **One fact per file**, named by its type: `feedback_…`, `project_…`.
- **The description decides everything**: together with the index line, it is what Claude sees before opening the note. Put in the words you will use on the day it becomes useful.
- **Absolute dates**: "yesterday", "next week", "recently" become `2026-03-04` at the time of writing. A relative date is wrong from the next session on.
- **Links between notes**: `[[name]]` pointing to the linked note's `name`, rather than copying its content. This is a convention, maintained by hand: when you delete a note, remove its index line and the links that pointed to it.
- **Update rather than create**: read the index before writing. If a note already covers the topic, extend it.
- Leave the header of an existing note as it is (its exact shape and the `modified` field, the timestamp of the last write, are managed by Claude Code).
---
## Section 4 : What goes in, what stays out
Worth remembering:
- What neither the code, nor git, nor CLAUDE.md tells
- A preference confirmed or a correction given during a session, with its reason
- An invisible constraint: a freeze, a deadline, a decision driven by something other than technology
- A pointer to an external resource consulted regularly
Leave out:
- What can be read in the repository: architecture, file paths, dependencies
- What git tells: who changed what, the fix for a bug, the history of a session
- The ephemeral: the current task, the state of a branch, the output of a command
- What CLAUDE.md already says
- Secrets: passwords, tokens, keys
- The edge case that won't happen again
The one-question test:
> "If I delete this note and Claude rereads the code and CLAUDE.md, will it be missing something in a future session?"
If not, the note is useless.
---
## Section 5 : Checking a note before trusting it
A note describes what was true on the day it was written. Before acting on what it claims:
- It names a file, a function, a command, a setting: check that it still exists (`ls`, `grep`, read the file).
- It freezes a state ("in progress", "still to do", a version, a count): check against the code, git or the tracker.
- The note and the repository contradict each other: the repository is right. Fix or delete the note right away.
- Look at its date: an old `project` note is suspect by default, a `user` or `feedback` note ages slowly.
---
## Section 6 : Audit and consolidation
Run it periodically (once a month on an active project) or when `MEMORY.md` nears its limit. Everyday use adds notes and almost never removes any: without this pass, memory only grows.
```text
Audit this project's auto memory: the project's memory/ folder
under ~/.claude/projects/ (list that folder to find the one for the current repository).
Do not modify anything before I approve.
Step 1. Read MEMORY.md and every file in the folder. For each file, check:
a. Accurate? Every file, command, setting or state it mentions is checked
against the repository (ls, grep, git log). Record the evidence.
b. Useful? Not deducible from the code, git or CLAUDE.md.
c. Well typed? user / feedback / project / reference.
d. Findable? The description is enough to decide whether to open the note without reading the body.
e. Dated? No relative dates; feedback and project notes have their reason (Why)
and where they apply (How to apply).
Step 2. Check the whole:
- duplicates (same knowledge, different words) and contradictions between notes;
- files missing from MEMORY.md, index lines without a file;
- [[name]] links without a target note;
- size of MEMORY.md (wc -l, wc -c) against the 200 lines / 25 KB limit;
- lasting instructions that should live in a versioned file
(CLAUDE.md, .claude/rules/, skill).
Step 3. Return a single table, one row per file, omitting none:
| File | Verdict | Evidence | Proposed action |
Verdict, one value among: keep, update, merge, delete, move.
- update: quote the sentence to change;
- merge: source -> target, and what survives;
- delete: the evidence is a command or a file, never an impression;
- move: the versioned destination file.
End with: N files read, N rows in the table (the two numbers are equal).
Step 4. Only after my approval:
- back up the memory/ folder;
- apply the approved actions; any deletion or merge also removes
the index line and the links that pointed to the note;
- recheck and display: number of files = number of index lines,
no link without a target, MEMORY.md under both limits.
```
The audit is done when the step 4 recheck passes with no exceptions.
### Turn it into an /audit-memory command
`/audit-memory` doesn't exist in Claude Code: it's a skill you create yourself. Save the prompt above in `~/.claude/skills/audit-memory/SKILL.md` (all projects) or `.claude/skills/audit-memory/SKILL.md` (one project, versioned), preceded by this header:
```markdown
---
name: audit-memory
description: Audits the project's auto memory (stale notes, duplicates, index) and proposes a table of actions to approve
disable-model-invocation: true
---
```
The folder name becomes the command. `disable-model-invocation: true` reserves triggering for the human, since the skill deletes files. The old `.claude/commands/audit-memory.md` format still works.
For instruction files (CLAUDE.md, rules, skills), Claude Code ships its own audit: `/doctor prompt-audit`. It does not replace this one.
---
## Section 7 : Saving before /clear or /compact
A `/clear` starts from an empty context, a compaction summarizes and loses detail. Auto memory only keeps what Claude finds useful at the time. To decide yourself what must survive, use a four-step routine: scan, deduplicate, write, verify.
Two rules govern everything else.
**1. Not deducible.** Write only what a future session couldn't find in the repository, in git or in CLAUDE.md: a decision and its reason, a trap discovered, a correction received, an external pointer. The test: "could a future session deduce it from the repository?" If yes, don't write it.
**2. The mechanism, not the snapshot.** A piece of work produces a state (where we are) and knowledge (what we understood). The state rots within weeks, the knowledge doesn't. Write only the latter, and this applies to the note's `description` too, which decides whether it gets recalled.
```text
✗ "The migration branch is pushed, the review isn't done" → false in ten days
✓ "Every migration first runs against a copy of the test database" → true as long as the rule is
```
When the insight is about work in progress, keep what will outlive it: the decision and its why, the trade-off settled, the trap met. Never the branch number or its status.
```text
Before I clear the context, save what this conversation has learned
that is not deducible from the repository, git and CLAUDE.md.
1. Scan: reread the conversation, especially the corrections I gave you
(they are often the best feedback notes). Convert relative dates
to absolute dates.
2. Deduplicate: read MEMORY.md. If a note already covers the topic, update it
instead of creating one. Also look for contradictions: before writing
a fact, grep its keyword across the whole memory/ folder.
3. Write: one fact per file, at most 3 writes (an update counts
as one write, and comes before any creation). No activity summary,
no plan, no todo, no dated state.
4. Verify: every path, symbol or command cited exists (ls, grep);
every note has name, description and type; the name is the file name
without its type prefix, with `_` replaced by `-` (feedback_integration_tests.md
gives integration-tests); MEMORY.md has one line per note, whose hook
(the text after the dash) is 100 characters at most.
"Nothing to save" is a normal outcome: say so in one line and
write no file. Do not run /clear yourself, I decide.
```
Why so few writes: memory never prunes itself, and every extra note degrades the recall of all the others. The index is loaded every session; the body of the notes only on demand, so volume belongs in the body, not in the index line.
As with `/audit-memory`, this prompt becomes a skill: `~/.claude/skills/save-context/SKILL.md`, with `disable-model-invocation: true` so that only the human triggers it. Run it before a `/clear`, or before a `/compact` you want to control.
---
## Section 8 : Checklist
```text
□ Auto memory on (/memory), project folder located
□ MEMORY.md: one line per note, under 200 lines and 25 KB
□ Each note: a single fact, a type, a description good enough to find it
□ feedback and project notes: reason and where it applies written down
□ No relative dates, no secrets
□ Nothing that can already be read in the repository, git or CLAUDE.md
□ Lasting instructions copied into a versioned file
□ /audit-memory created, date of the next audit set
□ Save routine before /clear in place: 3 writes at most, "nothing to save" accepted
```
---
*Last updated: 2026-11 — Context for the article [Persistent memory in Claude Code](https://www.web-developpeur.com/blog/memoire-auto-claude-code).*