Skip to main content

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 filesAuto memory
Written byYou and your teamThe agent, based on your corrections
StoredIn the repository (and ~/.claude)Per project in ~/.claude/projects/<project>/memory/
SharedVia gitPersonal
Best forRules and conventionsLearned 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

  1. Run /memory and look at what is loaded for your project.
  2. Work one session and correct the agent twice. Check what ended up in auto memory.
  3. Promote one useful note to CLAUDE.md and delete one outdated note.
  4. Put a monthly “memory review” reminder in your team calendar.

Walkthrough in TestRun Board

  1. Run /memory and look at what is loaded: CLAUDE.md with AGENTS.md, and the auto memory for this project.
  2. 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.”
  3. Open the auto memory through /memory and see what it stored.
  4. 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.
  5. 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.