{"slug": "what-survives-claude-code-compaction-77-of-decisions-0-2-of-commands", "title": "What survives Claude Code compaction: 77% of decisions, 0.2% of commands", "summary": "A study of 58 real Claude Code transcripts and 43 compaction events found that summaries preserved about 77% of decision sentences but only 9.8% of file paths, 1.9% of measured numbers and 0.2% of commands actually run, compressing 2.59 GB of raw conversation into 0.72 MB of summaries. The analysis, drawn from one machine's private session logs and recorded in the deja-vu project's cmd/deja/compact.go, frames the loss as a retrieval problem rather than data loss, since the full transcript remains on disk. The project's deja tool addresses this with a pre-compaction hook that re-injects the in-flight task, passed and failed commands, touched files and a git status line into a packet bounded to 4 KB.", "body_md": "# What compaction drops, and how to get it back\n\nthe summary keeps the reasoning and drops the work\n\nA long session compacts: the harness replaces earlier turns with a summary so the window keeps fitting. The session continues, the agent sounds like it remembers, and the specific thing you will need in twenty minutes is already gone.\n\n## What survives, measured\n\nAcross 58 real transcripts and 43 compaction events taken from one machine's history, 2.59 GB of raw conversation compressed into 0.72 MB of summaries. Comparing each summary against the transcript it replaced:\n\n- **~77%** of decision sentences survived — the conclusions, the \"we went with X because Y\".\n- **9.8%** of file paths survived.\n- **1.9%** of measured numbers survived.\n- **0.2%** of the commands that had actually been run survived.\n\nThose figures come from one machine's private session logs (recorded in [cmd/deja/compact.go](https://github.com/vshulcz/deja-vu/blob/main/cmd/deja/compact.go); the raw personal transcripts are not published). The reproducible seeded retrieval and context-cost suites live under [benchmarks](benchmarks.html), and you can inspect your own logs locally with the command below.\n\nThat split is the whole problem. A summary is written in the language of intent, and the things that cost you an afternoon are not intent: the invocation with the four flags that finally worked, the error text you pasted, the exact span an edit replaced, the path of the file that turned out to matter. Ask after a compaction and you get a confident paraphrase of the plan with none of the parts you would have copied.\n\n## What compaction does not touch\n\nThe transcript. Compaction shortens what is in the model's context; it does not go back and rewrite the log the harness has been appending to since the session opened. Every command, every tool result, every edit is still on disk — see [where each agent keeps it](where-sessions-are-stored.html).\n\nSo \"lost to compaction\" is a retrieval problem, not a data-loss problem. The work is there; nothing reads it back.\n\nYou can inspect what is still in your own Claude Code logs without installing anything:\n\n```\njq -r '.message.content? | arrays[] | select(.type == \"tool_use\" and .name == \"Bash\") | .input.command // empty' ~/.claude/projects/*/*.jsonl | tail -n 20\n```\n\nWatch `cleanupPeriodDays` in `~/.claude/settings.json`: Claude Code deletes transcripts older than 30 days by default, and setting it to `0` disables saving transcripts altogether (set a large number such as `99999` to keep them). Codex keeps its logs under `~/.codex/sessions`, Cursor in `state.vscdb`, and the rest follow the paths in the [format registry](../registry/README.html).\n\n## Getting it back\n\nTwo moments matter, and they are different.\n\n### During the session\n\n`deja install --auto` wires a pre-compaction hook wherever the host exposes a compaction event (Claude Code, Codex, opencode, Cursor CLI, Copilot CLI, VS Code Copilot Chat, Qwen Code, Kimi Code, Cline CLI, Kilo CLI, TRAE CLI, pi, OpenClaw and the other hosts in the [compaction reference](https://github.com/vshulcz/deja-vu/blob/main/docs/compaction.md); Hermes through its memory provider; Gemini CLI on the next prompt). When compaction starts, deja reads the active transcript with the same parser that indexes it and captures what the summary is about to drop — no manual checkpoint needed:\n\n- The task in flight, conclusions, and open items carried from earlier turns.\n- Commands that actually ran, marked `[passed]` or`[failed]` from the harness exit status or recorded output.\n- Files touched in the session, bounded so the re-injected packet fits inside 4 KB on the next hook call.\n- A final git status line noting the branch and whether HEAD or the working tree moved since capture, so stale conclusions get re-checked.\n\n`deja stats` reports the raw tool calls before the first edit after compaction, with incomplete observations kept separate. See the [compaction reference](https://github.com/vshulcz/deja-vu/blob/main/docs/compaction.md) for capture limits and privacy controls.\n\n### Afterwards\n\nAsk for the specific thing rather than the story:\n\n```\ndeja wip                    # what the last session here was doing: task, files, last command\ndeja how \"go test\"          # the invocation this project actually uses, with its flags\ndeja fix \"pq: too many connections\"   # what was run after this error, where it stayed fixed\ndeja blame internal/index/ingest.go   # which sessions discussed this file, and what they decided\n```\n\nThose questions map onto exactly what a summary drops: the task in flight, commands, failures and file-level decisions. With recall wired in, the agent asks them itself — before it runs a command, after one fails, and when a prompt matches earlier work.\n\n## Try it on your logs\n\n```\nbrew install deja-vu\ncurl -fsSL https://raw.githubusercontent.com/vshulcz/deja-vu/main/install.sh | sh\nnpx @vshulcz/deja-vu\n```\n\nOn Windows, use `winget install vshulcz.deja-vu` or `scoop install deja-vu` (see [getting started](getting-started.html) for the zip release). Running bare `deja` builds a local index of transcripts already on disk and opens search immediately; `deja install --auto` is optional and only needed to wire MCP recall and pre-compaction hooks into your agents.\n\n## Common questions\n\n### Why index transcripts instead of running rg over JSONL?\n\nRaw logs mix prompts, nested JSON tool payloads, file dumps and ANSI escapes across different schemas per agent. On the seeded multi-session corpus (`deja bench context`), deja matches naive grep's verbatim fact coverage in roughly **250× fewer tokens** (and about 70× fewer than replaying matched sessions in full), parses structured fields like command exit status and edited lines across [52 coding agents](harnesses.html), and captures the pre-compaction packet before the window resets. See [benchmarks](benchmarks.html).\n\n### Where does lexical search lose?\n\nPure BM25 misses keyword-free paraphrases. On LongMemEval-S (470 cleaned questions, no LLM or embeddings), deja scores **88.9% hit@1** overall (97.4% hit@5), while the preference slice drops to **43.3% hit@1** (100% hit@20) — exact runs and failure modes are on [benchmarks](benchmarks.html) and [day zero](day-zero.html). If you run a local embedding endpoint such as Ollama or LM Studio, `deja embed` adds an optional vector sidecar for hybrid recall; without one, search stays strictly offline.\n\n### What about secrets in raw transcripts?\n\nIndexing and search stay local with no network path unless you enable embeddings. API keys, bearer tokens, private-key blocks and credential URLs are redacted at index time before anything is written to the index or pre-compaction packet. You can scan raw on-disk transcripts without building an index with `deja audit --secrets`, or inspect and scrub findings via `deja secrets` — details in [privacy](privacy.html) and [credentials in transcripts](credentials-in-transcripts.html).\n\n## What this does not fix\n\nCompaction is not a defect to be switched off. The window is finite, summarising is the right response, and a memory layer does not change that — it stops the summary from being the only copy. If the harness never wrote the session to disk, none of this applies, and the answer really is gone.\n\n[Why agents forget between sessions](forgetting.html) · [Where the transcripts live](where-sessions-are-stored.html) · [Getting started](getting-started.html)\n\nFound this useful? [Star deja-vu on GitHub](https://github.com/vshulcz/deja-vu).", "url": "https://wpnews.pro/news/what-survives-claude-code-compaction-77-of-decisions-0-2-of-commands", "canonical_source": "https://vshulcz.github.io/deja-vu/guide/after-compaction.html", "published_at": "2026-11-24 13:03:07+00:00", "updated_at": "2026-11-24 13:12:38.052540+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "large-language-models"], "entities": ["Claude Code", "deja", "deja-vu", "Codex", "Cursor", "GitHub Copilot", "Gemini CLI", "opencode"], "also_reported_by": [], "takeaway": "Compaction summaries retained ~77% of decisions but only 0.2% of executed commands and 9.8% of file paths, so re-inject the transcript's commands, files and git status in a packet under 4 KB before compaction runs.", "recommendation": {"advice": "Wire a pre-compaction hook that re-injects the in-flight task, passed and failed commands, touched files and a git status line in under 4 KB, since summaries keep decisions but drop 99.8% of commands.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/what-survives-claude-code-compaction-77-of-decisions-0-2-of-commands", "markdown": "https://wpnews.pro/news/what-survives-claude-code-compaction-77-of-decisions-0-2-of-commands.md", "text": "https://wpnews.pro/news/what-survives-claude-code-compaction-77-of-decisions-0-2-of-commands.txt", "jsonld": "https://wpnews.pro/news/what-survives-claude-code-compaction-77-of-decisions-0-2-of-commands.jsonld"}}