You have been in a long Claude Code session. The context meter creeps up, auto-compact fires, or you run /compact yourself. The next reply is confident and slightly wrong. It repeats a mistake you already corrected. It proposes a dependency you already rejected. It talks about "the plan" without following the plan.
This is not a mysterious bug. Compaction is lossy on purpose. The useful question is what still exists after it runs, and how to put the work somewhere compaction cannot eat.
What /compact actually does
Claude Code's context window holds the session: your instructions, files it read, its replies, and some tool output you never see in the terminal. When that window fills, Claude Code summarizes the conversation so the session can continue. Official documentation describes this the same way whether it was automatic or you typed /compact.
A summary is not a transcript. It keeps what the summarizer thinks matters, usually the recent work, and drops or flattens the rest. People who have checked this in their own sessions report a consistent pattern: the latest stretch is mostly still there; older decisions are the ones that disappear. One widely discussed case: after many compactions in a single session, a later summary had kept none of a dozen older decisions, including a product-positioning line, a backend cleanup call, and a bug they had already tracked down. Treat that as a cautionary measurement, not a universal statistic — your summaries will differ — but the shape of the failure is real.
Official docs are blunt about the same class of problem: if an instruction seemed to vanish after /compact, it was probably given only in conversation, lives in a nested CLAUDE.md that has not reloaded yet, or is a path-scoped rule that has not matched a file since. Conversation-only commitments are the first thing to write down.
What official docs say survives
As of the current Claude Code documentation on the context window and memory, this is what is re-injected or reloaded after compaction. Check the docs if your version is older; skill re-injection, for example, needs a recent Claude Code release.
| Still there after compact | Gone or only if the summary kept it |
|---|---|
| System prompt and output style | Anything you only said in chat |
| Project-root CLAUDE.md and unscoped rules, re-read from disk | Nested CLAUDE.md files until they are reloaded on demand |
| Auto memory, re-injected from disk | Path-scoped rules until they match a file again |
| Skill descriptions, rebuilt from current skills (recent versions) | Context a hook added earlier, which is summarized with the chat |
| The plan Claude wrote in plan mode, re-injected from disk | A PLAN.md or notes file nobody told it to re-read |
| Up to five files Claude already read or edited, most recently modified first | The rest of the files it "already understood" |
| Invoked skill bodies, with a token cap; oldest dropped first | Older decisions after a summary of a summary |
SessionStart hooks whose matcher includes compact, plus their output | The assumption that "it will remember the plan" |
Two important nuances. First, plan mode's own plan file is re-injected; a markdown plan you have been using as a working document is not, unless something re-reads it. That is why people report "Claude does not review your active plan after compaction" even when they religiously keep a PLAN.md. Second, root CLAUDE.md comes back; an instruction you only typed into the chat does not, unless you add it to that file.
Do this in the next five minutes
- Do not keep arguing with the compacted session about what it "should remember." Write the missing decisions down first, while you still have them.
- Create or update three short files in the repo, each with one job:
CLAUDE.md— standing rules. Keep it short. How to build, what not to touch, a pointer to the other two files.DECISIONS.md— append-only. Each entry is the date, the decision, why, and what you already ruled out.NOTES.md— current state only. What is done, what is open, the next step. Rewrite it; do not let it grow into a novel.
- Tell Claude, in this session: "Re-read CLAUDE.md, DECISIONS.md and NOTES.md before you continue. Then do only the next step in NOTES.md."
- Add a SessionStart hook so you are not depending on it remembering to re-read. Compaction fires SessionStart with source
compact, and the hook's stdout is added to the compacted context. A typical shape:
{
"SessionStart": [
{
"matcher": "compact",
"hooks": [
{
"type": "command",
"command": "printf '\n# Repo state after compact\n' && (test -f DECISIONS.md && cat DECISIONS.md) && (test -f NOTES.md && cat NOTES.md)"
}
]
}
]
} Put that in your Claude Code hooks settings, and confirm the paths match your repo. You can also match startup and clear if you want the same brief on a fresh session. Official docs call out this exact hook source; a number of practitioners have landed on it independently after losing a plan mid-refactor.
Control when and what gets compacted: /context, /rewind, /autocompact
The files and the hook decide what comes back after a compaction. Claude Code also has a few built-in controls for when the summary happens and what it focuses on. All of these are in the official commands, checkpointing and hooks docs.
- See what is filling the window.
/contextshows current context usage as a colored grid, with suggestions for context-heavy tools and memory files. Check it before you decide whether to compact, clear or keep going. - Compact with a focus. Run something like
/compact focus on the auth bug fixbefore the automatic pass guesses what matters. That helps the current task. It will not reliably keep a decision from ten compactions ago. Those belong in DECISIONS.md. - Summarize only part of the session. Run
/rewind(or press Esc twice with an empty prompt), pick a message, and choose Summarize from here or Summarize up to here. Highlight the option with the arrow keys and type what the summary should keep into the add context (optional) row. It does not change files on disk, and the original messages stay in the session transcript. It works like a targeted/compact: summarize a noisy debugging stretch and keep the messages where you set the plan word for word. - Move the auto-compact point.
/autocompact 500ksets how full the context window gets before Claude Code compacts on its own, and/autocompact autogoes back to the default for your model. With no argument it opens a dialog that shows the current setting. It needs Claude Code v2.1.221 or later and accepts 100K tokens or more, capped at the model's context window. Claude Code saves the value to your user settings (from v2.1.288, per model) and applies it to the current session. For one launch only, useclaude --autocompact 500k. TheCLAUDE_CODE_AUTO_COMPACT_WINDOWenvironment variable overrides both. - Tell the summary what to keep, every time. A
PreCompacthook runs before each compaction (matchermanualfor/compact,autofor automatic compaction). If it exits 0, Claude Code uses its stdout as instructions for the compaction summary, up to 10,000 characters. For example, print "Keep the current step from NOTES.md and every rejected approach from DECISIONS.md". Exiting with code 2 blocks the compaction instead, which is rarely what you want mid-task.
Be clear about what these do. They change when the summary is written and what it focuses on. A later auto-compact point means a later summary, not no summary, and a bigger window holds more noise as well as more plan. The plan still needs to live on disk, which is what the SessionStart hook above re-reads.
Claude Code's built-in task list is a separate question from the plan: see which AI agent task lists survive compaction for how it compares with Codex and Cursor, and a 2-minute test.
A hook is not a task list
The file-and-hook pattern above is useful and free. It also has limits, and they are worth stating plainly.
- A hook that
cats two files will dump those files into context every compact. If the files get long, you are back to crowding the window. - Nothing in that setup tracks dependencies between tasks, or which task is actually in progress, unless you maintain that by hand in NOTES.md.
- The same files are not automatically available if you switch from Claude Code to Cursor, Codex, or another MCP client, unless you keep using them as plain files and remember to point the new tool at them.
- A stale line in DECISIONS.md is worse than a missing one, because the agent will follow it with confidence. Date the entries and prune what is no longer true.
This is the gap a dedicated task store is for. The six ways a context window forgets is the broader picture; compaction is only one of them. Crashes, /clear, model switches, and coming back tomorrow are the others. If you also work in Cursor, the same idea applies to a new Cursor chat that forgot your earlier requests. If you switch between Claude Code, Cursor and Codex on one repo, see how to add memory to Claude Code, Cursor and Codex.
Where Todo-MCP fits, honestly
Todo-MCP is a local MCP server. Your tasks, dependencies and session context live in a SQLite file on your machine. It is a paid download, and the files stay yours. To see plans, leave your email in the form on this page first; it sends the Claude Code setup tutorial and then shows the options. After a compact, a crash, or a new session, the usual start is context_resume, which returns the current task, elapsed time, stored context keys and a recommendation for what to do next.
What it does not do: it does not hook itself into Claude Code's compact cycle automatically. If nobody calls the tools, the store sits there unused. The reliable setup is:
- Install Todo-MCP in Claude Code as a local stdio MCP server (the Claude Code setup guide walks through this).
- Start sessions, and resumes after compact, with
context_resume. - Optionally add a compact hook or a short CLAUDE.md line that says: after any compaction, call
context_resumebefore continuing. - Keep CLAUDE.md for standing rules. Let the task list hold the plan, and the context keys hold the decisions you would otherwise lose to a summary.
If you already use a compact reminder or a plan-revisor, those can sit beside a task store rather than replace it. We wrote about that pairing in How to use ToDo-MCP with Post-Compact Reminder. Use the reminder to force the re-read; use the task list as the thing that is re-read.
When to start a new session instead
If the conversation has mixed two or three tasks, or you have already compacted many times, a fresh session plus a file (or context_resume) is often cheaper than another summary of a summary. Write NOTES.md or update the current task, run /clear or start a new session, and have the new session read the store before it touches code.
Your plan does not have to live inside the context window. The window will compact again. The work you care about should already be somewhere else.