Race condition corrupts .claude.json when using Agent Teams on Windows

Resolved 💬 3 comments Opened Feb 26, 2026 by prokesmartin Closed Feb 27, 2026

Description

When using Agent Teams (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1) on Windows, the shared .claude.json configuration file gets repeatedly corrupted due to concurrent writes from multiple teammate processes.

Environment

  • Claude Code version: 2.1.59
  • OS: Windows 11 Pro 10.0.26200
  • Shell: Git Bash
  • Node.js: v24.13.0
  • Settings: bypassPermissions mode, custom statusline (PowerShell), agent teams enabled

Symptoms

  1. Repeated .claude.json corruption — "JSON Parse error: Unexpected EOF" errors appearing continuously during agent team sessions
  2. UI garbling — Terminal output becomes garbled (truncated words, overlapping lines, broken ANSI escape sequences)
  3. Session instability — Configuration is repeatedly destroyed and recreated, losing OAuth data, onboarding flags, project settings, etc.

Evidence

During a single ~11 minute session (20:34–20:45), 21 corrupted backups were generated:

-rw-r--r-- 20862 Feb 26 20:34 .claude.json.corrupted.1772134453024
-rw-r--r-- 20862 Feb 26 20:34 .claude.json.corrupted.1772134453096  (same second!)
-rw-r--r-- 20862 Feb 26 20:34 .claude.json.corrupted.1772134455181
-rw-r--r--   469 Feb 26 20:37 .claude.json.corrupted.1772134668847
-rw-r--r--    77 Feb 26 20:42 .claude.json.corrupted.1772134943307
-rw-r--r--   157 Feb 26 20:42 .claude.json.corrupted.1772134943339
...21 files total

Key observations:

  • Different userID hashes in each corrupted file — confirms multiple processes writing simultaneously
  • Wildly varying file sizes (77B to 20KB) — classic sign of truncated writes / race condition
  • Two corruptions in the same second (timestamps ending ...453024 and ...453096) — concurrent write collision
  • Corrupted files contain valid JSON prefixes that are simply truncated mid-write (Unexpected EOF)

Root Cause Analysis

Each agent teammate spawned by the team system runs as a separate process. All processes share and write to the same ~/.claude.json file. On Windows (NTFS), there is no atomic write guarantee for this pattern, so:

  1. Process A reads .claude.json, modifies in memory, starts writing
  2. Process B reads .claude.json (possibly stale), modifies, starts writing
  3. One write truncates the other → corrupted JSON → "Unexpected EOF"

The corruption cascade then triggers error handling that interrupts normal terminal rendering, causing the garbled UI output.

Expected Behavior

Agent team sessions should not corrupt the shared configuration file. Possible mitigations:

  • File locking (advisory or mandatory) around .claude.json writes
  • Per-process/per-agent state files instead of shared single file
  • Atomic write pattern (write to temp file, then rename — works atomically on most filesystems)
  • Retry with backoff on write conflicts

Reproduction Steps

  1. On Windows 11, enable CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 in settings.json env
  2. Set bypassPermissions mode
  3. Start a Claude Code session and invoke /devteam or use TeamCreate with 3+ teammates
  4. Have teammates perform concurrent tool operations (builds, tests, file edits)
  5. Observe .claude.json corruption errors and UI garbling within minutes

Workaround

Restore from the most recent valid backup in ~/.claude/backups/ and limit concurrent teammates to reduce collision frequency. Disabling the custom statusline also helps reduce UI garbling symptoms.

View original on GitHub ↗

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