Multiple CLI sessions corrupt ~/.claude.json on Windows (no file locking)

Resolved 💬 2 comments Opened Feb 26, 2026 by mat9922 Closed Feb 26, 2026

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

  1. Open 2-3 VS Code windows with different projects
  2. Start claude in the integrated terminal of each
  3. Use them concurrently
  4. Within minutes, ~/.claude.json gets 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., flock equivalent on Windows, or lock files)
  • Or use atomic write pattern: write to temp file → MoveFileEx with MOVEFILE_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

View original on GitHub ↗

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