cd /news/ai-agents/stop-claude-code-from-skipping-git-h… · home › topics › ai-agents › article
[ARTICLE · art-178336] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Stop Claude Code from skipping git hooks with --no-verify

A developer published a Claude Code PreToolUse hook that blocks `git commit --no-verify` and `git commit -n`, closing a gap left by existing guards against `git push --force` and `git reset --hard`. The Python script parses the Bash tool input, detects the bypass flags while ignoring quoted commit messages, and exits with code 2 to refuse the command so repository hooks still run. The hook is wired into `.claude/settings.json` under PreToolUse, optionally scoped to the Bash matcher.

recommendation

Add a PreToolUse Bash hook that exits 2 on `git commit --no-verify` or `-n` so coding agents cannot bypass repo hooks after a failure; fix the hook instead of skipping it.

more in playbook: Working with AI coding agents
by read2 min views16 publishedNov 30, 2026

A PreToolUse hook can already block git push --force and git reset --hard. That still leaves a hole: git commit --no-verify (or -n) skips the hook that would have caught a secret, a red test, or a broken lint. A small PreToolUse hook can refuse that flag so the repo hooks still run.

The hook should name the blocked command and exit 2.

Save this as .claude/hooks/block_no_verify.py and make it executable:

#!/usr/bin/env python3
import json
import re
import sys

try:
    event = json.load(sys.stdin)
except json.JSONDecodeError:
    sys.exit(0)

tool = event.get("tool_name") or event.get("tool") or ""
inp = event.get("tool_input") or event.get("input") or {}
if tool != "Bash":
    sys.exit(0)

command = str(inp.get("command") or "")
if not re.search(r"\bgit\b", command) or not re.search(r"\b(commit|commit-tree)\b", command):
    sys.exit(0)

if re.search(r"(^|[\s])--no-verify(\s|=|$)", command):
    print("PreToolUse: blocked git commit --no-verify. Let the repo hooks run.")
    sys.exit(2)

for token in re.findall(r"(?:[^\s\"']+|\"[^\"]*\"|'[^']*')", command):
    if token.startswith("'") or token.startswith('"') or token.startswith("--"):
        continue
    if token.startswith("-") and "n" in token[1:]:
        print("PreToolUse: blocked git commit -n. Let the repo hooks run.")
        sys.exit(2)

Wire it in .claude/settings.json under PreToolUse with command set to python3 .claude/hooks/block_no_verify.py. If your settings support a matcher, limit it to Bash.

"Don't skip hooks" in CLAUDE.md only works when the model remembers it mid-turn. After a hook fails, the next move is often git commit --no-verify to "just land the change." The PreToolUse hook runs before the shell, so that escape hatch is closed. If a hook is actually broken, fix the hook or run the commit yourself in a terminal — do not let the agent skip it.

reset --hard PreToolUse guard so destructive git and hook-skipping are both blocked.-n is treated as --no-verify on git commit. Quoted commit messages are ignored, so git commit -m "do not verify" will not trip the hook. I keep copy-ready Claude Code configs (CLAUDE.md templates, slash commands, hooks, permission rules) in Vildanden Agent Config. There's a free sample: https://justly-mia-429.rehost.page/

── more in #ai-agents 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/stop-claude-code-fro…] indexed:0 read:2min 2026-11-30 · —