[BUG] CLI Crashes with posix_spawn EAGAIN Error Due to Recursive pgrep Calls
Environment
- Platform (select one):
- [x] Anthropic API ?
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version:
1.0.56 (Claude Code) - Operating System:
Darwin 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:53:27 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6041 arm64 - Terminal:
alacritty 0.15.1 (0c405d5)alsokitty
Bug Description
After using claude-code for a bit while the model is working and I'm doing something else it gets into a infinite recursion around calling pgrep.
This appears to happen during subprocess calls that involve pgrep. It looks like the code recursively spawns processes without proper throttling or reuse, eventually hitting system process limits (EAGAIN). This may be related to repeated tool invocations or checks for running processes.
Steps to Reproduce
- I haven't quite figured out how this happens
Expected Behavior
The CLI should avoid hitting system resource limits. Ideally, subprocess spawning (e.g. pgrep) should be rate-limited or reused rather than recursively or rapidly spawned.
Actual Behavior
The CLI fails with posix_spawn errors (underlying error: Resource temporarily unavailable) and terminates unexpectedly. The crash happens when system process limits are reached, likely due to excessive pgrep subprocesses.
18 Comments
reproduction steps:
I'll provide a test command
happens on a different terminal as well
This is (apparently) caused by installing proctools ps:
https://github.com/anthropics/claude-code/issues/4316#issuecomment-3188347086
I don't have access to my subscription to confirm at this time. If this is the case it helps to know this to either remove it or make sure proctools isn't available to CC, Thanks.
The issue should still stay open regardless IMO so that it's solved by CC
workaround for me:
I want to fix this issue as soon as posible.
I haven't proctools installed on my machine, and I get into this error
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.
I don't have access to Claude code this moment to verify if it's still an issue but if you are still seeing it bump this to prevent auto-closure of the issue.
I have been experiencing this problem frequently today - in the middle of performing relatively trivial actions, Claude Code crashes with an infinite loop of error like this
Getting the same issue as well. I see a lot of zombie/defunct processes.
If there's one thing that can bring my $8,000 Mac Studio to its knees, it's being fork bombed by Claude.
Yes, this isn't a bug. Yes, the brew uninstall proctools workaround works. Apparently that's the random nonstandard open source dependency that's drinking your milkshake. But it's nasty enough problem you may want to consider taking steps to avoid it anyway.
I’ve also experienced similar issues. Numerous pgrep processes were generated, causing the system to become completely unresponsive.
The following is a reproduction screen. When monitoring the process after the query, multiple pgrep processes are generated as shown below and enter the ‘Resource temporarily unavailable (OS error 35)’ state.
Claude CLI version: 2.1.19 (Claude Code)
Operating System: macOS 26.2 (25C56)
Terminal: wezterm 20240203-110809-5046fc22 also kitty, alacritty, ghostty, iterm ...
Multiplexer: zellij 0.43.1
Shell: zsh 5.9 (arm-apple-darwin23.1.0)
<img width="2560" height="1410" alt="Image" src="https://github.com/user-attachments/assets/dac52466-f403-43f0-8516-095c66eec5b0" />
In case you're on Apple silicon (M1+) and you already tried
brew uninstall proctoolswith no luck, check wherepgrepis installed on your machine viawhich pgrep. Mine was installed in/usr/local/bin/pgrepdespite being on Apple silicon (brew should install in/opt/homebrewfor Apple silicon) 🤦. Turns out some packages were left over when I migrated from an older Intel Mac to M1. I removed orphaned Intel Homebrew files and then verified thatwhich pgrepcorrectly returns/usr/bin/pgrep(the system-installed one). That fixed this issue for me.In my environment, /opt/homebrew/bin/pgrep is used by default.
which -a pgrep
/opt/homebrew/bin/pgrep
/usr/bin/pgrep
---
~Observing the recurring situation, it appears to occur when modifying settings in $HOME/.claude/~
~Claude Code seems to be monitoring (watching) the $HOME/.claude directory in real-time, leading to a simultaneous sequence of file modification -> change detection -> configuration reload, potentially resulting in an infinite recursive state.~
I'm not sure if you're still looking to fix the recursive
pgrepissue (maybe you're just giving more context in your reply) so apologies if you knew this already but the fix for this issue is to REMOVE thepgrepyou got via Homebrew by doingbrew uninstall proctoolsand only have the one in/usr/bin/pgrep(the system-installedpgrep). You're currently using the Homebrew one despite having the system one.@ShivanKaul Thanks.
Running
brew uninstall proctoolsalso removes/opt/homebrew/bin/pgrep.which -a pgrep/usr/bin/pgrepIn this state, the pgrep infinite spawning issue has disappeared.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.