Multiple CLI sessions corrupt ~/.claude.json on Windows (no file locking)
Problem
Running multiple claude CLI sessions simultaneously (e.g., in different VS Code terminal tabs for different projects) causes repeated corruption of ~/.claude.json on Windows.
The file gets detected as corrupted ("JSON Parse error: Unexpected EOF"), backed up, and replaced with a near-empty config — losing all project data, tool usage stats, tips history, etc.
Root cause
Multiple claude.exe processes read/write ~/.claude.json concurrently without any file locking. On Windows, there is no atomic rename() like on Unix, making partial reads during writes very likely.
Reproduction
- Open 2-3 VS Code windows with different projects
- Start
claudein the integrated terminal of each - Use them concurrently
- Within minutes,
~/.claude.jsongets corrupted
Evidence
Over 5 days (Feb 21-26), we collected 43 "corrupted" backup files. 97% of them were valid JSON — the corruption is purely a timing issue where one process reads while another writes.
The file grew from 67KB to 80KB over time, then cascaded down to 77 bytes through repeated "detect corrupt → backup → replace with empty" cycles.
Impact
- Complete loss of project configurations (30 projects → 0)
- Loss of tool usage statistics, tips history, startup count
- Requires manual recovery from backup files
- Happens repeatedly, making multi-project workflows unreliable
Affected processes
All of these write to ~/.claude.json concurrently:
- Multiple CLI sessions (
~/.local/bin/claude.exe) - Claude Desktop App (Electron)
- VS Code Claude Code Extension (spawns its own
claude.exe)
Suggested fix
- Use proper file locking (e.g.,
flockequivalent on Windows, or lock files) - Or use atomic write pattern: write to temp file →
MoveFileExwithMOVEFILE_REPLACE_EXISTING - Or separate per-session state from shared config
Environment
- Windows 11 Pro, Claude Code CLI v2.1.59
- 3 concurrent CLI sessions in different VS Code terminals
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗