CLI /branch duplicates all pre-compaction-boundary messages in fork JSONL

Resolved 💬 3 comments Opened Apr 16, 2026 by ojura Closed Apr 16, 2026

Description

When using /branch on a session that has been compacted, the fork JSONL ends up with duplicate entries for all messages before the last compaction boundary. Observed fork with ~2x expected line count and ~50% duplicate UUIDs.

Root cause chain

  1. branch.ts writes a correct fork JSONL with rewritten parentUuid chains
  2. context.resume(sessionId, forkLog, 'fork') triggers the REPL to mount
  3. useLogMessages fires on first render with startIndex=0 (full array)
  4. recordTranscript calls getSessionMessagesloadTranscriptFile with the precompact-skip optimization (SKIP_PRECOMPACT_THRESHOLD)
  5. Because the fork file is >5MB, loadTranscriptFile only loads post-boundary UUIDs into the dedup set
  6. All pre-boundary messages pass the messageSet.has(m.uuid) dedup check and get appended again — with parentUuid=null and no forkedFrom stamps

Reproduction

/branch any session with at least one compaction boundary and >5MB file size.

Observed

Fork JSONL has ~2x the expected line count; ~50% duplicate UUIDs. The duplicates have parentUuid=null and lack forkedFrom stamps, unlike the originals written by branch.ts.

Workaround

export CLAUDE_CODE_DISABLE_PRECOMPACT_SKIP=1

For VSCode/Cursor, add to claudeCode.environmentVariables:

[{"name": "CLAUDE_CODE_DISABLE_PRECOMPACT_SKIP", "value": "1"}]

Version

Claude Code 2.1.109

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗