diff options
Diffstat (limited to 'hooks/run-hook.cmd')
| -rwxr-xr-x | hooks/run-hook.cmd | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/hooks/run-hook.cmd b/hooks/run-hook.cmd index a2f7c48..4501021 100755 --- a/hooks/run-hook.cmd +++ b/hooks/run-hook.cmd @@ -53,10 +53,27 @@ CMDBLOCK # running) instead of a PATH lookup for bash, so this keeps working when # Claude Code spawns the SessionStart hook with a broken/empty PATH # (anthropics/claude-code#43127). +# No $(cd ... && pwd) subshell: a fork costs tens of milliseconds under Git +# Bash on Windows, and a relative directory is enough for the exec below. case "$0" in - */*|*\\*) SCRIPT_DIR="$(cd "${0%[/\\]*}" && pwd)" ;; - *) SCRIPT_DIR="$(pwd)" ;; + */*|*\\*) SCRIPT_DIR="${0%[/\\]*}" ;; + *) SCRIPT_DIR="." ;; 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}" "$@" |
