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

Resolved 💬 3 comments Opened Jan 9, 2026 by sdzjoy Closed Jan 12, 2026

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.

View original on GitHub ↗

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