Persistent Memory
Why This Matters
Every session starts fresh. Without memory you re-explain the same decisions; with too much memory the agent drags along outdated notes that quietly steer it wrong. Good memory is small, current and reviewable.
Two kinds of memory
Claude Code has two complementary memory systems, both loaded at the start of a session:
| CLAUDE.md files | Auto memory | |
|---|---|---|
| Written by | You and your team | The agent, based on your corrections |
| Stored | In the repository (and ~/.claude) | Per project in ~/.claude/projects/<project>/memory/ |
| Shared | Via git | Personal |
| Best for | Rules and conventions | Learned preferences and project facts |
Use /memory in a session to see which files are loaded, open them in your editor and switch auto memory on or off. You can also ask directly: “Remember that API tests need the mock server running.”
What to store, and what not
Store:
- decisions that are not visible in the code (“we use the URL for filter state, so links are shareable”);
- facts that cost time to rediscover (how to start the mock server, which test is known-flaky and why);
- your preferences for how the agent works with you.
Do not store:
- anything that is already in the code or CLAUDE.md;
- temporary state (“currently working on ticket 42”);
- secrets, tokens, customer data or personal data;
- guesses the agent made that nobody verified.
Memory that helps without building up noise
- Review it monthly. Open the memory files with
/memory, delete what is outdated, move what the team needs into CLAUDE.md. - Promote, then delete. When a note in auto memory turns out to be a team rule, move it into the repository and remove it from memory.
- Keep it short. Memory is loaded into every session; a long, stale memory costs tokens and causes wrong assumptions.
- Subagents can have their own memory. Useful for a reviewer that learns your team’s recurring findings, as long as you review it too.
Hands-on
- Run
/memoryand look at what is loaded for your project. - Work one session and correct the agent twice. Check what ended up in auto memory.
- Promote one useful note to CLAUDE.md and delete one outdated note.
- Put a monthly “memory review” reminder in your team calendar.
Walkthrough in TestRun Board
- Run
/memoryand look at what is loaded: CLAUDE.md with AGENTS.md, and the auto memory for this project. - Work on a small change and correct the agent twice with project facts, for example “The mock API is MSW in tests/mocks/handlers.ts, not a JSON server” and “Fixtures live in tests/mocks/data.ts.”
- Open the auto memory through
/memoryand see what it stored. - Decide per note: the fixture location is a team fact and is already in
.claude/rules/testing.md, so the memory note can go. A personal preference (“answer in short bullet points”) can stay in memory or move to~/.claude/CLAUDE.md. - Check that nothing sensitive was stored (tokens, URLs with credentials, customer data).
Key Takeaways
- CLAUDE.md is the team’s memory; auto memory is the agent’s personal notes.
- Store decisions and hard-won facts, never secrets or temporary state.
- Review and prune memory regularly; promote team knowledge into the repository.