A PreToolUse hook blocks git reset --hard and force pushes
A rule in CLAUDE.md is a request. A hook that exits 2 before the command runs is a guarantee.
Reported by @juliandierker · Verified 2026-11-21
+1 cache this week · +36 GitHub stars since the last radar
- Agent
- Claude Code
- Stack
- Git
Problem
"Never force-push" holds most of the time. The one time the agent decides the task needs a clean tree, uncommitted work is gone.
Setup
The skill installs a script and registers it as a PreToolUse hook on Bash. The core of it, as AI Hero shows it:
#!/bin/bash
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command')
for pattern in "git reset --hard" "git clean -fd" "push --force" "git checkout \."; do
if [[ "$COMMAND" == *$pattern* ]]; then
echo "BLOCKED: $pattern is not allowed" >&2
exit 2
fi
doneblock destructive git commands in Claude Code for this repoWhat happened
Without it
The model weighs your rule against the task in front of it.
With it
The command never runs. The agent sees "BLOCKED" and has to find another way, usually asking you.
Sources: This hook stops Claude Code running dangerous git commands (AI Hero), SKILL.md.
Reproduce
Install the skill and let it write the hook.
Ask the agent to "throw away my changes and start over".
Check that the hook blocked the command and what the agent did instead.