Hooks fail with posix_spawn '/bin/sh' ENOENT without sandbox enabled

Resolved 💬 4 comments Opened Feb 15, 2026 by synap5e Closed Mar 15, 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?

All 4 Stop hooks fail with ENOENT: no such file or directory, posix_spawn '/bin/sh', without the sandbox feature enabled (no sandbox key in settings.json, no bubblewrap processes associated with Claude Code).

● Ran 4 stop hooks
  ⎿  command: "/home/user/agentic/claude-hooks/emit-event.py"
  ⎿  command: "$HOME/agentic/claude-hooks/chat-update.py"
  ⎿  command: "$HOME/agentic/claude-hooks/hooks/notify-stop.sh"
  ⎿  command: "$HOME/agentic/claude-hooks/log-event.py"
  ⎿  Stop hook error: Failed with non-blocking status code: Error occurred while
     executing hook command: ENOENT: no such file or directory, posix_spawn '/bin/sh'
  ⎿  (repeated for all 4 hooks)

Investigation

  • /bin/sh exists and is executable (lrwxrwxrwx /bin/sh -> bash)
  • Running the hook commands manually via /bin/sh -c '"$HOME/agentic/claude-hooks/log-event.py"' works fine
  • Sandbox is NOT enabled — no sandbox key in settings.json, no bwrap processes associated with Claude Code, process is in the init namespaces
  • The hook scripts themselves have correct shebangs and execute successfully when invoked manually
  • The error is transient — hooks in the same session executed successfully on subsequent turns

Hypothesis: CWD-related posix_spawn failure

A comment on #20211 by @danyelf identified that posix_spawn returns ENOENT when the current working directory doesn't exist at spawn time, but the error message misleadingly attributes it to the binary path (/bin/sh). This is a well-known POSIX behavior.

What Should Happen?

Hooks should either:

  1. Execute with an explicit cwd that's guaranteed to exist (e.g., $HOME or /tmp) as a fallback
  2. Handle ENOENT from posix_spawn gracefully and retry with a safe CWD
  3. At minimum, log the actual CWD being used in the error message so the root cause is diagnosable

Error Messages/Logs

ENOENT: no such file or directory, posix_spawn '/bin/sh'

Steps to Reproduce

  1. Configure multiple Stop hooks in ~/.claude/settings.json (no sandbox configuration)
  2. Use Claude Code normally
  3. Occasionally (not every time), Stop hooks fail with the above error
  4. Subsequent turns in the same session execute hooks successfully

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.42

Platform

Anthropic API

Operating System

Linux (Arch/CachyOS, kernel 6.18.8-3-cachyos)

Terminal/Shell

fish / Alacritty + tmux

Additional Information

Related to #20211 but distinct: that issue attributes the error to sandbox restrictions (Seatbelt on macOS). This report demonstrates the same error occurs on Linux without the sandbox feature enabled, pointing to a different root cause (likely CWD-related posix_spawn behavior).

View original on GitHub ↗

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