git-guardrails

Blocks irreversible git commands via a Claude Code PreToolUse hook before agents execute them.

1|Updated Jul 13, 2026
One-click install
npx skills add https://github.com/dineshrevunuru/SuperSkills --skill git-guardrails-dineshrevunuru
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails
Source: https://github.com/dineshrevunuru/SuperSkills/tree/main/git-guardrails
Command: npx skills add https://github.com/dineshrevunuru/SuperSkills --skill git-guardrails-dineshrevunuru

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jq.

What problem does it solve? AI coding agents can silently run destructive git commands like git reset --hard or git push --force, permanently destroying uncommitted work or rewriting shared history. Prompt instructions alone fail the one time it matters; this Skill installs a hook that enforces the block at the tool level. ## Core Features & Use Cases - PreToolUse Bash hook: Intercepts every Bash command, matches it against a blocked-pattern list, and exits with code 2 to stop execution and feed the reason back to the agent. - Two-band blocked list: Band A covers irreversible operations (hard reset, clean -f, force-push, branch -D, filter-branch, reflog expire, rm -rf .git); Band B covers external publishes (any git push) requiring confirmation. - Global or project install: Writes the hook script to ~/.claude/hooks/ and merges into settings.json without overwriting existing hooks, with a mandatory verification step to catch fail-open misconfigurations like missing jq. - Use Case: After an agent nukes uncommitted work with a hard reset, install this guard globally in about five minutes so every future destructive command is blocked and the agent proposes a reversible alternative like git stash or a WIP commit instead. ## Quick Start Install a global Claude Code PreToolUse hook that blocks dangerous git commands like hard reset, force-push, and clean -f, then verify it blocks a test command.

Frequently Asked Questions about git-guardrails

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I block dangerous git commands in Claude Code?

Write a PreToolUse Bash hook script that parses the incoming command with jq, matches it against a list of dangerous patterns with grep, and exits with code 2 on a match. Register the hook in settings.json under the PreToolUse hooks array with the Bash matcher.

How do I stop an AI agent from force-pushing or hard-resetting?

Install a PreToolUse hook that intercepts Bash calls and blocks patterns like git reset --hard, push --force, and git clean -f before execution. The hook exits non-zero and returns the block reason to the agent, which then proposes a reversible alternative like git stash.

Can I install the git safety hook globally across all projects?

Yes, place the hook script in ~/.claude/hooks/ and register it in ~/.claude/settings.json for global coverage. Project-scope installation uses .claude/hooks/ and the project settings file with the $CLAUDE_PROJECT_DIR path.

Why is my PreToolUse hook not blocking any commands?

The most common cause is missing jq, which the script uses to parse the command from stdin JSON; without it every command falls through unblocked. Verify by piping a test command like git reset --hard into the script and confirming it exits with code 2.

Will the hook block safe git commands like clean -n or branch -d?

No, the pattern list targets only irreversible variants such as git clean -f and git branch -D. Dry-run and safe forms like git clean -n and git branch -d remain usable so normal workflows are not disrupted.