Skip to content

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

Description

@jeffyaw

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

Activity

  1. added
    bugSomething isn't working
    platform:windowsIssue specifically occurs on Windows
    has reproHas detailed reproduction steps
    on Apr 11, 2026
  2. github-actions commented on Apr 11, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. EBUSY: concurrent instances race on .claude.json (Windows) #46481
    2. Race condition: .claude.json corrupted by concurrent writes from multiple sessions #29217
    3. EBUSY: resource busy or locked on .claude.json with multiple concurrent instances (Windows) #25699

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  3. added
    duplicateThis issue or pull request already exists
    and removed
    bugSomething isn't working
    has reproHas detailed reproduction steps
    platform:windowsIssue specifically occurs on Windows
    on Apr 14, 2026
  4. github-actions commented on Apr 14, 2026

    @github-actions

    This issue has been automatically closed as a duplicate of #46481.

    If this is incorrect, please re-open this issue or create a new one.

    🤖 Generated with Claude Code

  5. github-actions commented on Apr 21, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  6. locked as resolved and limited conversation to collaborators on Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions