A Git hook runs a program automatically at a repository event. A pre-commit hook runs before a commit is recorded; a pre-push hook runs before changes leave the local machine. These points can put checks close to the changes they review. section 5.3.2
A hook that blocks on an AI reviewer’s judgment can create friction: false positives may teach developers to bypass the hook with --no-verify, bypassing deterministic checks too. A safer split is to let deterministic checks block and let a model advise on questions such as project conventions that are harder to express as fixed rules. section 5.3.2
Listing 5.4 Pre-commit hook example
#!/bin/bash
# .git/hooks/pre-commit
set -euo pipefail
DIFF=$(git diff --cached)
[ -z "$DIFF" ] && exit 0
# Deterministic checks block. This is the real gate.
gitleaks protect --staged --redact || exit 1
# The model advises. It cannot block on its own.
VERDICT=$(printf '%s' "$DIFF" | claude -p "Review this diff against our
conventions: error handling, test coverage for new public functions,
naming. Reply with exactly one line of JSON and nothing else:
{\"verdict\":\"clean\"} or {\"verdict\":\"concerns\",\"notes\":\"...\"}")
if [ "$(printf '%s' "$VERDICT" | jq -r '.verdict')" = "concerns" ]; then
echo "AI reviewer raised concerns (advisory, not blocking):"
printf '%s' "$VERDICT" | jq -r '.notes'
fi
exit 0This pre-commit example scans the staged diff with gitleaks, then asks an AI reviewer for a JSON verdict parsed with jq. The model’s concerns are printed as warnings. section 5.3.2
The example’s intended split needs an operational check: because the script uses set -e and pipefail, a failed model command can terminate the hook even though the model is meant to be advisory. Test failure paths as well as ordinary verdicts. Structured parsing also matters: searching for PASS could mistakenly accept a response containing both FAIL and PASSWORD. section 5.3.2
Git hooks are distinct from agent lifecycle hooks, which respond to events inside an agent’s run rather than repository events. Hooks are also an execution boundary: a compromised agent could modify a pre-commit hook that later runs under the developer’s authority, outside the sandbox. section 5.6.5 section 5.6.6


