[BUG] Error: spawn EBADF when running CLI (via agent test execution)

Resolved 💬 6 comments Opened Oct 1, 2025 by hypery11 Closed Jan 26, 2026

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?

Description
When the @anthropic-ai/claude-code CLI is triggered by an agent running tests, I repeatedly hit Error: spawn EBADF.
The error does not always occur when running manually, but is reproducible when the agent executes tests.

Actual Behavior
The CLI crashes with the following stack trace (de-duplicated and de-identified for readability):

Error: spawn EBADF
    at ChildProcess.spawn (node:internal/child_process:420:11)
    at spawn (node:child_process:762:9)
    at file:///<REDACTED_HOME>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:115:2705
    at _t1 (file:///<REDACTED_HOME>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:115:3200)
    at file:///<REDACTED_HOME>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:115:3433
    at Array.forEach (<anonymous>)
    at ChildProcess.W (file:///<REDACTED_HOME>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:115:3368)
    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'
}

What Should Happen?

The CLI should work normally when invoked by an agent running tests.

Error Messages/Logs

Error: spawn EBADF
    at ChildProcess.spawn (node:internal/child_process:420:11)
    at spawn (node:child_process:762:9)
    at file:///<REDACTED_HOME>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:115:2705
    at _t1 (file:///<REDACTED_HOME>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:115:3200)
    at file:///<REDACTED_HOME>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:115:3433
    at Array.forEach (<anonymous>)
    at ChildProcess.W (file:///<REDACTED_HOME>/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:115:3368)
    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

  1. Install @anthropic-ai/claude-code via npm/yarn
  2. Set up an agent to execute automated tests (which internally calls the CLI)
  3. Observe the error during test execution

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.0

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

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