C² Method7 min read

How to stop Claude Code losing context between sessions

Every session starts with a fresh window and compaction rewrites the old one. What Claude Code keeps for you, and the routine that keeps the rest.

Stuart Leo

You finish a good session in Claude Code. The agent found the bug, worked out why, and left a fix half-done. Tomorrow you open a new session and it knows none of it. Or worse, it happens mid-session: the context fills, the conversation compacts, and the decision you made an hour ago is now one line in a summary, or gone.

This is the most searched frustration with Claude Code, and it isn't a bug. It's how the tool is built. Once you know exactly what Claude Code keeps and what it drops, the fix is a routine, not a product.

Why does Claude Code lose context between sessions?

There are two separate losses, and they need separate answers.

A session ends. The Claude Code memory docs say it plainly: each Claude Code session begins with a fresh context window. The conversation, the files it read, the reasoning it built up — none of it carries over by itself.

A session compacts. Within a session, the window is finite. As you approach the limit, Claude Code compacts automatically, and running /compact does the same thing on demand. Per the context window docs, compaction replaces the conversation with a structured summary. The summary keeps what the automatic pass judges important. Your judgement and its judgement are not always the same.

So the work drains away twice. All at once when you close the session. In pieces whenever it compacts.

What does Claude Code remember natively?

More than it used to. Two mechanisms carry knowledge across sessions, and both are worth using.

CLAUDE.md. Instructions you write. The project file at ./CLAUDE.md is loaded in full at the start of every session, and after compaction the project-root CLAUDE.md is re-read from disk and re-injected. Claude Code can also read an AGENTS.md in its place. Anything in this file survives both kinds of loss.

Auto memory. Notes Claude writes itself, on by default in local sessions. They live at ~/.claude/projects/<project>/memory/, with a MEMORY.md index of one line per memory. The first 200 lines or 25KB of that index, whichever comes first, load at the start of every conversation, and auto memory is also re-injected after compaction.

The docs also list what compaction does not re-inject. Instructions given only in conversation. Context that hooks added earlier, which gets summarised with everything else. Nested CLAUDE.md files and path-scoped rules, which reload only when Claude next touches a matching file.

Why isn't CLAUDE.md and auto memory enough for a real project?

Because neither one holds the state of the work.

CLAUDE.md holds rules — how the project is built, what never to do. It is the wrong place for "the cancellation flow is half-built and the refund test fails". Put that in CLAUDE.md and the file becomes a diary that loads into every session forever.

Auto memory holds learnings and preferences, written by Claude, and the docs are clear that it is machine-local. It isn't in git. Your collaborator can't read it. A second machine doesn't have it. And Claude decides what goes in it.

What a project needs at the start of a session is different. What changed last time. Why. What was actually verified, and what wasn't. What to do next. That is a hand-off, and it has no native home. So I give it one, in git.

The C² routine: four habits that stop the loss

The C² Method is the build method I run every project with. The part that answers this problem is four habits.

  1. Read the latest session brief before you start. Not the whole history. The last one or two.
  2. Write a session brief before you stop. Also before a meeting, before /clear, and before a long session compacts. The trigger isn't "is the work finished?" It's "if I came back to this cold, what would I need to know?"
  3. Put decisions and gotchas in their own files. A brief is dated and gets buried. A gotcha — a non-obvious trap — goes in docs/03-knowledge/gotchas/ so it's found by topic, not by date.
  4. Let a hook point the agent at the briefs. Don't rely on remembering to say "read the last brief". Make the session start with the list in front of it.

All four are plain files, committed with the code. Nothing to install.

In my own monorepo this has been running long enough to have weight. The 2026 folder at docs/02-working/sessions/completed/2026/ holds over 1,100 brief files. docs/03-knowledge/gotchas/ holds more than 210 gotchas. Two of the titles, to show the grain: Two module names that differ only in case collide on a Mac, and A concurrent session can move the shared working tree out from under you. Each one is a trap an agent would otherwise walk into cold, again.

How do I make Claude Code read my session briefs automatically?

With a SessionStart hook. Per the hooks reference, a SessionStart hook runs when a session begins or resumes, with the source available as startup, resume, clear or compact, and Claude Code adds its plain-text stdout as context Claude can see before your first prompt. The context window docs add that SessionStart hooks matching the compact source run again after compaction and their output goes into the compacted context.

Mine lives at .claude/hooks/session-context.sh and is registered in .claude/settings.json. Here is the registration, trimmed to the one hook:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          { "type": "command", "command": ".claude/hooks/session-context.sh", "timeout": 10 }
        ]
      }
    ]
  }
}

The real script is longer because my file names drifted over the years and it parses four date formats. Stripped to the idea, for briefs named YYYY-MM-DD-topic.md:

#!/bin/bash
# .claude/hooks/session-context.sh — list recent session briefs at session start
PROJECT_DIR=$(cat | jq -r '.cwd // empty')
BRIEFS="$PROJECT_DIR/docs/02-working/session-briefs"

echo "=== Recent session briefs (last 30 days) ==="
find "$BRIEFS" -maxdepth 1 -type f -name "*.md" -mtime -30 -exec basename {} \; \
  | sort -r | head -15
echo ""
echo "Briefs get parked. Ask which one to pick up, don't assume the latest."

Two details are deliberate.

It lists, it doesn't dump. Fifteen file names cost almost nothing in context. Fifteen full briefs would fill the window the hook is meant to protect. The agent opens the one that matters.

It says briefs get parked. The newest brief is not always the priority. Work pauses, another stream jumps ahead. My hook ends by telling the agent to ask, and that one line has saved more wrong starts than anything else in the script.

The hook has also failed me, and the failure is worth knowing. The comment at the top of my script records it. The hook once matched only names ending -session-brief.md. When brief names dropped that suffix, the hook went blind, and every session booted showing an 18 August brief as the newest. Nothing errored. If you change how briefs are named, check the hook still sees them.

What goes in a session brief?

Keep it short enough that writing it is never the reason you skip it. This is the skeleton I'd copy, cut down from the template in the C² starter kit:

# Session brief: [area], YYYY-MM-DD

## Goal
One sentence. What this session set out to do.

## What changed
- [file or feature]: [what was done]

## Decisions
- [decision]: [why this, not the alternative]

## Verified
- [what was tested, and how]
- NOT verified: [what still needs checking]

## Key discovery
[A gotcha worth keeping, or "None this session".
If there is one, write docs/03-knowledge/gotchas/<name>.md in the same commit.]

## Next session starts here
Start with: [file, task or command]
First action: [one specific instruction]

The section that earns its keep is NOT verified. A brief that only lists successes tells the next session everything works. Say what you didn't check, and the next session doesn't build on it blind.

Save it as docs/02-working/session-briefs/YYYY-MM-DD-topic.md, the location the C² starter uses, and commit it with the work. My monorepo predates that layout and files briefs under docs/02-working/sessions/completed/ by year. The folder matters less than keeping one and pointing the hook at it.

For a fuller walk-through with an annotated example, see write your first session brief or the session brief template.

How do I keep compaction from losing context mid-session?

The routine covers the gap between sessions. Within a session, three moves keep compaction from costing you.

Write before it compacts. When a session is getting long, have Claude write the brief first. The brief is on disk. The summary is a guess.

Compact with a focus. The context window docs suggest /compact focus on the auth bug fix before a long new task, so the summary keeps what you choose rather than what the automatic pass guesses.

Clear between unrelated tasks. /clear is for switching to different work. Write the brief, clear, and let the SessionStart hook start the next task clean.

Anything that must survive both — a rule, a constraint, a standing decision — belongs in the project-root CLAUDE.md or a file it points to. That file is the one thing the docs say compaction re-reads from disk. The longer argument about window hygiene is in compaction: keeping the context window lean.

The cost is five minutes a session

None of this needs Claude Code to change. CLAUDE.md carries the rules. Auto memory carries Claude's own notes. A brief in git carries the state of the work, and a hook makes sure it gets read.

Five minutes at the end. A list of file names at the start. That is the whole price, and it's paid back the first morning the agent opens a session already knowing where it stopped.

The model doesn't remember the project. The repository does, if you write it down.

Start here: run your first C² session, read how to stop your agent forgetting, or see what a contextbase is.

Questions people ask

Does Claude Code remember previous sessions?
Not the conversation. Each Claude Code session begins with a fresh context window. Two things carry across: CLAUDE.md files you write, and auto memory notes Claude writes itself. Neither records the state of the work, so what was half-done, verified or decided needs to go in a file the next session reads.
Why did Claude Code lose context after compaction?
Compaction replaces the conversation with a summary. The project-root CLAUDE.md and auto memory are re-read from disk, but anything you only said in conversation survives only as well as the summary kept it. If an instruction or decision must survive, write it to a file rather than relying on the chat.
What is the difference between CLAUDE.md and auto memory in Claude Code?
You write CLAUDE.md: instructions and rules, loaded in full every session and usually committed to git. Claude writes auto memory: learnings and preferences, stored per repository on your machine, with the first 200 lines or 25KB of its MEMORY.md index loaded each session. Auto memory is machine-local and not shared.
How do I make Claude Code read my notes at the start of every session?
Use a SessionStart hook. Plain-text output from a SessionStart hook is added to Claude's context before your first prompt. A short script that lists the most recent session briefs is enough to point each new session at where the last one stopped.
Should I use /clear or /compact?
Use /compact to shrink a long session that is still on the same task, ideally with a focus instruction. Use /clear when you switch to unrelated work. Either way, write a session brief first if the session learned anything the next one will need.

Part of the C² Method. Start with the method

Put this in your repo

The C² Method is free and open. Point your agent at the kit and get started in minutes.