Claude Code daran hindern, git hooks mit --no-verify zu umgehen
Ein PreToolUse-Hook kann git push --force und git reset --hard blockieren, aber git commit --no-verify umgeht den Hook, der etwa Secrets oder fehlschlagende Tests abfangen wuerde. Ein kleiner Hook kann dieses Flag ablehnen, damit die Repo-Hooks weiter laufen.

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 ) Enter fullscreen mode Exit fullscreen mode 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.
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/