claude-code - 💡(How to fix) Fix [BUG] VSCode reopen appends duplicate entries to session JSONL, corrupting /insights analysis [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56196Fetched 2026-05-06 06:34:37
View on GitHub
Comments
2
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×3commented ×2

When VSCode is closed and reopened with an active Claude Code session, entries from that session are re-appended to the JSONL log file. Each replayed entry is byte-for-byte identical to the original (same uuid, same timestamp, same content) with only minor context fields differing (e.g. cwd).

Root Cause

When VSCode is closed and reopened with an active Claude Code session, entries from that session are re-appended to the JSONL log file. Each replayed entry is byte-for-byte identical to the original (same uuid, same timestamp, same content) with only minor context fields differing (e.g. cwd).

Code Example

// line 528
{"uuid":"01cd4a53-9d16-4fc8-860d-b9b46b1abce4","timestamp":"2026-04-23T07:25:36.857Z","cwd":"/path/to/project/subdir","sessionId":"110e2e95-...","type":"assistant",...}

// line 1172 — identical entry, replayed on VSCode reopen
{"uuid":"01cd4a53-9d16-4fc8-860d-b9b46b1abce4","timestamp":"2026-04-23T07:25:36.857Z","cwd":"/path/to/project","sessionId":"110e2e95-...","type":"assistant",...}

---

entries = [...new Map(entries.map(e => [e.uuid ?? Math.random(), e])).values()];
RAW_BUFFERClick to expand / collapse

Description

When VSCode is closed and reopened with an active Claude Code session, entries from that session are re-appended to the JSONL log file. Each replayed entry is byte-for-byte identical to the original (same uuid, same timestamp, same content) with only minor context fields differing (e.g. cwd).

Minimal example — same UUID at two different line offsets in the same file

// line 528
{"uuid":"01cd4a53-9d16-4fc8-860d-b9b46b1abce4","timestamp":"2026-04-23T07:25:36.857Z","cwd":"/path/to/project/subdir","sessionId":"110e2e95-...","type":"assistant",...}

// line 1172 — identical entry, replayed on VSCode reopen
{"uuid":"01cd4a53-9d16-4fc8-860d-b9b46b1abce4","timestamp":"2026-04-23T07:25:36.857Z","cwd":"/path/to/project","sessionId":"110e2e95-...","type":"assistant",...}

A single affected session can have hundreds of duplicate UUID pairs.

Impact on /insights

The duplicated entries cause /insights to see phantom session segments — it reported 13 analyzed sessions against an actual count of ~30–50. The duplicate segments appear as empty or compaction-only sessions, and friction analysis was skewed as a result (flagged "excessive context compaction loops" as the primary friction pattern — this was an artifact of the phantom sessions, not real behavior).

Suggested fix

Deduplicate entries by uuid on read before any processing. The uuid field is stable across replays and is present on all substantive entry types. One-liner in the session parser:

entries = [...new Map(entries.map(e => [e.uuid ?? Math.random(), e])).values()];

To reproduce

  1. Open a session in the VSCode extension with active conversation history
  2. Close VSCode without ending the session
  3. Reopen VSCode
  4. Inspect the session JSONL in ~/.claude/projects/ — entries from before the close will appear duplicated

Environment

macOS, Claude Code VSCode extension

extent analysis

TL;DR

Deduplicate entries by uuid in the session parser to prevent duplicate session segments.

Guidance

  • Verify the issue by following the provided reproduction steps and inspecting the session JSONL file for duplicate entries.
  • Apply the suggested fix by adding the one-liner entries = [...new Map(entries.map(e => [e.uuid ?? Math.random(), e])).values()]; to the session parser.
  • Test the fix by reopening VSCode with an active session and checking the session JSONL file for duplicates.
  • Monitor the /insights endpoint to ensure that phantom session segments are no longer reported.

Example

The provided one-liner code snippet can be used to deduplicate entries: entries = [...new Map(entries.map(e => [e.uuid ?? Math.random(), e])).values()];

Notes

This fix assumes that the uuid field is stable across replays and is present on all substantive entry types. If this is not the case, an alternative deduplication strategy may be needed.

Recommendation

Apply the workaround by adding the suggested one-liner to the session parser, as it directly addresses the issue of duplicate session segments caused by replayed entries.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING