How to keep context between Claude Code sessions
Five mechanisms, what each is actually for, and the commands.
Claude Code starts every session with an empty context window. The previous conversation is on disk, but nothing loads it for you. There are five separate mechanisms for carrying work forward, and most of the frustration people have comes from using one where another was meant to go. Here is each one and what it is genuinely for.
If you want the general version of this that is not specific to Claude Code, start with why coding agents forget between sessions.
1. Resume the conversation
claude --continue # most recent session here
claude --resume # pick from a listThis restores the actual conversation, which nothing else on this page does. Use it whenever you are continuing the same piece of work on the same machine.
It will not help you on a different computer, in a different editor, or six weeks later when you have forgotten which of forty sessions was the right one. A session long enough to be worth resuming is also long enough that resuming it can immediately trigger compaction.
2. CLAUDE.md
Loaded automatically at the start of every session. Two places:
./CLAUDE.md # this project
~/.claude/CLAUDE.md # all of your projectsRight things to put in it: how the project is laid out, how to run the tests and the linter, conventions to follow, things that must never be touched, which commands you want used instead of the obvious ones.
Wrong thing to put in it: current state. Nothing updates this file for you, so "we are midway through the auth refactor" is true for about a day and then quietly misleads every future session. A stale instruction file is worse than no file, because the agent trusts it completely.
3. /compact, which is not what people think
/compact summarizes the conversation so a long session can continue past a full context window. It is a within-session tool. It does not save anything for tomorrow, and reaching for it when the real problem is cross-session state is the single most common mix-up.
The useful habit it implies: if a decision matters, have it written to a file when it is made. Anything living only in the conversation is at the mercy of the next compaction.
4. A SessionStart hook
Hooks let Claude Code run your own command at defined moments. A SessionStart hook runs as a session begins and its output is injected into the context before your first message. Configure it in ~/.claude/settings.json or the project's .claude/settings.json:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{ "type": "command", "command": "cat HANDOFF.md" }
]
}
]
}
}That example is deliberately trivial, and it is already most of the value. Swap cat HANDOFF.md for a script that also prints recent commits, your open tickets, or which branch is in flight, and every session starts briefed with nothing for you to remember.
This is the step that fixes the discipline problem. Options 2 and 3 fail in practice not because they do not work but because updating them competes with finishing the work. Automating the read is what makes the habit survive.
5. An MCP memory server
When state needs to cross a boundary a file cannot, it has to live somewhere both sides can reach. MCP is the interface Claude Code shares with Codex, Cursor, Copilot and Devin, so a memory server is reachable from all of them and from any machine.
Local knowledge graph
Free, self-contained, no account
The official reference memory server keeps a knowledge graph on your own disk. Good when you want persistence without a service, and you do not need another machine to see it.
A hosted board
For many projects across machines and editors
State lives on a server, so a session on your laptop sees what the desktop did. Astryke Hub is ours: it keeps a board per project, the agent reads a brief at the start and writes progress at the end, and connecting is a config entry plus a browser sign-in. Setup is in the Claude Code docs.
The tradeoff, stated plainly: it is a service to trust and, for hosted ones, a bill. If one project on one machine is your whole situation, steps 2 and 4 above are a better answer and cost nothing.
What most people should actually do
- Write a
CLAUDE.md. Twenty minutes, fixes the most common complaints immediately. - Keep a
HANDOFF.mdwith what is in flight, and tell CLAUDE.md to read and update it. - Add the
SessionStarthook above so the read happens whether or not you remember. - Only if you have outgrown one repo or one machine, move state to MCP.
Common questions
How do I make Claude Code remember the previous session?
Run claude --continue to pick up the most recent session in that directory, or claude --resume to choose from a list. This restores the real conversation rather than a summary. It only works on the machine that holds the transcript, so it is the right tool for continuing today's work and the wrong one for carrying state across machines.
What is CLAUDE.md and where does it go?
CLAUDE.md is a file Claude Code loads automatically at the start of every session. Put one at the root of a project for project-specific facts, and one at ~/.claude/CLAUDE.md for things that apply to all of your work. It is for stable instructions such as how to run the tests or which conventions to follow, not for current state, because nothing updates it for you.
Does /compact save my session for next time?
No. /compact summarizes the conversation so the current session can keep going once context fills up. It is a within-session tool. When you close the session the summary goes with it, unless you resumed that specific session next time.
How do I make Claude Code load my project state automatically?
Use a SessionStart hook. It runs a command when a session begins and injects the output into the context before you type anything. Point it at a script that prints your handoff notes, recent commits, or open work, and every session starts briefed without you having to remember to paste anything.
Should I use CLAUDE.md or an MCP memory server?
Use CLAUDE.md for facts that are true regardless of what you did yesterday, and it should exist either way. Reach for an MCP memory server when state has to cross a boundary a file cannot: several projects at once, a second machine, a second editor, or wanting the agent to record progress without being asked each time.
Does CLAUDE.md work in Codex or Cursor?
No. Each client reads its own file. Codex reads AGENTS.md, Copilot reads .github/copilot-instructions.md, and Cursor reads .cursor/rules. If you move between editors, keep the durable content in a neutral file such as HANDOFF.md and have each client's instruction file point at it, or put state behind MCP, which all of them speak.
Why does Claude Code seem to forget mid-session?
That is compaction rather than forgetting. When the context window fills, older conversation is replaced by a summary and specific details can be dropped. Writing important decisions to a file as you go, rather than leaving them in the conversation, is what makes them survive both compaction and the end of the session.
Last updated 2026-09-14.