spawn pgrep ENOENT crash on macOS
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
Claude Code crashes with spawn pgrep ENOENT error during normal operation. The crash occurs when Claude Code's internal process management attempts to use pgrep -P <pid> to track child processes, but pgrep is not available in the sandboxed environment's PATH.
Environment
- OS: macOS (darwin)
- Claude Code Version: Latest (as of 2025-12-21)
- Model: claude-opus-4-5-20251101
Error Message
Error: spawn pgrep ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:286:19)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn pgrep',
path: 'pgrep',
spawnargs: [ '-P', 18164 ]
}
Steps to Reproduce
- Start a Claude Code session on macOS
- Perform various operations (the exact trigger is unclear, but appears related to process management)
- Claude Code crashes with the above error
Expected Behavior
Claude Code should either:
- Use a pgrep alternative that works in the sandboxed environment (e.g., ps aux | grep)
- Gracefully handle the case where pgrep is unavailable
- Include pgrep in the sandbox PATH if it's required
Actual Behavior
Claude Code crashes immediately when attempting to spawn pgrep, terminating the session and losing work in progress.
Additional Context
- macOS has pgrep at /usr/bin/pgrep, but Claude Code's sandboxed environment appears to not have access to it
- The spawnargs: [ '-P', 18164 ] suggests Claude Code is trying to find child processes of a specific PID
- This is an internal Claude Code operation, not triggered by user bash commands
- The crash is intermittent but reproducible across multiple sessions
Workaround
None available for the internal crash. Users can avoid running pgrep as a bash command (which also fails), but the internal process management crash cannot be prevented from the user side.
Suggested Fix
Replace internal pgrep -P <pid> calls with a cross-platform alternative:
// Instead of: spawn('pgrep', ['-P', pid])
// Use: spawn('ps', ['-o', 'pid=', '--ppid', pid]) // Linux
// Or: spawn('ps', ['-o', 'pid=', '-g', pid]) // macOS
Or wrap the pgrep call in a try-catch with fallback logic.
What Should Happen?
Workaround
None available for the internal crash. Users can avoid running pgrep as a bash command (which also fails), but the internal process management crash cannot be prevented from the user side.
Suggested Fix
Replace internal pgrep -P <pid> calls with a cross-platform alternative:
// Instead of: spawn('pgrep', ['-P', pid])
// Use: spawn('ps', ['-o', 'pid=', '--ppid', pid]) // Linux
// Or: spawn('ps', ['-o', 'pid=', '-g', pid]) // macOS
Or wrap the pgrep call in a try-catch with fallback logic.
Error Messages/Logs
crash; exit to terminal
Steps to Reproduce
Steps to Reproduce
- Start a Claude Code session on macOS
- Perform various operations (the exact trigger is unclear, but appears related to process management)
- Claude Code crashes with the above error
Expected Behavior
Claude Code should either:
- Use a pgrep alternative that works in the sandboxed environment (e.g., ps aux | grep)
- Gracefully handle the case where pgrep is unavailable
- Include pgrep in the sandbox PATH if it's required
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.75
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 9 comments on GitHub. Read the full discussion on GitHub ↗