[BUG] Concurrent writes to .claude.json by parallel workers + MCP truncate the file mid-JSON, triggering cascading agent spawn

Open 💬 4 comments Opened Jun 2, 2026 by aiken884

[BUG] Concurrent writes to .claude.json by parallel workers + MCP truncate the file mid-JSON, triggering cascading agent spawn

Background

Split-out from master ticket (54891). This issue isolates the concurrent-write race on shared config files failure mode, with .claude.json as the concrete case.

Distinct from sibling splits 01 / 02 / 03 / 04: the corruption surface is concurrency (no atomic write lock), not byte-level write semantics on a single writer. The same pattern likely affects other shared config files (settings.json, MCP server registries, etc.) but .claude.json is the observed instance.

Suspected root cause: writes to .claude.json are not serialized via file lock or atomic rename (write to tmp + os.replace / MoveFileEx). When 4 parallel Cowork workers + 1 Chrome MCP session + 1 dispatcher all attempt to update the file in the same window, two of them interleave at the byte level and the file ends mid-JSON. Once the file is invalid JSON, downstream agent boot retries fail, and the retry loop spawns cascading agent processes that consume memory and CPU.

Reproducer

Environment: Windows 11 + Cowork desktop app + 4 parallel general-purpose subagents + 1 Chrome MCP session + 1 dispatcher subagent, all active simultaneously.

  1. Open Cowork desktop app.
  2. From dispatcher, spawn 4 parallel general-purpose subagents that each perform tasks involving MCP server registration or session state writes (any action that updates .claude.json).
  3. Simultaneously open a Chrome MCP session.
  4. Within 5–10 minutes, observe:
  • .claude.json becomes invalid JSON (truncated mid-object, or two writes interleaved).
  • Cowork app retries agent boot; each retry spawns new agent processes without cleaning up failed ones.
  • System Task Manager shows 20+ orphan claude-code / sandbox-helper processes accumulating.
  1. Confirm via:

``powershell
Get-Content $env:USERPROFILE\.claude.json | ConvertFrom-Json
# Throws JSON parse error.
``

Expected behavior

  1. Writes to .claude.json (and any shared config file) must be serialized via file lock (e.g. flock on POSIX, LockFileEx on Windows) or atomic temp-file-rename.
  2. If a write cannot acquire the lock within a timeout, return an error to the caller rather than performing a destructive partial write.
  3. Agent boot retry loop must have a circuit breaker: after N consecutive failures with the same root cause (invalid .claude.json), stop spawning new agents and surface a clear error to the user.
  4. Consider sharding per-session state into separate files so concurrent agents don't contend for the same JSON document.

Actual behavior

.claude.json corrupts under parallel-worker load. The cascading agent spawn amplifies the failure into a memory / CPU outage of the entire Cowork session, requiring desktop app force-quit + manual .claude.json restore from backup.

This is also a known class of failure with prior issues in the area of .claude.json concurrent write corruption + cascading agent spawn referenced inside (54891) — splitting it out here so it can carry its own minimal reproducer.

Environment

  • OS: Windows 11 (build 26100.x), NTFS host
  • Claude Code: 2.1.123
  • Cowork desktop app (2026-04-29 ~ 04-30 build)
  • 12 Cowork plugins enabled (customer-support, pdf-viewer, operations, slack-by-salesforce, data, sales, engineering, marketing, product-management, design, cowork-plugin-management, productivity)
  • Concurrent worker count when observed: 4 general-purpose subagents + 1 dispatcher + 1 Chrome MCP

Related

  • Parent master ticket: (54891)
  • Sibling splits: #54891-split-01, -02, -03, -04
  • Adjacent class: prior .claude.json concurrent corruption / cascading agent spawn issues

Workaround (current)

Reduce parallel worker count to ≤ 2 when MCP write activity is expected. Periodic backup of .claude.json to a known-good copy (Aiken's scheduled task). When cascading agent spawn detected (Task Manager > 5 orphan processes), force-quit Cowork app and restore .claude.json from backup before relaunch.

Not a viable long-term workaround for MSP / B2B use — the entire value of parallel workers is parallelism.

---

Cross-reference: split from closed master ticket #54891 (auto-closed as not_planned 2026-06-01 by github-actions[bot]; reproducible bugs persist). Also related to #64592 (Cowork VM service cluster). Submitted by dispatcher via REST API on behalf of the issue author (Claude Team subscription holder, IT MSP production use).

View original on GitHub ↗

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