Skip to content

Commit c50a635

Browse files
committed
build: 🤖 Improve the Claude hook integrations
1 parent 4fa817e commit c50a635

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"_comment": "Copy this file to config.local.json to disable individual hooks locally. config.local.json is gitignored. Each key is a hook script filename; set it to false to bail that hook. Any hook not listed (or with no config file at all) is enabled.",
3-
"php-review-track.sh": true,
4-
"php-review-stop.sh": true
2+
"_comment": "Copy this file to config.local.json to disable individual hooks locally.",
3+
4+
"_info-php-review": "Disable the hooks that trigger a code review after editing PHP files.",
5+
"php-review": true
56
}

‎.claude/hooks/php-review-stop.sh‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
# unchanged file is never nudged twice and the loop terminates cleanly once edits
1313
# stop changing content. Silent (exit 0) when there is nothing new to review.
1414

15-
# Local opt-out: hooks/config.local.json maps each hook filename to a boolean.
16-
# A script set to false here bails immediately. No config file (the default) or a
15+
# Everything below parses JSON with jq. Without it, bail silently.
16+
command -v jq >/dev/null 2>&1 || exit 0
17+
18+
# Local opt-out: hooks/config.local.json maps each "feature" to a boolean.
19+
# A disabled feature bails immediately. No config file (the default) or a
1720
# missing key means enabled.
21+
feature="php-review"
1822
config="$(dirname "$0")/config.local.json"
1923
if [ -f "$config" ]; then
20-
self="$(basename "$0")"
21-
enabled=$(jq -r --arg k "$self" 'if has($k) then .[$k] else true end' "$config" 2>/dev/null)
24+
enabled=$(jq -r --arg k "$feature" 'if has($k) then .[$k] else true end' "$config" 2>/dev/null)
2225
[ "$enabled" = "false" ] && exit 0
2326
fi
2427

@@ -41,6 +44,8 @@ content_hash() {
4144
list=""
4245
for marker in "$dir"/touched-*; do
4346
[ -e "$marker" ] || continue
47+
# The glob also matches the ".reviewed" sidecars we write below; skip them.
48+
case "$marker" in *.reviewed) continue ;; esac
4449
file=$(cat "$marker" 2>/dev/null)
4550
[ -n "$file" ] && [ -f "$file" ] || continue
4651

@@ -55,6 +60,6 @@ done
5560

5661
[ -n "$list" ] || exit 0
5762

58-
reason="Before finishing this turn, review your PHP changes. Dispatch the \`php-review\` agent once for each file below (in parallel is fine), then apply any fixes it reports. Files needing review:${list}"
63+
reason="Before finishing this turn, review your PHP changes. Dispatch the \`php-review\` agent once for each file below (in parallel is fine), each with the prompt \`review CHANGES in <file>\`, then apply any fixes it reports. Files needing review:${list}"
5964

6065
jq -n --arg r "$reason" '{decision: "block", reason: $r}'

‎.claude/hooks/php-review-track.sh‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
# here get reviewed later, so pre-existing dirty files the session never edited
99
# are left alone.
1010

11-
# Local opt-out: hooks/config.local.json maps each hook filename to a boolean.
12-
# A script set to false here bails immediately. No config file (the default) or a
11+
# Everything below parses JSON with jq. Without it, bail silently.
12+
command -v jq >/dev/null 2>&1 || exit 0
13+
14+
# Local opt-out: hooks/config.local.json maps each "feature" to a boolean.
15+
# A disabled feature bails immediately. No config file (the default) or a
1316
# missing key means enabled.
17+
feature="php-review"
1418
config="$(dirname "$0")/config.local.json"
1519
if [ -f "$config" ]; then
16-
self="$(basename "$0")"
17-
enabled=$(jq -r --arg k "$self" 'if has($k) then .[$k] else true end' "$config" 2>/dev/null)
20+
enabled=$(jq -r --arg k "$feature" 'if has($k) then .[$k] else true end' "$config" 2>/dev/null)
1821
[ "$enabled" = "false" ] && exit 0
1922
fi
2023

0 commit comments

Comments
 (0)