C39 Updated 2026-06-20
Pillar 4 - Troubleshooting

Claude Code Loses Context After Compaction: How to Persist It

Claude Code compaction helps a session continue, but durable project memory needs transcript sync, MCP retrieval, and source-linked writes.

Claude Code can lose useful detail after compaction because compaction is not a durable memory write path. Persist important context by saving source-linked memories through MCP and syncing transcript turns with ae sync run --source claude-code, then verify recall in a fresh session.

Last updated: June 20, 2026.

What does compaction solve?

Compaction helps an active conversation continue when the thread gets long. Claude Code’s memory docs describe memory files for project and user context, and the Claude Code docs include broader MCP setup for external tools (Claude Code MCP docs). Those are useful, but compaction remains a session-continuity tool.

The problem is durable recall. A summary can preserve enough for the next prompt while losing exact source, rationale, and deletion handles.

What should become durable memory?

Save context that a future coding agent needs:

ContextPersist?Why
Issue constraintsYesFuture agents need scope
Test command chosenYesPrevents repeat exploration
Temporary command outputUsually noWorking context only
User correctionYesShould supersede a bad assumption
SecretsNoDo not store sensitive data in shared memory

The launch CLI surface documents ae sync for Claude Code transcripts. The local implementation uses packages/cli/src/sync/sources/claude-code.ts and stable source identifiers, so retries can upsert instead of duplicating transcript turns.

How do you persist Claude Code context?

Use both explicit memory and transcript sync:

ae auth login
ae sync once --source claude-code --library personal-memory
ae sync run --source claude-code --library personal-memory --poll-interval 15

Then register MCP:

{
  "mcpServers": {
    "answer-engine": {
      "command": "npx",
      "args": ["answer-engine-mcp"],
      "env": {
        "ANSWER_ENGINE_API_KEY": "ae_live_your_key_here",
        "ANSWER_ENGINE_API_URL": "https://engine.answeragent.ai",
        "ANSWER_ENGINE_LIBRARY": "personal-memory"
      }
    }
  }
}

The MCP introduction explains why this server can be reused outside Claude Code.

How do you debug a missed memory after compaction?

Ask four questions:

  1. Did the important fact appear in a transcript turn?
  2. Did ae sync import that turn?
  3. Did the memory library scope match the MCP config?
  4. Did Claude Code call the memory server before answering?

If the fact was never imported, run sync once and inspect status. If it was imported but not retrieved, inspect search terms and library scope. If it was retrieved but ignored, adjust instructions so Claude uses cited memory.

Why not put everything in CLAUDE.md?

Because CLAUDE.md is static boot context. It is useful for stable instructions, but it becomes stale and bloated if every decision lands there. Read CLAUDE.md is not memory for the full boundary.

What should you put in CLAUDE.md after adding memory?

Keep CLAUDE.md focused on startup instructions: where to find memory, which library to use, what must never be stored, and how to verify source-backed recall. It should point Claude Code toward the memory system, not become the memory system.

For example, CLAUDE.md can say: “Use Answer Engine memory for durable project facts and cite retrieved sources before relying on prior decisions.” That is stable guidance. The individual decisions belong in memory with source lineage and lifecycle state.

What does a good post-compaction check look like?

After compaction, ask one retrieval question that should only be answerable from durable memory:

Use Answer Engine memory to find the current test command for this repo. Cite the source before using it.

If Claude Code answers correctly with a cited memory, the write path and retrieval path survived the session boundary. If it answers from the compacted summary without a source, the context was summarized but not persisted.

Keep that check small. A single known memory is enough to prove the path works; a broad “summarize everything you remember” prompt makes failures harder to isolate.

Read Add persistent memory to Claude Code, Give your coding agent memory, and the Memory Failure-Mode Catalog.

Sources

Fig. 9 FAQPage schema / visible answers
FIG. 9

FAQ

Why does Claude Code lose context after compaction?

Compaction summarizes the active thread, but it does not automatically turn every important decision into durable, shared, source-linked memory.

How do I persist important Claude Code context?

Use Answer Engine MCP memory for explicit writes and `ae sync run --source claude-code` to import transcript turns into a scoped library.

Should I put everything in CLAUDE.md?

No. Keep CLAUDE.md small for stable instructions and store changing project decisions in memory with source lineage.

How do I verify the fix?

Open a fresh Claude Code session and ask it to retrieve a known prior decision through Answer Engine memory.

NEXT

Build memory you can inspect.

Answer Engine gives agents a persistent, tenant-isolated memory layer via MCP, with source-aware recall and roadmap-labeled inspection work.