Skip to content

fix(coding-agents): drop Claude Code's compaction summary from retained turns (#3379) - #3383

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/coding-agents-compact-summary-3379
Aug 11, 2026
Merged

fix(coding-agents): drop Claude Code's compaction summary from retained turns (#3379)#3383
nicoloboschi merged 1 commit into
mainfrom
fix/coding-agents-compact-summary-3379

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Came out of investigating #3379, which asked for a PreCompact hook 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):

compact-summary records at line(s): [3312, 6630]
records before the first marker: 3,312   <- still on disk
records after: 7,831

The transcript JSONL is append-only. Compaction shrinks the agent's context window and appends an isCompactSummary record; nothing is removed from the file we read. And Stop fires 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 no isMeta flag, so nothing filtered it and Claude Code's machine-written recap was retained as something the user said:

retained turns: 2,886
turns that are the compaction summary: 2   (53,643 chars)
  role=user chars=21,483 :: "This session is being continued from a previous conversation…"
  role=user chars=32,160 :: "This session is being continued from a previous conversation…"

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 isMeta and isSidechain.

Verification

Against the session that surfaced it, baseline built from v0.2.0:

before (v0.2.0): 2886 turns, 2 summaries (53,643 chars)
after:           2884 turns, 0 summaries
turns removed: 2 | expected: 2
every other turn identical: true

(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.ts cited 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 --noEmit and lint clean. One new regression: a compaction summary followed by a real user turn retains only the user's turn.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant