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

[Bug] Frequent EAGAIN and EBADF errors in process spawning on macOS

Open cyberops7 opened this issue 4 months ago • 4 comments

Bug Description Claude code is crashing FREQUENTLY with EBADF and/or EBADF process spawning errors. This has happened on both Claude 2.0.76 and 2.0.75, on macOS 15.7.x and 26.2.

Environment Info

  • Platform: darwin
  • Terminal: ghostty
  • Version: 2.0.75
  • Feedback ID: 2f56fa66-4ccd-4c65-b920-3b635b2366d3

I have already tried a lot of different troubleshooting suggestions, but nothing has helped, so far. This has happened across multiple sessions, plans, etc.

❯ ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8176
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       6000
-n: file descriptors                8192

-n used to be set to 256, but increasing it to 8192 has not made any difference.

Errors

[]

Initial error was:

EAGAIN: resource temporarily unavailable, posix_spawn '/opt/homebrew/bin/pgrep'
      path: "/opt/homebrew/bin/pgrep",
   syscall: "spawn pgrep",
     errno: -35,
 spawnargs: [ "-P", 586 ],
      code: "EAGAIN"

      at spawn (node:child_process:667:35)
      at spawn (node:child_process:14:39)
      at <anonymous> (/$bunfs/root/claude:190:41503)
      at RoR (/$bunfs/root/claude:190:41996)
      at <anonymous> (/$bunfs/root/claude:190:42231)
      at forEach (1:11)
      at $ (/$bunfs/root/claude:190:42170)
      at emit (node:events:98:22)
      at #maybeClose (node:child_process:766:16)

662 |     var file = this.spawnfile = options.file, spawnargs;
663 |     if (options.args === @undefined)
664 |       spawnargs = this.spawnargs = [];
665 |     else
666 |       validateArray(options.args, "options.args"), spawnargs = this.spawnargs = options.args;
667 |       if (this.#handle = Bun.spawn({

but more recently it is:

Error: spawn EBADF
    at ChildProcess.spawn (node:internal/child_process:420:11)
    at spawn (node:child_process:753:9)
    at file:///Users/david/.nvm/versions/node/v22.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:240:45818
    at fp1 (file:///Users/david/.nvm/versions/node/v22.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:240:46313)
    at file:///Users/david/.nvm/versions/node/v22.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:240:46546
    at Array.forEach (<anonymous>)
    at ChildProcess.X (file:///Users/david/.nvm/versions/node/v22.16.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:240:46481)
    at ChildProcess.emit (node:events:518:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1101:16) {
  errno: -9,
  code: 'EBADF',
  syscall: 'spawn'
}

cyberops7 avatar Dec 26 '25 00:12 cyberops7

It is now even happening with a brand new session after my prompt to enter plan mode and make a plan for my next task.

cyberops7 avatar Dec 26 '25 01:12 cyberops7

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/3989
  2. https://github.com/anthropics/claude-code/issues/7923
  3. https://github.com/anthropics/claude-code/issues/8593

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 Dec 26 '25 01:12 github-actions[bot]

Getting the same issue as well. I see a lot of zombie/defunct processes.

samx3499 avatar Dec 27 '25 07:12 samx3499

The culprit for mine is having proctools installed via Homebrew. There is something about that version/build of pgrep that is incompatible with how Claude Code tries to do things on macOS. I commented on another issue, but uninstalling proctools solved this problem for me.

My request for Anthropic would be to have claude doctor check if pgrep is installed via Homebrew and give a warning about this (seemingly) known issue. With that, I wish Anthropic would give the option to explicitly use the built-in pgrep instead of whatever results in your PATH. I'd like to have the GNU versions of these tools installed, and still have Claude Code work.

cyberops7 avatar Dec 27 '25 14:12 cyberops7

Proctools installed via Homebrew was the issue for me as well (macos)

Confirmed:

which pgrep /opt/homebrew/bin/pgrep

brew list proctools /opt/homebrew/Cellar/proctools/0.4pre1/bin/pfind /opt/homebrew/Cellar/proctools/0.4pre1/bin/pgrep /opt/homebrew/Cellar/proctools/0.4pre1/bin/pkill /opt/homebrew/Cellar/proctools/0.4pre1/sbom.spdx.json /opt/homebrew/Cellar/proctools/0.4pre1/share/man/ (3 files)

'You have proctools installed, and it is overriding the system's default process management tools (pgrep and pkill) that Claude relies on. Claude expects the macOS BSD-style behavior, but proctools is giving it something else, leading to the crash.'

I ran the following and have not had the issue since:

brew uninstall proctools hash -r which pgrep (should be /usr/bin/pgrep)

Tip: If you still need the brew proctools binaries, just do brew unlink proctools and run them directly eg. /opt/homebrew/Cellar/proctools/*/bin/pfind when needed.

n0kovo avatar Jan 11 '26 16:01 n0kovo

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Feb 11 '26 10:02 github-actions[bot]

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Feb 25 '26 22:02 github-actions[bot]