Skip to content

fix(claude-code): segment retains from PreCompact#2355

Open
Sanderhoff-alt wants to merge 1 commit into
vectorize-io:mainfrom
Sanderhoff-alt:fix/claude-code-precompact-retain
Open

fix(claude-code): segment retains from PreCompact#2355
Sanderhoff-alt wants to merge 1 commit into
vectorize-io:mainfrom
Sanderhoff-alt:fix/claude-code-precompact-retain

Conversation

@Sanderhoff-alt

@Sanderhoff-alt Sanderhoff-alt commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Why

The Claude Code integration retains from the on-disk transcript JSONL file provided by the hook input as transcript_path. On current Claude Code builds we verified, that file is append-only across compaction: compact does not truncate the file or delete old transcript entries. Instead, Claude Code appends compact metadata, a compact summary, retained tail entries, and later conversation turns to the same JSONL transcript.

The previous full-session retain logic inferred compaction from a transcript size decrease. That does not match the observed Claude Code transcript behavior, so it is not a reliable way to segment retained documents. With an append-only transcript, shrink-based detection never represents the real compact boundary and can leave pre- and post-compact material mixed under the same document lifecycle.

This change wires the Claude Code PreCompact hook into the integration. Before Claude Code compacts, the hook forces one retain of the current pre-compact transcript. If that retain succeeds, it records the current transcript message count as a checkpoint. The next full-session retain reads the same append-only transcript and writes only the appended compact summary, retained tail, and new turns to a fresh session_id-cN document, preserving the pre-compact document instead of overwriting it.

The checkpoint is only marked after the retain API call succeeds. If the daemon, API URL resolution, or retain request fails, the hook does not advance the boundary. The next normal retain will continue using the original session document and full transcript, which may cost more extraction work but avoids dropping the pre-compact window.

Chunked retain mode continues to use its existing timestamped document behavior and does not create full-session compact checkpoints.

What changed

  • Added a PreCompact hook registration and script for the Claude Code plugin.
  • Replaced shrink-based compaction inference with explicit PreCompact checkpoints.
  • Made full-session retain segment post-compact content into session_id-cN documents after a checkpoint.
  • Made run_retain return a success flag so PreCompact can avoid marking failed retains.
  • Updated tests around append-only compact behavior, checkpoint failure, chunked mode, and state tracking.

Claude Code transcripts are append-only across compaction. Add the
PreCompact hook so full-session retain writes the pre-compact transcript
before recording a boundary for the next compact segment.

Remove shrink-based compaction detection from retention state. The next
full-session retain now writes appended compact summary, retained tail,
and new turns into a session_id-cN document after the checkpoint.

Make run_retain return a success flag and only mark the PreCompact
checkpoint after the retain API call succeeds. This avoids losing the
pre-compact window when the daemon or retain request fails.
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