Stop hook fails with ENOENT: posix_spawn '/bin/sh' during session end

Resolved 💬 3 comments Opened Feb 21, 2026 by algoboa Closed Feb 24, 2026

Description

When a Claude Code session ends, the Stop hook fails with:

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'

This occurs consistently when hooks are configured to run shell commands during the Stop lifecycle event.

Environment

  • OS: macOS (Darwin 25.2.0)
  • Claude Code: Latest version
  • Plugin: claude-mem (hooks registered for Stop event)

Hook Configuration

The Stop hook runs commands via node (e.g., node "scripts/worker-service.cjs" hook claude-code summarize). The hooks are configured in hooks.json with the Stop event type.

Root Cause Hypothesis

The sandbox environment appears to tear down /bin/sh access before the Stop hook commands finish executing. Since posix_spawn requires /bin/sh to execute shell commands, this race condition causes the ENOENT error.

Key observations:

  • The error specifically mentions posix_spawn '/bin/sh' — the shell binary itself is inaccessible
  • This only happens during Stop hooks, not during PostToolUse or UserPromptSubmit hooks
  • The timing suggests the sandbox cleanup begins before Stop hooks complete

Expected Behavior

Stop hooks should complete execution before the sandbox environment is torn down. The /bin/sh binary should remain accessible for the duration of hook execution.

Steps to Reproduce

  1. Configure a Stop hook that runs a shell command (e.g., via claude-mem plugin or any custom hook)
  2. Start a Claude Code session
  3. End the session (type "exit", use /clear, or let it complete naturally)
  4. Observe the Stop hook error in the output

Suggested Fix

Ensure the sandbox teardown waits for all Stop hook processes to complete (or at minimum, keeps /bin/sh accessible) before cleaning up the environment.

View original on GitHub ↗

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