How to give Claude Code memory between sessions
CLAUDE.md is for rules, not for progress. Split agent memory into rules, work state and decisions, and every new session picks up in two calls.

The usual way this goes wrong is quiet.
Week one, you add a memory bank: activeContext.md, progress.md, a /memorize command that updates them at the end of each session. It works beautifully. Week three, activeContext.md is 600 lines long and still opens with "Currently migrating the session store to Redis". You dropped Redis on day nine and the decision lives in a chat that has since scrolled away. A fresh session reads the file, sees an unfinished migration, and helpfully finishes it.
The model did what the memory told it. The memory was wrong because it mixed three things that age at different speeds.
Why does Claude Code forget everything between sessions?
Because it never remembered anything. Each session is a new context window. Anthropic's docs say so directly: every Claude Code session "begins with a fresh context window", and two mechanisms carry knowledge across (memory docs):
CLAUDE.mdfiles, which you write. They load in full at the start of every session. Claude Code can also read a repository'sAGENTS.md.- Auto memory, which Claude writes itself: a
MEMORY.mdindex plus topic files. Only the first 200 lines or 25 KB ofMEMORY.mdload at startup, and auto memory is machine-local. It isn't shared across machines or cloud environments.
Everything else, the chat, the todo list, the reasoning behind your last three choices, is gone when the session ends or gets compacted. Codex, Gemini CLI and Cursor work the same way with their own instruction files.
So "memory" is a writing problem. What you write, where, and who keeps it current.
What should go in CLAUDE.md, and what shouldn't?
CLAUDE.md is the employee handbook. It should be true next month.
Good content: how to run, test and deploy; conventions you'd reject a PR for; where things live; which commands are dangerous; where tasks are tracked. Anthropic recommends keeping each file under 200 lines, because longer files cost context and reduce adherence. Imports organize a long file but don't make it cheaper, since imported files load with it.
Bad content: "currently working on", "next steps", "last session we", lists of open bugs, anything with a date in it. It is stale by tomorrow and, worse, it looks authoritative because it sits in the file the agent trusts most.
A quick test for every line: would this still be correct if nobody touched the repo for a month? If not, it doesn't belong in CLAUDE.md.
The three layers of agent memory

Layer 1: rules
Stable, short, version-controlled. CLAUDE.md / AGENTS.md, plus path-scoped rules for parts of the codebase. Changes a few times a month, usually by a human or after a human says "remember this".
Layer 2: work state
The thing every memory bank tries to be and fails at, because it's global. Work state belongs to a task, not to the project. For every task in progress, keep one to three lines:
State: endpoint and CSV writer done, tests green locally.
Next: pagination for >10k rows, then docs. Blocked on nothing.
Overwrite it, don't append. History is somewhere else; state is now. When a session picks up the task, these lines are the first thing it reads, and when it stops, the last thing it writes. If you only adopt one habit from this article, make it this one.
Layer 3: decisions
Short, append-only, findable. One line of what, one line of why, a date and a link to where it happened:
2026-11-03 · Decision: no Redis for sessions. Postgres table + 15-min cache is enough
at our load; one less service to run. (APP-18)
Decisions are what new sessions get wrong most often, because the code shows what exists, never what was rejected. A session that can't find "we decided against Redis" will propose Redis, with good arguments, every week.
What should a new session do first?
Make the start a ritual, and keep it cheap:
- Read the rules (automatic:
CLAUDE.mdloads by itself). - Find out what changed and what's waiting: answers to your questions, work returned to you, your queue.
- Read the state and decisions of the one task you're picking up. Not the whole project.
And make the end a ritual too: update the state lines, record any decision, link the commit. The handoff note is written for a reader with no memory at all, which is exactly what the next session is.
Put both rituals in CLAUDE.md. That's a rule, so it belongs there.
Can I do this with files in the repo?
Yes, for one person and one machine. A docs/decisions.md log and a tasks/ folder with one Markdown file per task, each with a State: line at the top, gets you all three layers. Claude Code's own Tasks feature can also persist a task list across sessions if you set CLAUDE_CODE_TASK_LIST_ID to a repo-specific value.
Files get awkward when more than one session or person is involved. Two sessions overwrite each other's state lines. Nobody notices a decision added on a branch that hasn't merged. Your phone can't read tasks/APP-18.md. And auto memory, being machine-local, is invisible to the Codex session on your other laptop.
How does Rappy give agents memory between sessions?
Each layer is a field or a call, and the session-start ritual is two calls.
Rules live in the product's knowledge base. An agent writes them with write_doc (how to run, test, deploy, conventions), and pinned docs ship with product_context, together with the team, the epics and the owner's approval guide. Your CLAUDE.md shrinks to the handbook plus a pointer:
## Task tracking: Rappy
This repository is product `APP` in Rappy (MCP server `rappy`).
- Session start: `whats_next`; first time this session: `product_context product=APP`.
- Picking up a task: read its state and decisions in `get_task` before touching code.
- Stopping: `update_task state="where it stands / what's next"`. Decisions: `comment kind=decision`.
- Mention task keys in commits (`APP-42: …`).
Work state is the state field on every task, 1 to 3 lines, overwritten as work moves:
update_task key=APP-18 state="CSV writer done, tests green. Next: pagination >10k rows." progress=60 remaining="40m"
→ OK: APP-18 [in_progress] Export to CSV · @claude · AC 2/4 · 60% ~40m left
Decisions are comments with a kind, so they can be found later without reading the whole discussion:
comment key=APP-18 kind=decision body="No Redis for sessions: Postgres + 15-min cache is enough at our load."
The next morning, a brand new session on a different machine runs whats_next. The output is short text, not a JSON dump:
You are @claude (agent).
## Updates for you (2)
- [answered] APP-18 by @anna: Keep the old /export URL working? — Yes, redirect
- [rejected] APP-21 by @anna: Returned: header overlaps on mobile (screenshot attached)
## Your active tasks (2: in_progress 2)
- APP-18 [in_progress] Export to CSV · @claude · AC 2/4 · 60% ~40m left
- APP-21 [in_progress] Mobile header · @claude · AC 3/3 · rework×1 (changed)
An answer it didn't have yesterday, a returned task with a screenshot, and both tasks it owns. One get_task key=APP-18 later it has the exact line where it stopped and the Redis decision. If it has been away longer, changes_since returns only what moved since a cursor, which is the cheap way to catch up after a weekend. Every commit, branch and PR linked to a task stays on it, and the full history is recorded, so "why is this here?" has an answer.

How do I stop memory files from rotting?
Whatever tool you use:
- One owner per layer. Humans own rules. The session doing the work owns that task's state. Anyone can add a decision, nobody edits old ones.
- Overwrite state, append decisions. If your state section has more than three lines, it's turning into a diary.
- Date everything that isn't a rule. Undated notes are read as current forever.
- Delete aggressively from
CLAUDE.md. If a line hasn't changed agent behaviour in a month, it's costing context for nothing. Anthropic's 200-line guidance is a ceiling, not a target. - Keep memory next to the work. A decision about the export lives on the export task. A global memory file is where context goes to get lost.
FAQ
Is Claude Code auto memory enough on its own?
For personal preferences, often yes: it learns your corrections and loads the first 200 lines of its index every session. It isn't a project log. It's machine-local, nobody reviews it, and it can't tell a teammate or a second session what happened.
Should I use CLAUDE.md or AGENTS.md?
Use AGENTS.md if more than one agent vendor works on the repo, since Codex, Cursor and others read it, and Claude Code can read it in place of CLAUDE.md. The content rules are the same: short, stable, exact commands.
What's a memory bank, and should I use one?
A community pattern: a folder of Markdown files (brief, active context, progress) that the agent reads at start and updates at the end. It's a reasonable start for solo work. Keep the "active context" part per task and short, or it turns into the 600-line file from the top of this article.
How do I give memory to several agents at once?
Put state and decisions somewhere all of them read and write through the same interface, not in each machine's memory. That's also what makes running agents in parallel manageable: the claim, the state and the decision are visible to every session.

