git-guardrails-claude-code

Configures Claude Code PreToolUse hooks to block dangerous git commands before execution.

Updated Sep 19, 2026
One-click install
npx skills add https://github.com/Ab0umar/selrs.cc.BU --skill git-guardrails-claude-code-ab0umar
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/Ab0umar/selrs.cc.BU/tree/main/.agents/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/Ab0umar/selrs.cc.BU --skill git-guardrails-claude-code-ab0umar

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? AI coding agents can accidentally run destructive git commands like git push --force or git reset --hard, causing irreversible data loss. This Skill installs a safety hook that intercepts and blocks these commands before they execute. ## Core Features & Use Cases - Command Blocking: Intercepts git push, git reset --hard, git clean -f, git branch -D, git checkout ., and git restore . via a PreToolUse Bash hook. - Flexible Scope: Installs the guardrail either per-project (.claude/settings.json) or globally across all projects (~/.claude/settings.json). - Customizable Patterns: Lets you add or remove blocked patterns by editing the bundled shell script. - Use Case: A team lead wants Claude Code to never force-push to shared branches. They install this hook globally so every session blocks push commands and returns a clear BLOCKED message to the agent. ## 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 matches, the script exits with code 2 and Claude receives a BLOCKED message.

How to prevent Claude Code from running git push?▼

Copy the block-dangerous-git.sh script to .claude/hooks/ or ~/.claude/hooks/, make it executable, and register it in settings.json under hooks.PreToolUse with a Bash matcher. The script blocks all git push variants including --force.

Can I install Claude Code hooks globally for all projects?▼

Yes, place the hook script in ~/.claude/hooks/ and add the PreToolUse configuration to ~/.claude/settings.json instead of the project-level file. This applies the guardrail to every Claude Code session on the machine.

What git commands does the guardrail script block?▼

The script blocks git push, git reset --hard, git clean -f and -fd, git branch -D, git checkout ., and git restore . by matching grep patterns. You can edit the DANGEROUS_PATTERNS array to add or remove entries.

Why is my Claude Code hook not blocking commands?▼

Common causes are a missing executable permission on the script, jq not being installed, or the hook not being registered in the correct settings.json. Test by piping a sample JSON command into the script and checking for exit code 2.