fix(coding-agents): drop Claude Code's compaction summary from retained turns (#3379) - #3383
Merged
Merged
Conversation
…ed turns Found investigating #3379, which asked for a PreCompact hook to avoid losing context at compaction. The premise does not hold — compaction APPENDS a summary record and leaves every earlier record in the transcript (verified on a real 11,144-record session compacted twice: 3,312 records precede the first marker and are still there), and Stop fires after every assistant response, so the content was already retained before compaction ran. The investigation turned up the opposite problem. That summary record is a plain type:"user" line with no isMeta flag, so nothing filtered it and Claude Code's machine-written recap was retained as something the user said: 29 records / 474,016 chars across local transcripts, averaging 16KB each. Worse than misattribution, it summarises turns ALREADY retained, so the same decisions get extracted a second time from the recap. Dropped alongside isMeta and isSidechain. Verified against the session that surfaced it: 2886 -> 2884 turns, exactly the two summaries gone, every other turn byte-identical. Also corrects retain-cursor.ts, which cited Claude Code compaction as an example of a transcript being rewritten rather than extended. It is not: the prefix stays intact, so the append path keeps working through a compaction. The guard is unchanged — only the example it named was wrong.
This was referenced Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Came out of investigating #3379, which asked for a
PreCompacthook so context isn't lost when Claude Code compacts. The premise doesn't hold, and the investigation found the opposite problem.Compaction appends; it doesn't rewrite
On a real session (11,144 records, compacted twice):
The transcript JSONL is append-only. Compaction shrinks the agent's context window and appends an
isCompactSummaryrecord; nothing is removed from the file we read. AndStopfires after every assistant response, not at session end, so everything up to the last response was already retained before compaction ran. There is no window where content lives only in the agent's context.What is actually wrong: we retain too much
That summary record is
type: "user"with noisMetaflag, so nothing filtered it and Claude Code's machine-written recap was retained as something the user said:Across local transcripts: 29 records, 474,016 characters, ~16KB each. Same class as the
<task-notification>fix in #3378, but roughly 30x larger per instance — and worse than misattribution, it is a summary of turns already retained, so the same decisions get extracted a second time from the recap.Dropped alongside
isMetaandisSidechain.Verification
Against the session that surfaced it, baseline built from v0.2.0:
(My first run of this compared against a stale bundle and showed 168 turns removed — worth mentioning because it is exactly the kind of false verification that reads as success. Rebuilding the baseline from current main gave the exact figure above.)
Also corrected
retain-cursor.tscited Claude Code compaction as an example of a transcript being rewritten rather than extended. It isn't — the prefix stays intact, so the append path keeps working straight through a compaction. The guard is unchanged; only the example it named was wrong.Test
434 passed, 19 skipped.
tsc --noEmitand lint clean. One new regression: a compaction summary followed by a real user turn retains only the user's turn.