[BUG] PID exhaustion via pgrep

Resolved 💬 6 comments Opened Jul 24, 2025 by bukzor Closed Aug 15, 2025

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

  1. Navigate to a directory with bash scripts that use complex pipelines (find + xargs + grep patterns)
  2. Run a bash command through Claude Code that executes such scripts: ./bin/validate-coverage 2>&1 | head -20
  3. The script appears to hang or take a long time
  4. Attempt to cancel the action, via <esc>
  5. Claude Code begins spawning exponential numbers of pgrep -P <pid> processes
  6. 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 1000 allows capturing the error before complete system lockup
  • The specific script uses find ... -print0 | xargs -0 grep-any -l ... patterns
  • Bug occurs in /$bunfs/root/claude binary, suggesting issue in process cleanup/monitoring code

View original on GitHub ↗

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