EBUSY: resource busy or locked on .claude.json with multiple concurrent instances (Windows)
Bug Description
When running multiple Claude Code CLI instances and/or Claude Desktop simultaneously on Windows, writeFileSync to ~/.claude.json intermittently fails with:
ERROR EBUSY: resource busy or locked, open 'C:\Users\apami\.claude.json'
at writeFileSync (unknown)
Iq (B:/~BUN/root/claude.exe:6171:1226)
rHf (B:/~BUN/root/claude.exe:6171:4208)
BA (B:/~BUN/root/claude.exe:6171:2887)
<anonymous> (B:/~BUN/root/claude.exe:3797:23173)
cA (B:/~BUN/root/claude.exe:679:62572)
w1 (B:/~BUN/root/claude.exe:679:75521)
ED (B:/~BUN/root/claude.exe:679:75405)
w1 (B:/~BUN/root/claude.exe:679:76304)
ED (B:/~BUN/root/claude.exe:679:75405)
Environment
- OS: Windows 11 Pro 10.0.26200
- Claude Code version: Latest (native install via
.local/bin/claude.exe) - Claude Desktop: app-1.1.2685
- Concurrent processes: ~14 CLI instances + ~9 Desktop app processes
Root Cause
Multiple Claude processes write to the shared ~/.claude.json file (19KB, contains telemetry counters, session stats, feature flags, project configs). On Windows, file writes acquire mandatory locks (unlike Unix advisory locks). When two processes call writeFileSync() at the same instant, one gets EBUSY.
Windows Defender real-time protection makes this worse — it briefly locks the file for scanning after each write, extending the contention window.
Suggested Fix
Replace the bare writeFileSync() with one of:
- Atomic write: Write to
~/.claude.json.tmp, thenfs.renameSync()to~/.claude.json— rename is atomic on both Windows (NTFS) and Unix - Retry with backoff: Wrap
writeFileSyncin a retry loop (e.g., 3 attempts, 50-200ms exponential backoff) to handle transient locks - Both: Atomic write + retry on the rename for belt-and-suspenders
Workaround
Adding a Windows Defender exclusion for ~/.claude.json and claude.exe reduces the lock window and makes collisions less frequent, but doesn't fully eliminate the race.
Add-MpExclusion -ExclusionPath "C:\Users\<user>\.claude.json"
Add-MpExclusion -ExclusionProcess "claude.exe"This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗