claude-code
claude-code copied to clipboard
CLI crashes with EBADF error when history.jsonl.lock file is inaccessible
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:
- Log a warning message (e.g., "History file inaccessible, starting without history")
- Continue execution normally
- Create a new history file if possible
Actual Behavior
The CLI crashes and exits immediately, preventing any interaction.
Possible Causes
- File locked by another Claude Code process
- Insufficient file permissions
- Corrupted lock file
- 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.
Found 2 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/15739
- 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