EBUSY file lock error on Windows when multiple sessions write to .claude.json

Resolved 💬 3 comments Opened Apr 11, 2026 by jeffyaw Closed Apr 14, 2026

Description

Running multiple Claude Code sessions simultaneously on Windows causes intermittent EBUSY: resource busy or locked errors when writing to ~/.claude.json. This is Windows-specific — macOS and Linux don't exclusively lock files during writes the same way.

Error

ERROR EBUSY: resource busy or locked, open 'C:\Users\<user>\.claude.json'

  at writeFileSync (unknown)
  VZ8 (B:/~BUN/root/src/entrypoints/cli.js:135:1271)
  NcK (B:/~BUN/root/src/entrypoints/cli.js:442:23227)
  p6 (B:/~BUN/root/src/entrypoints/cli.js:442:21289)
  <anonymous> (B:/~BUN/root/src/entrypoints/cli.js:8305:475)
  Au (B:/~BUN/root/src/entrypoints/cli.js:492:63164)
  zm8 (B:/~BUN/root/src/entrypoints/cli.js:492:76228)
  dR (B:/~BUN/root/src/entrypoints/cli.js:492:76109)
  zm8 (B:/~BUN/root/src/entrypoints/cli.js:492:77018)
  dR (B:/~BUN/root/src/entrypoints/cli.js:492:76109)

Steps to Reproduce

  1. Open two Claude Code sessions on Windows (e.g., two terminals, or CLI + desktop app)
  2. Use both sessions actively
  3. The error occurs when both try to write to .claude.json at the same time

Root Cause

writeFileSync on Windows acquires an exclusive file lock. When two Claude Code processes try to write to the same .claude.json simultaneously, the second process gets EBUSY.

This doesn't happen on macOS/Linux because POSIX file writes don't acquire exclusive locks by default.

Suggested Fix

Wrap the writeFileSync call to .claude.json with a retry-on-EBUSY pattern:

function writeFileSyncRetry(path, data, options, retries = 3, delay = 50) {
  for (let i = 0; i < retries; i++) {
    try {
      writeFileSync(path, data, options);
      return;
    } catch (err) {
      if ((err.code === 'EBUSY' || err.code === 'EPERM') && i < retries - 1) {
        const waitUntil = Date.now() + delay * (i + 1);
        while (Date.now() < waitUntil) {} // sync backoff
        continue;
      }
      throw err;
    }
  }
}

Alternatively, use atomic writes (write to a temp file, then rename) which avoids the lock contention entirely.

Environment

  • OS: Windows 11 Pro
  • Claude Code version: 0.9.560
  • Runtime: Bun

View original on GitHub ↗

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