Race condition corrupts .claude.json when using Agent Teams on Windows
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:
bypassPermissionsmode, custom statusline (PowerShell), agent teams enabled
Symptoms
- Repeated
.claude.jsoncorruption — "JSON Parse error: Unexpected EOF" errors appearing continuously during agent team sessions - UI garbling — Terminal output becomes garbled (truncated words, overlapping lines, broken ANSI escape sequences)
- 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
userIDhashes 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:
- Process A reads
.claude.json, modifies in memory, starts writing - Process B reads
.claude.json(possibly stale), modifies, starts writing - 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.jsonwrites - 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
- On Windows 11, enable
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1in settings.json env - Set
bypassPermissionsmode - Start a Claude Code session and invoke
/devteamor useTeamCreatewith 3+ teammates - Have teammates perform concurrent tool operations (builds, tests, file edits)
- Observe
.claude.jsoncorruption 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗