~/.claude.json corruption from concurrent instances (no atomic writes)

Resolved 💬 3 comments Opened Feb 26, 2026 by kevinnbass Closed Feb 26, 2026

Bug

Running multiple Claude Code instances concurrently causes repeated corruption of ~/.claude.json due to a write race condition. The file is written with a non-atomic truncate-then-write instead of the standard atomic pattern (write to temp file, then rename).

Evidence

  • 335 corruption events over 7 days (Feb 19–26, 2026) from the built-in backup system at ~/.claude/backups/
  • 12 concurrent claude.exe processes observed at time of diagnosis
  • Error: JSON Parse error: Unexpected EOF
  • Corrupted files show partial writes — valid JSON for the first few fields, then truncated (157, 234, 298 bytes instead of the full ~5KB)
  • Different corrupted snapshots have different userID hashes and timestamps within milliseconds of each other, confirming the race between separate processes

Size distribution of corrupted files

57 occurrences:  234 bytes (partial write)
23 occurrences:  397 bytes (partial write)
16 occurrences:  298 bytes (partial write)
15 occurrences:  157 bytes (partial write)
 8 occurrences: ~28KB     (near-full but still invalid)

Reproduction

  1. Open 3+ terminal windows
  2. Run claude in each
  3. Wait ~5–10 minutes for periodic config writes to collide
  4. Observe JSON Parse error: Unexpected EOF and corruption backups appearing in ~/.claude/backups/

Suggested fix

Use atomic writes: write to a temp file, then rename() to the target path. Rename is atomic on both NTFS and POSIX filesystems. This is the standard pattern for preventing this class of corruption.

import { writeFileSync, renameSync } from 'fs';

const tmp = configPath + '.tmp.' + process.pid;
writeFileSync(tmp, JSON.stringify(data, null, 2));
renameSync(tmp, configPath);

Environment

  • Windows 11 Pro 10.0.26200
  • Claude Code 2.1.59
  • Multiple concurrent sessions (terminal + VS Code)

View original on GitHub ↗

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