EBUSY: resource busy or locked on .claude.json with multiple concurrent sessions (Windows)
Bug Description
When running multiple concurrent Claude Code sessions on Windows, sessions crash with EBUSY: resource busy or locked when trying to write to ~/.claude.json. This file is a shared global state file that all Claude Code instances write to using writeFileSync, which causes file locking collisions on Windows.
Error Message
ERROR EBUSY: resource busy or locked, open 'C:\Users\mail\.claude.json'
at writeFileSync (unknown)
Wq (B:/~BUN/root/claude.exe:6177:1226)
R$f (B:/~BUN/root/claude.exe:6177:4302)
FA (B:/~BUN/root/claude.exe:6177:2896)
OC$ (B:/~BUN/root/claude.exe:3503:10084)
Environment
- OS: Windows 10/11 (MINGW64_NT-10.0-26200)
- Claude Code version: 2.1.42 (native install)
- Concurrent sessions: ~14 Claude Code instances running simultaneously across different project directories
- File system: Local NTFS (C: drive) -
.claude.jsonis NOT on a network/cloud drive
Steps to Reproduce
- Open 10+ Claude Code sessions in different terminals, each in a different project directory
- Use them actively (tool calls, etc.)
- Eventually one or more sessions crash with the EBUSY error above
Expected Behavior
Multiple concurrent Claude Code sessions should be able to coexist without crashing. The ~/.claude.json global state file should handle concurrent access safely.
Root Cause Analysis
The crash occurs at writeFileSync in the Claude Code binary. On Windows, writeFileSync acquires an exclusive file lock. When multiple Claude Code instances try to write to the same ~/.claude.json file simultaneously, all but one get EBUSY.
Suggested Fixes
- Atomic writes: Write to a temp file, then rename (rename is atomic on NTFS)
- Retry with backoff: On EBUSY, retry the write after a short random delay
- Per-process state: Split the state file so each instance writes to its own file, with a merge on read
- File locking with retry: Use
flock/advisory locking with retry logic instead of barewriteFileSync - Environment variable for path: Allow
CLAUDE_STATE_FILEor similar to override~/.claude.jsonlocation
Workaround
Currently there is no workaround - ~/.claude.json is hardcoded to $HOME/.claude.json with no way to override it per instance.
Impact
This is a significant issue for users who work across multiple projects simultaneously. Power users running 10+ concurrent sessions experience frequent crashes, losing work in progress.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗