[BUG] PID exhaustion via pgrep
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: 1.0.59 (Claude Code)
- Operating System: macOS (Darwin 24.5.0)
- Terminal: kitty (0.31.0)
Bug Description
Claude Code CLI enters an infinite loop spawning thousands of pgrep subprocesses, leading to PID exhaustion and system instability. The CLI appears to be recursively monitoring child processes,
where each pgrep spawn triggers more monitoring attempts.
Steps to Reproduce
- Navigate to a directory with bash scripts that use complex pipelines (find + xargs + grep patterns)
- Run a bash command through Claude Code that executes such scripts:
./bin/validate-coverage 2>&1 | head -20 - The script appears to hang or take a long time
- Attempt to cancel the action, via <esc>
- Claude Code begins spawning exponential numbers of
pgrep -P <pid>processes - System hits process limit and becomes unstable
Expected Behavior
Claude Code should execute the bash command normally, monitor child processes appropriately, and clean up resources without creating a fork bomb.
Actual Behavior
Claude Code spawns thousands of pgrep processes in a recursive loop, causing:
- PID exhaustion (EAGAIN errors)
- System instability
- Thousands of identical stack traces logged
Additional Context
Stack trace shows:
EAGAIN: resource temporarily unavailable, posix_spawn '/opt/homebrew/bin/pgrep'
path: "/opt/homebrew/bin/pgrep",
syscall: "spawn pgrep",
errno: -35,
spawnargs: [ "-P", 82107 ],
code: "EAGAIN"
at spawn (node:child_process:647:35)
at spawn (node:child_process:14:39)
at ua0 (/$bunfs/root/claude:269:1563)
at <anonymous> (/$bunfs/root/claude:269:1798)
at forEach (1:11)
at X (/$bunfs/root/claude:269:1737)
at emit (node:events:98:22)
at #maybeClose (node:child_process:746:16)
at emit (node:events:92:22)
- Bug is reproducible when running the same command multiple times
- Issue appears to be in Claude Code's process monitoring logic, not the bash scripts themselves
- Setting
ulimit -u 1000allows capturing the error before complete system lockup - The specific script uses
find ... -print0 | xargs -0 grep-any -l ...patterns - Bug occurs in
/$bunfs/root/claudebinary, suggesting issue in process cleanup/monitoring code
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗