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
branch.tswrites a correct fork JSONL with rewrittenparentUuidchainscontext.resume(sessionId, forkLog, 'fork')triggers the REPL to mountuseLogMessagesfires on first render withstartIndex=0(full array)recordTranscriptcallsgetSessionMessages→loadTranscriptFilewith the precompact-skip optimization (SKIP_PRECOMPACT_THRESHOLD)- Because the fork file is >5MB,
loadTranscriptFileonly loads post-boundary UUIDs into the dedup set - All pre-boundary messages pass the
messageSet.has(m.uuid)dedup check and get appended again — withparentUuid=nulland noforkedFromstamps
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
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗