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:
| Context | Persist? | Why |
|---|---|---|
| Issue constraints | Yes | Future agents need scope |
| Test command chosen | Yes | Prevents repeat exploration |
| Temporary command output | Usually no | Working context only |
| User correction | Yes | Should supersede a bad assumption |
| Secrets | No | Do 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:
- Did the important fact appear in a transcript turn?
- Did
ae syncimport that turn? - Did the memory library scope match the MCP config?
- 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.
What should you read next?
Read Add persistent memory to Claude Code, Give your coding agent memory, and the Memory Failure-Mode Catalog.