block-no-verify-hook
Configure a PreToolUse hook to prevent AI agents from skipping git pre-commit hooks with --no-verify and other bypass flags. Use when setting up Claude Code projects that enforce commit quality gates.
- License 许可
- MIT
- 最近更新
- 2026-11-10
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- block-no-verify-hook
- description
- Configure a PreToolUse hook to prevent AI agents from skipping git pre-commit hooks with --no-verify and other bypass flags. Use when setting up Claude Code projects that enforce commit quality gates.
03 SKILL.md 正文
Block No-Verify Hook
PreToolUse hook configuration that intercepts and blocks bypass-flag usage before execution, ensuring AI agents cannot skip pre-commit hooks, GPG signing, or other git safety mechanisms.
Overview
AI coding agents (Claude Code, Codex, etc.) can run shell commands with flags like --no-verify that bypass pre-commit hooks. This defeats the purpose of linting, formatting, testing, and security checks configured in pre-commit hooks. The block-no-verify hook adds a PreToolUse guard that rejects any tool call containing bypass flags before execution.
PreToolUse hooks are a Claude Code feature. For other harnesses, see Other harnesses.
Problem
When AI agents commit code, they may use bypass flags to avoid hook failures:
# These commands skip pre-commit hooks entirely. Never run them without the user's approval.
git commit --no-verify -m "quick fix"
git push --no-verify
git commit --no-gpg-sign -m "unsigned commit"
git merge --no-verify feature-branch
Solution
Add a PreToolUse hook to .claude/settings.json that inspects every Bash tool call and blocks git commands containing bypass flags.
Configuration
The hook entry to merge into your settings (see Installation):
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "if grep -qE '\"command\"[[:space:]]*:[[:space:]]*\"(([^\"\\\\]|\\\\.)*([[:space:]/(;&|]|\\\\[tn]))?git([[:space:]]|\\\\t)(([^\"\\\\;&|]|\\\\[^n])*([[:space:]]|\\\\t))?((commit|push|merge|rebase|pull|am|cherry-pick|revert)([[:space:]]|\\\\t)(([^\"\\\\;&|]|\\\\[^n])*([[:space:]]|\\\\t))?--no-(ver(i[a-z]*)?|g[a-z-]*)([[:space:]=;&|)\"]|\\\\)|commit([[:space:]]|\\\\t)(([^\"\\\\;&|]|\\\\[^n])*([[:space:]]|\\\\t))?-[a-zA-Z]*n)'; then echo 'BLOCKED: --no-verify and --no-gpg-sign flags are not allowed. Run the commit without bypass flags so that pre-commit hooks execute properly.' >&2; exit 2; fi"
}
]
}
]
}
}
How It Works
- Matcher: The hook targets only
Bashtool calls, so it does not interfere with other tools (Read, Edit, Grep, etc.). - Inspection: Claude Code sends the tool call to the hook as JSON on stdin and sets no
$TOOL_INPUTvariable. The hook searches thecommandvalue in that JSON withgrep -E, so it needs nojqornode, and text in other fields, such ascwdor the tool call's description, can't trigger it. - Matching: The pattern looks for the word
git, then a subcommand that takes a bypass flag (commit,push,merge,rebase,pull,am,cherry-pick,revert), then the flag, all within one shell command. A;,&,|or newline ends the command, sogit commit -m x && echo -npasses. The flag must be a whole word:--no-verify,--no-gpg-sign, or a shorter prefix git accepts, e.g.,--no-verior--no-g. A word that only starts the same way, such as--no-git-tag-versioninnpm version patch --no-git-tag-version, passes. Aftercommitit also blocks a short option group withn, e.g.,-nor-nm, because-nis the short form of--no-verifythere.gitmay follow a space,/,(or a shell separator, sosudo git ...,if git ...and/usr/bin/git ...are caught. A false match, such as a commit message that mentions a flag, blocks the call, which is the safe way to fail. - Result: On a match the hook prints an error and exits 2, which makes Claude Code reject the tool call. Otherwise it exits 0 and the command runs.
- Limits: The hook checks text, so it stops an agent that reaches for a bypass flag out of habit. It doesn't stop an agent that sets out to evade it, e.g., by building the flag from pieces, by calling git through a variable (
g=git; $g commit --no-verify), or by runninggit -c core.hooksPath=/dev/null commit. Pair it with the server-side checks in Other harnesses.
Blocked Flags
| Flag | Purpose | Why Blocked |
|---|---|---|
--no-verify |
Skips pre-commit and commit-msg hooks | Bypasses linting, formatting, testing, security checks |
-n (on git commit) |
Short form of --no-verify |
Same as above |
--no-gpg-sign |
Skips GPG commit signing | Bypasses commit signing policy |
Installation
The /block-no-verify command (/block-no-verify --global for every project) does this merge for you. To install by hand, run the script below. It never replaces the settings file wholesale:
- It copies an existing settings file to
settings.json.bak.<timestamp>first. - It keeps every existing setting and hook.
- It removes an earlier copy of this hook and adds the current one, so it is safe to run again.
f=.claude/settings.json # use f=~/.claude/settings.json to enforce across all projects
mkdir -p "$(dirname "$f")"
[ -f "$f" ] && cp "$f" "$f.bak.$(date +%Y%m%d%H%M%S)"
python3 - "$f" << 'EOF'
import json, os, sys
path = sys.argv[1]
hook = {"type": "command", "command": "if grep -qE '\"command\"[[:space:]]*:[[:space:]]*\"(([^\"\\\\]|\\\\.)*([[:space:]/(;&|]|\\\\[tn]))?git([[:space:]]|\\\\t)(([^\"\\\\;&|]|\\\\[^n])*([[:space:]]|\\\\t))?((commit|push|merge|rebase|pull|am|cherry-pick|revert)([[:space:]]|\\\\t)(([^\"\\\\;&|]|\\\\[^n])*([[:space:]]|\\\\t))?--no-(ver(i[a-z]*)?|g[a-z-]*)([[:space:]=;&|)\"]|\\\\)|commit([[:space:]]|\\\\t)(([^\"\\\\;&|]|\\\\[^n])*([[:space:]]|\\\\t))?-[a-zA-Z]*n)'; then echo 'BLOCKED: --no-verify and --no-gpg-sign flags are not allowed. Run the commit without bypass flags so that pre-commit hooks execute properly.' >&2; exit 2; fi"}
settings = json.load(open(path)) if os.path.exists(path) else {}
entries = settings.setdefault("hooks", {}).setdefault("PreToolUse", [])
for entry in entries:
entry["hooks"] = [h for h in entry.get("hooks", []) if "BLOCKED: --no-verify" not in h.get("command", "")]
entries[:] = [e for e in entries if e["hooks"]]
entries.append({"matcher": "Bash", "hooks": [hook]})
with open(path, "w") as out:
json.dump(settings, out, indent=2)
out.write("\n")
EOF
If the existing file isn't valid JSON, the script stops with an error before it writes anything. Fix the file and run the script again.
Verification
Test that the hook blocks bypass flags:
# This should be blocked by the hook:
git commit --no-verify -m "test"
# This should succeed normally:
git commit -m "test"
Extending the Hook
To block more commands, add another entry to the PreToolUse array rather than growing the pattern. This one blocks git push --force and -f but allows --force-with-lease:
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "if grep -qE '\"command\"[[:space:]]*:[[:space:]]*\"(([^\"\\\\]|\\\\.)*([[:space:]/(;&|]|\\\\[tn]))?git([[:space:]]|\\\\t)(([^\"\\\\;&|]|\\\\[^n])*([[:space:]]|\\\\t))?push([[:space:]]|\\\\t)(([^\"\\\\;&|]|\\\\[^n])*([[:space:]]|\\\\t))?(--force|-[a-zA-Z]*f)([[:space:]=;&|)\"]|\\\\)'; then echo 'BLOCKED: force push is not allowed.' >&2; exit 2; fi"
}
]
}
Other harnesses
Codex, Cursor, Copilot and the other harnesses have no PreToolUse hook that can run this check. Use git and your code host instead:
- Git hooks: Install the checks as
pre-commitandpre-pushhooks, for example with pre-commit or acore.hooksPathdirectory. They run for every harness and for people.--no-verifyskips them, so they can't be the only gate. - Branch protection: Run the same checks in CI and require them to pass before a merge into the protected branch, with direct pushes turned off. Require signed commits there if you sign them. A bypass flag then can't get code past the server.
Best Practices
- Commit the settings file -- Add
.claude/settings.jsonto version control so all team members benefit from the hook. - Pair with pre-commit hooks -- The hook only ensures pre-commit hooks run; make sure they check something meaningful.
- Test after setup -- Run the commands under Verification.
04 同仓库更多 Skills
no-description
暂无简介
good-skill
Fixture skill that satisfies every rule.
broken-link
Links to a reference file that does not exist.
Bad_Name
Name violates the kebab-case rule and does not match the directory.
skill-authoring
Write, review, and validate portable agent skills in SKILL.md format. Use when creating a new skill, editing an existing one, or asked whether a skill follows the Agent Skills spec.
weigh-bags
Record scale readings for each bag — empty (tare), outbound, current, final — and reconcile them against the itemised inventory to find unaccounted weight. Use when the user gives a bag weight, says how heavy something is, weighs their luggage, or asks how close to the limit they are. Appends to bags.yaml and runs scripts/reconcile.py.