[BUG] Session Race Condition: 888 Duplicate Transcripts in 7 Days (2189 files, 57MB)

Open 💬 0 comments Opened Jul 15, 2026 by berilsanda

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Claude Code is creating hundreds of duplicate session transcript files due to a race condition in session file creation. A single 7-day work period resulted in 2,189 session files (57MB) when only 9 real sessions were performed—an overhead of 98.9% phantom files.

Evidence

Scale of the Problem:

  • Total files: 2,189
  • Real sessions (7 days): 9
  • Phantom sessions: 879 (98.9%)
  • Storage waste: ~54 MB
  • Sessions created today alone: 436

Burst Pattern (6/29 08:52 UTC):
30 duplicate sessions created in 8 minutes, each 2-5 seconds apart—inconsistent with user interaction.

Duplicate File Proof:

Two files created 8 seconds apart with identical content:

06945173-bb73-48ef-9ff5-be3b9f2cdb6c.jsonl  (2026-06-29T08:52:20.734Z)
0edbc443-1e88-4096-8d31-7dded75b2e5a.jsonl  (2026-06-29T08:52:28.182Z)

Both reference the same session:

  • session_id: ddb3a036-a17b-47b8-aba5-83751f28dd77
  • Session name: "Fix yarn code-quality errors on root"
  • Same model, cost, timestamps, context usage
  • Only the file UUID differs

Related Symptom:

  • 86 orphaned, empty directories in ~/.claude/session-env/ (never cleaned up)
  • Stale temp file: ~/.claude.json.tmp (failed atomic write)

Expected vs Actual

| Aspect | Expected | Actual |
|--------|----------|--------|
| Files per session | 1 | 100+ |
| Sessions/day | ~1-2 | 436 |
| Transcript size | < 10MB | 57MB |
| History accuracy | 9 sessions | 900+ reported in /usage |

Environment

  • Claude Code: 2.1.195
  • OS: macOS (Darwin 25.5.0)
  • Shell: zsh
  • Project: Yarn 4 + Turborepo monorepo
  • Settings: Default (autoCompactEnabled: true)

Root Cause Analysis

Race condition likely in:

  1. Concurrent session ID creation: Multiple operations assign new IDs instead of routing to current session
  2. File write synchronization: No proper file locking; stale .tmp files indicate failed atomic writes
  3. Queue processing: queue-operation log entries suggest concurrent enqueue/dequeue without mutual exclusion
  4. Session routing: Internal operations (tool calls, events) each spawn a new transcript file instead of appending to current session

Workaround

# Backup first
cp -r ~/.claude/projects/-Users-username-Documents-work-monorepo-project{,.backup}

# Remove oldest duplicates (keep last 50 to be safe)
ls -1t ~/.claude/projects/-Users-username-Documents-work-monorepo-project/*.jsonl | \
  tail -n +51 | xargs rm -f

### What Should Happen?

In a 7-day period, this resulted in **888 phantom sessions** from only **9 real user sessions**, consuming **57MB of storage** with **24,839 transcript lines** that should have been consolidated into 9 files.

### Error Messages/Logs

```shell

Steps to Reproduce

  1. Install Claude Code 2.1.195
  2. Open a large monorepo project (Yarn/Turborepo)
  3. Perform normal work for 1+ hour (file edits, tool calls, queries)
  4. Check session file count:

``bash
ls -1 ~/.claude/projects/-Users-username-*/\*.jsonl | wc -l
``

  1. Actual: Count is 50-100x higher than real sessions performed
  2. Expected: One transcript file per session

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.195 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗