[BUG] EBADF error when calling TodoWrite tool multiple times in succession
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Environment:
- OS: macOS (Darwin 25.0.0)
- Claude Code Version: 2.0.27
- Node.js Version: latest
Description:
When the TodoWrite tool is called multiple times in quick succession (within a few seconds), a spawn EBADF error occurs. The error does not prevent the main task from
completing, but it clutters the terminal with error messages.
Steps to Reproduce:
- Run a slash command that uses TodoWrite to track task progress
- Update the todo list by calling TodoWrite to mark first task as in_progress
- Immediately call TodoWrite again to mark first task as completed and second task as in_progress
- Observe EBADF error in terminal
Error Output:
Error: spawn EBADF
at ChildProcess.spawn (node:internal/child_process:420:11)
at spawn (node:child_process:762:9)
at file:///Users/cph/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:2523
at f51 (file:///Users/cph/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:3018)
at file:///Users/cph/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:3251
at Array.forEach (<anonymous>)
at ChildProcess.J (file:///Users/cph/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:3186)
at ChildProcess.emit (node:events:524:28)
at ChildProcess.emit (node:domain:489:12)
at maybeClose (node:internal/child_process:1104:16) {
errno: -9,
code: 'EBADF',
syscall: 'spawn'
}
Expected Behavior:
TodoWrite should handle multiple rapid calls gracefully without spawning errors.
Actual Behavior:
Multiple EBADF errors are thrown, though the underlying task (file writing) still completes successfully.
Possible Root Cause:
- Race condition when spawning child processes for UI updates
- File descriptor cleanup issue between successive calls
- Child process management not properly handling rapid succession calls
Impact:
- Low: Does not break functionality
- Medium: Creates confusing error output for users
- Workaround: Batch todo updates instead of multiple successive calls
Suggested Fix:
- Add file descriptor validity check before spawning
- Implement better child process lifecycle management
- Add debouncing or queuing for rapid TodoWrite calls
What Should Happen?
TodoWrite should handle multiple rapid calls gracefully without spawning errors.
Error Messages/Logs
Error Output:
Error: spawn EBADF
at ChildProcess.spawn (node:internal/child_process:420:11)
at spawn (node:child_process:762:9)
at file:///Users/cph/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:2523
at f51 (file:///Users/cph/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:3018)
at file:///Users/cph/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:3251
at Array.forEach (<anonymous>)
at ChildProcess.J (file:///Users/cph/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:195:3186)
at ChildProcess.emit (node:events:524:28)
at ChildProcess.emit (node:domain:489:12)
at maybeClose (node:internal/child_process:1104:16) {
errno: -9,
code: 'EBADF',
syscall: 'spawn'
}
Steps to Reproduce
Steps to Reproduce:
- Run a slash command that uses TodoWrite to track task progress
- Update the todo list by calling TodoWrite to mark first task as in_progress
- Immediately call TodoWrite again to mark first task as completed and second task as in_progress
- Observe EBADF error in terminal
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.0.27
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗