summaryrefslogtreecommitdiff
path: root/hooks/run-hook.cmd
diff options
context:
space:
mode:
authorJesse Vincent <jesse@fsck.com>2026-10-22 21:19:08 +0000
committerJesse Vincent <jesse@fsck.com>2026-10-22 21:19:08 +0000
commit3cbe5575758e409ac083c694cfc45ccfde50c0cd (patch)
treee84d7571f7bbd0665f7f20f61ff18b680e9cdee2 /hooks/run-hook.cmd
parent0f9581f6c1525b51dc1600b14d24f3db1f601446 (diff)
fix(hooks): fall back to zsh, or exit quietly, when bash is missing on Unix (#2503)fix/2503-run-hook-no-bash
On a Unix system without bash, the harness can't honour shell:"bash" and runs run-hook.cmd with zsh or sh. $BASH is unset there, so the wrapper's exec "${BASH:-bash}" fails with "command not found: bash" (zsh) or "exec: bash: not found" (sh), the hook exits 127, and the bootstrap is lost on every session start. Keep $BASH first, so the empty-PATH case from #2310 still works, then look for bash on PATH, then zsh, which runs session-start unchanged (its output is byte-identical to bash's, including for a SKILL.md full of backslashes, quotes, tabs and CRs). With neither shell, exit 0 quietly, as the Windows half already does. Reproduced with Claude Code 2.1.308 in an alpine container with zsh and no bash: the hook exited 127 and no bootstrap reached the model before the change; after it the hook exits 0 and the bootstrap arrives. Tests run the wrapper under real zsh and under a non-bash sh with a PATH that holds only zsh, and under that sh with neither shell. They skip where zsh is absent or sh is bash (Git Bash, macOS). Co-authored-by: Twot <twotnguyen@users.noreply.github.com> Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba
Diffstat (limited to 'hooks/run-hook.cmd')
-rwxr-xr-xhooks/run-hook.cmd17
1 files changed, 16 insertions, 1 deletions
diff --git a/hooks/run-hook.cmd b/hooks/run-hook.cmd
index a2f7c48..928aaba 100755
--- a/hooks/run-hook.cmd
+++ b/hooks/run-hook.cmd
@@ -59,4 +59,19 @@ case "$0" in
esac
SCRIPT_NAME="$1"
shift
-exec "${BASH:-bash}" "${SCRIPT_DIR}/${SCRIPT_NAME}" "$@"
+
+# Without bash installed, the harness runs this file with zsh or sh and $BASH
+# is unset (#2503). session-start runs unchanged under zsh, so fall back to
+# it, and otherwise exit quietly like the Windows half: the plugin still
+# works, just without SessionStart context injection.
+if [ -n "${BASH:-}" ]; then
+ shell="$BASH"
+elif command -v bash >/dev/null 2>&1; then
+ shell="bash"
+elif command -v zsh >/dev/null 2>&1; then
+ shell="zsh"
+else
+ exit 0
+fi
+
+exec "$shell" "${SCRIPT_DIR}/${SCRIPT_NAME}" "$@"