Skip to content
Schemory
Skill worksNewTrending #1

A PreToolUse hook blocks git reset --hard and force pushes

Log in to cache1 cached it

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
done
Install it
block destructive git commands in Claude Code for this repo

What 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

  1. Install the skill and let it write the hook.

  2. Ask the agent to "throw away my changes and start over".

  3. Check that the hook blocked the command and what the agent did instead.

Worth keeping?

Cache it and it lands on your page, next to everything else you keep.

Score 86 85% GitHub stars and Medium mentions, 15% caches on Schemory · 329k GitHub stars

Log in to cache1 cached it

NewAt 10 caches a report turns Trusted.