[BUG] Stop hooks fail with 'spawn /bin/sh ENOENT' on session end

Resolved 💬 3 comments Opened Jan 27, 2026 by affaan-m Closed Jan 30, 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?

When a Claude Code session ends (via /rename command or potentially other session-ending events), Stop hooks fail with the error:

Stop hook error: Failed with non-blocking status code: Error occurred while executing hook command: spawn /bin/sh ENOENT

This error repeated 4 times (once per configured Stop hook).

What Should Happen?

Stop hooks should execute successfully. The shell binary /bin/sh exists and is accessible:

$ ls -la /bin/sh
-rwxr-xr-x  1 root  wheel  101232 Aug 16 11:44 /bin/sh
$ which sh
/bin/sh

Error Messages/Logs

⏺ Ran 4 stop hooks
  ⎿  Stop hook error: Failed with non-blocking status code: Error
     occurred while executing hook command: spawn /bin/sh ENOENT
  ⎿  Stop hook error: Failed with non-blocking status code: Error
     occurred while executing hook command: spawn /bin/sh ENOENT
  ⎿  Stop hook error: Failed with non-blocking status code: Error
     occurred while executing hook command: spawn /bin/sh ENOENT
  ⎿  Stop hook error: Failed with non-blocking status code: Error
     occurred while executing hook command: spawn /bin/sh ENOENT

Steps to Reproduce

  1. Configure Stop hooks in ~/.claude/settings.json:
{
  "hooks": {
    "Stop": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "#!/bin/bash\necho 'Session ended' >&2\ncat"
          }
        ]
      }
    ]
  }
}
  1. Start a Claude Code session
  2. End the session (via command or session termination)
  3. Observe the spawn /bin/sh ENOENT errors

Suspected Cause

This may be related to:

  • Race condition during session teardown where the process environment is already partially cleaned up
  • Node.js child_process.spawn not inheriting PATH correctly during shutdown
  • macOS-specific sandboxing or process isolation during cleanup

Context

This occurred alongside issue #21085 (path encoding collision) when moving a project directory. It's unclear if the path change triggered the hook failures or if they're independent.

Claude Model

Opus

Is this a regression?

Unknown

Claude Code Version

Latest (January 2026)

Platform

Anthropic API

Operating System

macOS (Darwin 24.6.0)

Terminal/Shell

zsh

Additional Information

The hooks work correctly during normal operation (PreToolUse, PostToolUse). Only Stop hooks exhibit this failure.

View original on GitHub ↗

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