Skip to content

Commit b91b8e9

Browse files
committed
fix(hooks): read session_id from stdin JSON instead of env var
PreToolUse hooks receive context via stdin as JSON, not as environment variables. Parse session_id with jq from the hook input payload.
1 parent a696021 commit b91b8e9

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

.claude/hooks/pre-commit.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
set -uo pipefail
66

7+
HOOK_INPUT=$(cat)
8+
SESSION_ID=$(printf '%s' "$HOOK_INPUT" | jq -r '.session_id // ""')
9+
FLAG_FILE="/tmp/claude-tests-confirmed${SESSION_ID:+-$SESSION_ID}"
10+
711
cd "$CLAUDE_PROJECT_DIR"
812

913
STAGED=$(git diff --cached --name-only)
@@ -12,9 +16,6 @@ if [ -z "$STAGED" ]; then
1216
exit 0
1317
fi
1418

15-
SESSION_ID="${CLAUDE_CODE_SESSION_ID:-${CLAUDE_SESSION_ID:-}}"
16-
FLAG_FILE="/tmp/claude-tests-confirmed${SESSION_ID:+-$SESSION_ID}"
17-
1819
ERRORS=""
1920

2021
# --- Format check ---

0 commit comments

Comments
 (0)