git-guardrails-claude-code

Installs a Claude Code PreToolUse hook that blocks dangerous git commands before execution.

Updated Jul 30, 2026
One-click install
npx skills add https://github.com/j172/bid --skill git-guardrails-claude-code-j172
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/j172/bid/tree/main/agent/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/j172/bid --skill git-guardrails-claude-code-j172

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jq, and includes scripts (resource) components.

What problem does it solve? AI coding assistants can execute destructive git commands like git push --force, git reset --hard, or git clean -fd that permanently destroy work or overwrite remote history. This Skill prevents that by installing a hook that intercepts and blocks these commands before they run. ## Core Features & Use Cases - Pre-execution Blocking: Registers a PreToolUse hook that intercepts Bash tool calls and blocks git push, git reset --hard, git clean -f/-fd, git branch -D, git checkout ., and git restore .. - Flexible Scope: Install the guardrail for a single project (.claude/settings.json) or globally across all projects (~/.claude/settings.json). - Customizable Patterns: Edit the bundled shell script to add or remove blocked command patterns to match your team's safety policy. - Use Case: A developer lets Claude Code run autonomously on a repository but wants to guarantee it can never force-push to main or wipe uncommitted changes during a session. ## Quick Start Ask Claude to set up git guardrails that block dangerous git commands like push and reset --hard for this project.

Frequently Asked Questions about git-guardrails-claude-code

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

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

Install a PreToolUse hook that matches the Bash tool and runs a script checking each command against dangerous patterns. When a command like git push or git reset --hard matches, the script exits with code 2 and Claude sees a blocked message.

Which git commands does this hook block?

The script blocks git push (including --force), git reset --hard, git clean -f and -fd, git branch -D, git checkout ., and git restore . by matching regex patterns against the command string.

Can I install git guardrails for all projects at once?

Yes, copy the hook script to ~/.claude/hooks/ and register it in ~/.claude/settings.json instead of the project-level file. The hook then applies to every Claude Code session regardless of project.

How do I add or remove blocked git command patterns?

Edit the DANGEROUS_PATTERNS array in the copied block-dangerous-git.sh script. Each entry is a grep -E compatible pattern, so you can add new commands or remove existing ones to fit your policy.

Why is the git guardrail hook not blocking commands?

Common causes are the script missing executable permission (run chmod +x), an incorrect path in settings.json, or jq not being installed since the script uses jq to parse the tool input JSON.