claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

CLI crashes with EBADF error when history.jsonl.lock file is inaccessible

Open sdzjoy opened this issue 3 months ago • 1 comments

Bug Description

The Claude Code CLI crashes and exits completely when it encounters an error reading the history.jsonl.lock file, instead of gracefully handling the error and continuing execution.

Error Message

Error: EBADF: bad file descriptor, realpath 'C:\Users\44230\.claude\history.jsonl.lock'

Stack Trace

at async realpath (node:internal/fs/promises:1170:10)
at async Hal._addToNodeFs (file:///C:/Users/44230/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:419:84893)
Emitted 'error' event on Eai instance at: Eai.handleError (file:///C:/Users/44230/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:419:96764)

Error details:

  • errno: -4083
  • code: 'EBADF'
  • syscall: 'realpath'
  • path: 'C:\Users\44230\.claude\history.jsonl.lock'

Environment

  • OS: Windows (PowerShell)
  • Node.js: v22.18.0
  • Claude Code Version: v2.1.1
  • Installation: npm global install
  • Installation path: C:/Users/44230/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/

Expected Behavior

When the history file or lock file is inaccessible, the CLI should:

  1. Log a warning message (e.g., "History file inaccessible, starting without history")
  2. Continue execution normally
  3. Create a new history file if possible

Actual Behavior

The CLI crashes and exits immediately, preventing any interaction.

Possible Causes

  1. File locked by another Claude Code process
  2. Insufficient file permissions
  3. Corrupted lock file
  4. Antivirus/security software interference

Suggested Fix

Wrap the history file operations in try-catch blocks and implement graceful degradation:

try {
    // Load history
} catch (error) {
    console.warn('Warning: Could not load history file. Continuing without history.');
    // Continue execution
}

Workaround

Delete or rename the .claude/history.jsonl.lock file and restart the CLI.

sdzjoy avatar Jan 09 '26 01:01 sdzjoy

Found 2 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/15739
  2. https://github.com/anthropics/claude-code/issues/14558

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

github-actions[bot] avatar Jan 09 '26 01:01 github-actions[bot]