Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions plugins/hookify/hooks/hfy-python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Find a working Python 3 interpreter and exec the hookify hook with it.
#
# On Windows + Git Bash, `python3` typically resolves to the Microsoft Store
# stub which exits 49 silently in non-TTY subprocess context. This shim probes
# each candidate and skips any that fails, so the Store stub falls through to
# the real python.org install or the `py -3` launcher.
#
# Order:
# 1. python3 — canonical on macOS/Linux
# 2. python — python.org installs on Windows
# 3. py -3 — Windows Python launcher
#
# Args after the shim path are passed straight through to the chosen
# interpreter.
set -e

probe() {
"$@" -c 'import sys; print(sys.version_info[0])' 2>/dev/null
}

for cmd in "python3" "python" "py -3"; do
# shellcheck disable=SC2086
v=$(probe $cmd | tr -d '\r') || continue
if [ "$v" = "3" ]; then
# shellcheck disable=SC2086
exec $cmd "$@"
fi
done

echo "hookify: no working Python 3 interpreter found." >&2
echo " tried: python3, python, py -3" >&2
echo " on Windows, install Python from https://python.org (NOT the Microsoft Store)" >&2
exit 1
8 changes: 4 additions & 4 deletions plugins/hookify/hooks/hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"hooks": [
{
"type": "command",
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/pretooluse.py",
"command": "bash -c 'R=$(echo \"$CLAUDE_PLUGIN_ROOT\" | tr \\\\ /); bash \"$R/hooks/hfy-python.sh\" \"$R/hooks/pretooluse.py\"'",
"timeout": 10
}
]
Expand All @@ -17,7 +17,7 @@
"hooks": [
{
"type": "command",
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/posttooluse.py",
"command": "bash -c 'R=$(echo \"$CLAUDE_PLUGIN_ROOT\" | tr \\\\ /); bash \"$R/hooks/hfy-python.sh\" \"$R/hooks/posttooluse.py\"'",
"timeout": 10
}
]
Expand All @@ -28,7 +28,7 @@
"hooks": [
{
"type": "command",
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/stop.py",
"command": "bash -c 'R=$(echo \"$CLAUDE_PLUGIN_ROOT\" | tr \\\\ /); bash \"$R/hooks/hfy-python.sh\" \"$R/hooks/stop.py\"'",
"timeout": 10
}
]
Expand All @@ -39,7 +39,7 @@
"hooks": [
{
"type": "command",
"command": "python3 ${CLAUDE_PLUGIN_ROOT}/hooks/userpromptsubmit.py",
"command": "bash -c 'R=$(echo \"$CLAUDE_PLUGIN_ROOT\" | tr \\\\ /); bash \"$R/hooks/hfy-python.sh\" \"$R/hooks/userpromptsubmit.py\"'",
"timeout": 10
}
]
Expand Down