{"slug": "stop-claude-code-from-skipping-git-hooks-with-no-verify", "title": "Stop Claude Code from skipping git hooks with --no-verify", "summary": "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.", "body_md": "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.\n\nThe hook should name the blocked command and exit `2`.\n\nSave this as `.claude/hooks/block_no_verify.py` and make it executable:\n\n``` python\n#!/usr/bin/env python3\nimport json\nimport re\nimport sys\n\ntry:\n    event = json.load(sys.stdin)\nexcept json.JSONDecodeError:\n    sys.exit(0)\n\ntool = event.get(\"tool_name\") or event.get(\"tool\") or \"\"\ninp = event.get(\"tool_input\") or event.get(\"input\") or {}\nif tool != \"Bash\":\n    sys.exit(0)\n\ncommand = str(inp.get(\"command\") or \"\")\nif not re.search(r\"\\bgit\\b\", command) or not re.search(r\"\\b(commit|commit-tree)\\b\", command):\n    sys.exit(0)\n\nif re.search(r\"(^|[\\s])--no-verify(\\s|=|$)\", command):\n    print(\"PreToolUse: blocked git commit --no-verify. Let the repo hooks run.\")\n    sys.exit(2)\n\nfor token in re.findall(r\"(?:[^\\s\\\"']+|\\\"[^\\\"]*\\\"|'[^']*')\", command):\n    if token.startswith(\"'\") or token.startswith('\"') or token.startswith(\"--\"):\n        continue\n    if token.startswith(\"-\") and \"n\" in token[1:]:\n        print(\"PreToolUse: blocked git commit -n. Let the repo hooks run.\")\n        sys.exit(2)\n```\n\nWire 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`.\n\n\"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.\n\n`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.\nI 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/](https://justly-mia-429.rehost.page/)", "url": "https://wpnews.pro/news/stop-claude-code-from-skipping-git-hooks-with-no-verify", "canonical_source": "https://dev.to/vildandenai/stop-claude-code-from-skipping-git-hooks-with-no-verify-46dl", "published_at": "2026-11-30 01:02:38+00:00", "updated_at": "2026-11-30 01:15:25.273186+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": ["Claude Code", "Anthropic", "Vildanden Agent Config"], "also_reported_by": [], "takeaway": "A PreToolUse hook that exits 2 on `git commit --no-verify` or `-n` closes the escape hatch left after a repo hook fails, while skipping quoted arguments so `git commit -m \"do not verify\"` still passes.", "recommendation": {"advice": "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.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/stop-claude-code-from-skipping-git-hooks-with-no-verify", "markdown": "https://wpnews.pro/news/stop-claude-code-from-skipping-git-hooks-with-no-verify.md", "text": "https://wpnews.pro/news/stop-claude-code-from-skipping-git-hooks-with-no-verify.txt", "jsonld": "https://wpnews.pro/news/stop-claude-code-from-skipping-git-hooks-with-no-verify.jsonld"}}