Why Claude Code forgets after compaction

Claude Code's compaction keeps your requests and key code but can drop early instructions. What survives, what doesn't, and how to keep the rest.

On this page

Claude Code forgets after compaction because compaction replaces the conversation with a summary, and the summary is lossy. In the docs’ own words, it “keeps your requests and key code snippets, but detailed instructions from early in the conversation may be lost”. Your project’s root CLAUDE.md is read again from disk afterwards. Anything you only said in the chat is not. The fix is to put what must survive into files before compaction happens, not to hope the summary keeps it.

This is as of November 2026, from Claude Code’s documentation, linked throughout. Claude Code memory: what it keeps, and where maps everything Claude Code remembers, and every guide on it.

After compaction
Your requests, key code snippets Kept, in the summary
Detailed instructions from early in the chat May be lost
CLAUDE.md at the project root Re-read from disk and put back
CLAUDE.md in a subfolder, rules scoped to a path Loaded again only when a matching file is touched
A rule you gave only in conversation Gone unless the summary kept it
Files on disk: plans, notes, memory Untouched, if the agent reads them again

What compaction does

Every session has a context window. As it fills, Claude Code “compacts the conversation into a summary” and carries on with the summary in place of the history. It happens on its own when the conversation reaches the auto-compact window, or when you run /compact.

A summary of a long session can’t hold everything. It favours what you asked for and the code that mattered. The details that go first are the ones that were said once, early, and not repeated: “don’t touch the migration files”, “we tried the cache and it made things worse”, “use the staging key for this”.

That is why it feels like forgetting. The agent doesn’t lose the task. It loses the conditions you put on it.

Does CLAUDE.md reload after compaction?

The root one does. The memory docs say: “Project-root CLAUDE.md survives compaction: after /compact, Claude re-reads it from disk and re-injects it into the session.”

Two kinds of instruction don’t come straight back. A CLAUDE.md in a subfolder and rules scoped to a path “load again on demand”, so they return when the agent next works on a matching file, not before. And an instruction given only in conversation has nothing to be reloaded from.

People have reported the opposite: that rules from CLAUDE.md were ignored after compaction (one issue, another, both closed). The docs’ own explanation covers most of those cases: the rule lived in a nested file, a path-scoped rule, or the chat. If a rule matters everywhere, it belongs in the root file.

Before compaction: four things to do

  1. Move chat-only rules into CLAUDE.md. If you corrected the agent twice on the same point, write the point down. The docs give the same advice: “Add conversation-only instructions to CLAUDE.md to make them persist.”
  2. Write the state of the task to a file. What’s done, what’s next, what was tried and failed, in a plan or notes file in the repo. The summary may shorten it. The file won’t change.
  3. Compact on purpose, with a focus. Don’t wait for it to happen mid-thought. Run /compact at a natural stopping point and say what to keep: /compact focus on the API changes.
  4. Start fresh between tasks. /clear when you switch to unrelated work. A session that never fills never compacts.

Tell the summary what to keep

You can steer the summary itself, in three ways.

  • A section in CLAUDE.md. Add a “Compact Instructions” section saying what a summary must preserve. The costs page shows one: “When you are using compact, please focus on test output and code changes”.
  • A focus on the command. Whatever you type after /compact is passed to the summary as instructions.
  • A PreCompact hook. It runs before every compaction, manual or automatic, and its output “becomes instructions for the compaction summary”. Use it to list what must be kept in every project, with no one having to remember.

You can also change when it happens. The auto-compact window is set with /autocompact, the autoCompactWindow setting or the CLAUDE_CODE_AUTO_COMPACT_WINDOW variable (model configuration). A smaller window compacts sooner and more often. It doesn’t make a summary keep more.

Keep what matters outside the conversation

Everything above is one idea: the conversation is temporary, so what has to last can’t live only there. Rules go in CLAUDE.md. The state of a task goes in a file. That works with nothing installed.

What’s left is what the agent learned along the way: why a choice was made, the cause of a bug that took an hour to find, a fact about the codebase. Those are worth more than one session, and a summary is the wrong place for them too.

This is the part Memorinth handles. Agents save what they learn as Markdown notes in your cortex while they work, so it’s on disk before any compaction. Two hooks do the rest:

  • A reminder to save. When a turn ends after three or more file edits and nothing was saved to memory, the agent is asked whether the work produced something a later session would need.
  • The briefing comes back. Claude Code runs session-start hooks again after compaction, and Memorinth’s is registered for every kind of start. So the briefing of current decisions, facts and recent memories is put back into the context right after the summary replaces the history.

It doesn’t stop compaction or make the summary better. It makes the summary matter less, because the things you’d miss were never only in the conversation.

To set it up, see Give Claude Code a long-term memory. How agents use it explains the briefing and when agents save, and Memory what a saved note looks like.

All posts