Skip to content

Commit 8e943ae

Browse files
committed
docs: tighten the no-verify hook in the AI agents guide
Quoted text now becomes a placeholder instead of vanishing, so `git -C "my repo" commit -n` is still caught. --no-verify is only matched after `git`, so commands like `rg -- --no-verify` pass. The hook blocks with a clear message when jq is missing instead of silently allowing everything, and the page names `bash -c` as a case it does not catch.
1 parent c2c3383 commit 8e943ae

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎docs/guides/ai-agents.md‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ and tells Claude why. This one stops `--no-verify`, and `-n` on `git commit`:
3434

3535
```bash title=".claude/hooks/no-verify.sh"
3636
#!/usr/bin/env bash
37-
# Stop `git commit` and `git push` from skipping the hooks. Quoted text
38-
# is dropped first, so a commit message that mentions -n still passes.
39-
command=$(jq -r '.tool_input.command' | sed -E "s/\"[^\"]*\"//g; s/'[^']*'//g")
40-
skips='--no-verify|git( +-C +[^ ]+)* +commit[^;&|]* +-[a-zA-Z]*n'
37+
# Stop git from skipping the hooks: --no-verify, or -n on git commit.
38+
# Quoted text becomes _ first, so a commit message that mentions -n passes.
39+
command -v jq >/dev/null || { echo "This hook needs jq." >&2; exit 2; }
40+
cmd=$(jq -r '.tool_input.command' | sed -E "s/\"[^\"]*\"/_/g; s/'[^']*'/_/g")
41+
any='git [^;&|]*--no-verify'
42+
commit='git( +-C +[^ ]+)* +commit[^;&|]* +-[a-zA-Z]*n'
4143

42-
if grep -Eq -e "$skips" <<<"$command"; then
44+
if grep -Eq -e "$any" -e "$commit" <<<"$cmd"; then
4345
echo "Do not skip the hooks (--no-verify, -n)." \
4446
"Fix what Commit Check reported and commit again." >&2
4547
exit 2
@@ -65,10 +67,11 @@ fi
6567
}
6668
```
6769

68-
Make the script executable, install [jq](https://jqlang.org/), and commit both
69-
files, so everyone who works in the repository with Claude Code gets the hook.
70-
It reads the command as written and does not catch every way around a hook,
71-
pre-commit's `SKIP` variable for one.
70+
Make the script executable, install [jq](https://jqlang.org/) (without it the
71+
hook stops every command), and commit both files, so everyone who works in the
72+
repository with Claude Code gets the hook. It reads the command as written and
73+
does not catch every way around a hook, such as a command wrapped in `bash -c`
74+
or pre-commit's `SKIP` variable.
7275

7376
## Check the pull request
7477

0 commit comments

Comments
 (0)