Block No-Verify Hook

Block No-Verify Hook

Configures a PreToolUse hook that stops AI agents from skipping git pre-commit hooks with --no-verify and similar bypass flags.

Skill files1 file
SKILL.md207 lines
1
---
2
name: block-no-verify-hook
3
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.
4
---
5
6
# Block No-Verify Hook
7
8
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.
9
10
## Overview
11
12
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.
13
14
## Problem
15
16
When AI agents commit code, they may use bypass flags to avoid hook failures:
17
18
```bash
19
# These commands skip pre-commit hooks entirely
20
git commit --no-verify -m "quick fix"
21
git push --no-verify
22
git commit --no-gpg-sign -m "unsigned commit"
23
git merge --no-verify feature-branch
24
```
25
26
This allows:
27
- Unformatted code to enter the repository
28
- Linting errors to bypass checks
29
- Security scanning to be skipped
30
- Unsigned commits to bypass signing policies
31
- Test suites to be circumvented
32
33
## Solution
34
35
Add a `PreToolUse` hook to `.claude/settings.json` that inspects every Bash tool call and blocks commands containing bypass flags.
36
37
### Configuration
38
39
Add the following to your project's `.claude/settings.json`:
40
41
```json
42
{
43
"hooks": {
44
"PreToolUse": [
45
{
46
"matcher": "Bash",
47
"hooks": [
48
{
49
"type": "command",
50
"command": "if grep -qE '\"command\"[[:space:]]*:[[:space:]]*\"([^\"\\\\]|\\\\.)*(--no-(ver|g)|commit([^\"\\\\]|\\\\.)*([[:space:]]|\\\\[tn])-[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"
51
}
52
]
53
}
54
]
55
}
56
}
57
```
58
59
### How It Works
60
61
1. **Matcher**: The hook targets only `Bash` tool calls, so it does not interfere with other tools (Read, Edit, Grep, etc.).
62
2. **Inspection**: Claude Code sends the tool call to the hook as JSON on stdin and sets no `$TOOL_INPUT` variable. The hook searches the `command` value in that JSON with `grep -E`, so it needs no `jq` or `node`, and text in other fields, such as `cwd` or the tool call's description, can't trigger it. It blocks `--no-verify`, `--no-gpg-sign`, and any shorter prefix of them that git accepts, e.g., `--no-veri`. It also blocks a short option group with `n` that follows `commit` in the same command, e.g., `-n` or `-nm`, because `-n` is the short form of `--no-verify`. The hook doesn't look for the word `git`, so it also catches `if git ...`, `sudo git ...`, and `g=git; $g commit --no-verify`. A false match, such as a commit message that mentions a flag, blocks the call, which is the safe way to fail.
63
3. **Blocking**: If a bypass flag is found in a git command, the hook exits with code 2 and prints an error message. Exit code 2 signals Claude Code to reject the tool call entirely.
64
4. **Pass-through**: If no bypass flag is found, the hook exits with code 0 and the command executes normally.
65
5. **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 or by running `git -c core.hooksPath=/dev/null commit`.
66
67
### Exit Codes
68
69
| Code | Meaning |
70
|------|---------|
71
| 0 | Allow the tool call to proceed |
72
| 1 | Error (tool call still proceeds, warning shown) |
73
| 2 | Block the tool call entirely |
74
75
## Blocked Flags
76
77
| Flag | Purpose | Why Blocked |
78
|------|---------|-------------|
79
| `--no-verify` | Skips pre-commit and commit-msg hooks | Bypasses linting, formatting, testing, security checks |
80
| `--no-gpg-sign` | Skips GPG commit signing | Bypasses commit signing policy |
81
82
## Installation
83
84
### Per-Project Setup
85
86
Create or update `.claude/settings.json` in your project root:
87
88
```bash
89
mkdir -p .claude
90
cat > .claude/settings.json << 'EOF'
91
{
92
"hooks": {
93
"PreToolUse": [
94
{
95
"matcher": "Bash",
96
"hooks": [
97
{
98
"type": "command",
99
"command": "if grep -qE '\"command\"[[:space:]]*:[[:space:]]*\"([^\"\\\\]|\\\\.)*(--no-(ver|g)|commit([^\"\\\\]|\\\\.)*([[:space:]]|\\\\[tn])-[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"
100
}
101
]
102
}
103
]
104
}
105
}
106
EOF
107
```
108
109
### Global Setup
110
111
To enforce across all projects, add to `~/.claude/settings.json`:
112
113
```bash
114
mkdir -p ~/.claude
115
cat > ~/.claude/settings.json << 'EOF'
116
{
117
"hooks": {
118
"PreToolUse": [
119
{
120
"matcher": "Bash",
121
"hooks": [
122
{
123
"type": "command",
124
"command": "if grep -qE '\"command\"[[:space:]]*:[[:space:]]*\"([^\"\\\\]|\\\\.)*(--no-(ver|g)|commit([^\"\\\\]|\\\\.)*([[:space:]]|\\\\[tn])-[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"
125
}
126
]
127
}
128
]
129
}
130
}
131
EOF
132
```
133
134
## Verification
135
136
Test that the hook blocks bypass flags:
137
138
```bash
139
# This should be blocked by the hook:
140
git commit --no-verify -m "test"
141
142
# This should succeed normally:
143
git commit -m "test"
144
```
145
146
## Extending the Hook
147
148
### Adding More Blocked Flags
149
150
To block additional flags (e.g., `--force`), extend the grep pattern:
151
152
```json
153
{
154
"hooks": {
155
"PreToolUse": [
156
{
157
"matcher": "Bash",
158
"hooks": [
159
{
160
"type": "command",
161
"command": "if grep -qE '\"command\"[[:space:]]*:[[:space:]]*\"([^\"\\\\]|\\\\.)*(--no-(ver|g)|commit([^\"\\\\]|\\\\.)*([[:space:]]|\\\\[tn])-[a-zA-Z]*n|git([[:space:]]|\\\\t)([^\"\\\\]|\\\\.)*--force)'; then echo 'BLOCKED: Bypass flags are not allowed.' >&2; exit 2; fi"
162
}
163
]
164
}
165
]
166
}
167
}
168
```
169
170
### Combining with Other Hooks
171
172
The block-no-verify hook works alongside other PreToolUse hooks:
173
174
```json
175
{
176
"hooks": {
177
"PreToolUse": [
178
{
179
"matcher": "Bash",
180
"hooks": [
181
{
182
"type": "command",
183
"command": "if grep -qE '\"command\"[[:space:]]*:[[:space:]]*\"([^\"\\\\]|\\\\.)*(--no-(ver|g)|commit([^\"\\\\]|\\\\.)*([[:space:]]|\\\\[tn])-[a-zA-Z]*n)'; then echo 'BLOCKED: Bypass flags not allowed.' >&2; exit 2; fi"
184
}
185
]
186
},
187
{
188
"matcher": "Bash",
189
"hooks": [
190
{
191
"type": "command",
192
"command": "if grep -qE 'rm[[:space:]]+-rf[[:space:]]+/'; then echo 'BLOCKED: Dangerous rm command.' >&2; exit 2; fi"
193
}
194
]
195
}
196
]
197
}
198
}
199
```
200
201
## Best Practices
202
203
1. **Commit the settings file** -- Add `.claude/settings.json` to version control so all team members benefit from the hook.
204
2. **Document in onboarding** -- Mention the hook in your project's contributing guide so developers understand why bypass flags are blocked.
205
3. **Pair with pre-commit hooks** -- The block-no-verify hook ensures pre-commit hooks run; make sure you have meaningful pre-commit hooks configured.
206
4. **Test after setup** -- Verify the hook works by intentionally triggering it in a test commit.
207

© cskwork · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…