[BUG] Claude Code crashes with `spawn pgrep ENOENT` when hooks spawn background processes

Resolved 💬 2 comments Opened Jan 12, 2026 by sathreddy Closed Jan 12, 2026

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?

Claude Code crashes when I run /clear or when a permission prompt appears. The error:

Error: spawn pgrep ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn pgrep',
path: 'pgrep',
spawnargs: [ '-P', 73582 ]
}

What Should Happen?

Claude Code should handle the case where pgrep is not found gracefully, or use the absolute path /usr/bin/pgrep. It shouldn't crash.

Error Messages/Logs

Error: spawn pgrep ENOENT
      at ChildProcess._handle.onexit (node:internal/child_process:285:19)
      at onErrorNT (node:internal/child_process:483:16)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn pgrep',
    path: 'pgrep',
    spawnargs: [ '-P', 73582 ]
  }

Steps to Reproduce

  1. Set up a notification hook that runs something in the background:
# ~/.claude/hooks/notification-sound.sh
#!/bin/bash
afplay /System/Library/Sounds/Glass.aiff &
exit 0
  1. Add it to settings.json:
{
  "hooks": {
    "Notification": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "/path/to/notification-sound.sh"
          }
        ]
      }
    ]
  }
}
  1. Use Claude Code normally until a notification triggers
  2. Run /clear or do something that triggers a permission prompt → crash

What's going on

pgrep exists at /usr/bin/pgrep and works fine in shell commands. The problem is Claude Code's internal spawn() call doesn't seem to have /usr/bin in its PATH when it tries to check child processes with pgrep -P <pid>.

The background & in my hook seems to trigger Claude Code's child process tracking, which then calls pgrep and fails.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.5

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Other

Additional Information

  • Terminal: Ghostty
  • Shell: zsh (configured via CLAUDE_CODE_SHELL=/bin/zsh)
  • macOS 15 (Darwin 25.2.0), Apple Silicon

Workaround: Remove & from hook scripts so they don't spawn background processes.

Related issues:
#15389 - Similar pgrep spawn issues but with EAGAIN instead of ENOENT
#3989 - Also pgrep-related crashes

View original on GitHub ↗

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