Claude Code

Claude Code lost context after /compact? What survives, and what doesn't

You were an hour into a bug. You ruled out the cache, found the real cause, agreed on a workaround. Then Claude Code compacted the conversation, and now it suggests the approach you dropped an hour ago.

That is how compaction works, not a fault: the history becomes a summary, and details you found along the way are only as good as that summary. This page lists what Claude Code keeps, taken from its documentation, and four ways to keep the rest.

What survives compaction

When the context window fills up, or when you run /compact, Claude Code summarizes the conversation. Some things are loaded again from disk afterwards. The documentation lists each kind of content:

WhatAfter compaction
Project-root CLAUDE.md and unscoped rulesRe-injected from disk
Auto memoryRe-injected from disk
The plan Claude wrote in plan modeRe-injected from disk
Rules with paths: frontmatter, nested CLAUDE.mdReloaded on demand
Files Claude read or editedRe-reads up to five, most recently modified first
Context that hooks added earlierSummarized with the rest of the conversation
SessionStart hooks that match the compact sourceRun again, output added to the compacted context

Shortened from What survives compaction in the Claude Code docs, as of 5 November 2026.

What only gets summarized

Everything that existed only in the conversation goes into the summary. When coding, that is often the part you worked hardest for:

  • the root cause you found after an hour of logs,
  • the approaches you tried and ruled out,
  • a workaround you agreed on, and why,
  • context a hook added earlier in the session. The docs list it as "summarized with the rest of the conversation".

The summary keeps what the model thinks matters. When it guesses wrong, the ruled-out path comes back. People describe this in the issue tracker, for example in anthropics/claude-code #17428.

Four ways to keep it

  1. Compact with a focus. Run /compact with instructions before the automatic pass does it for you, for example /compact focus on the auth bug fix. The summary keeps what you name.
  2. Move it into CLAUDE.md. The project-root CLAUDE.md is read again from disk after compaction. The docs advise to add conversation-only instructions there, and to keep each file under 200 lines: longer files cost context and reduce adherence.
  3. Re-inject with a SessionStart hook. A SessionStart hook with the matcher compact runs right after compaction, and its output goes into the new context:
    .claude/settings.json
    {
      "hooks": {
        "SessionStart": [
          {
            "matcher": "compact",
            "hooks": [
              { "type": "command", "command": "cat .claude/after-compact.md" }
            ]
          }
        ]
      }
    }
  4. Let auto memory take notes. Claude writes notes for itself as it works, and they are re-injected after compaction. The index loads its first 200 lines or 25 KB, and the notes stay on one machine.

Instructions versus experience

The four ways work well for instructions: a rule, a convention, the plan for today. They fit less well for experience, the many specific things you learned: why the deploy fails on a full disk, which flag breaks the build, the migration that must run first.

Experience grows by the week. In CLAUDE.md it soon passes 200 lines, and most of it does not matter for the prompt you are typing now. What helps is to look up the matching notes for each prompt. A UserPromptSubmit hook does that. It runs again on the first prompt after compaction, so the note is back exactly when you need it. Our guide has a working one that reads a notes file, and Lessons learned for coding agents shows what to write down.

With cachly

cachly keeps that experience outside the conversation, so compaction cannot summarize it away:

  • When a turn ends with a fix, cachly's Stop hook records it as a lesson: the cause, what failed, the command that worked.
  • Before each prompt, the hook adds up to three matching lessons. The first prompt after /compact gets them like any other.
  • Lessons live in your instance, not on one machine. They work in Claude Code, Cursor, Copilot and other editors, and for your whole team.
Claude Code
/plugin marketplace add cachly-dev/cachly-mcp
/plugin install cachly-brain@cachly

Then turn on auto-update once: /plugin → Marketplaces → cachly → Enable auto-update. Claude Code leaves it off for marketplaces outside Anthropic's own, and the hooks update only with the plugin.

Lessons are stored on servers in the EU. What leaves your machine, and where it goes.

Sources

More: Auf Deutsch lesen: Claude Code vergisst den Kontext · Claude Code hooks · Agent keeps making the same mistake · AI memory in three layers · All docs