git-guardrails-claude-code

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

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/Fatih0234/mattpocock-skills-pi --skill git-guardrails-claude-code-fatih0234
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/Fatih0234/mattpocock-skills-pi/tree/main/skills/misc/git-guardrails-claude-code
Command: npx skills add https://github.com/Fatih0234/mattpocock-skills-pi --skill git-guardrails-claude-code-fatih0234

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? AI coding agents can execute destructive git operations like force pushes, hard resets, and branch deletions that permanently destroy work. This Skill installs a PreToolUse hook that intercepts and blocks these commands before Claude Code can run them. ## Core Features & Use Cases - Command Blocking: Intercepts git push, git reset --hard, git clean -f/-fd, git branch -D, git checkout ., and git restore . before execution. - Flexible Scope: Installs the guardrail hook either per-project (.claude/settings.json) or globally across all projects (~/.claude/settings.json). - Customizable Patterns: The blocked-pattern list in the shell script can be edited to add or remove commands based on team 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; the hook returns exit code 2 with a BLOCKED message whenever a dangerous pattern is detected. ## Quick Start Set up git guardrails in Claude Code to 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 git push in Claude Code?▼

Install a PreToolUse hook that matches the Bash tool and runs a script checking commands against dangerous patterns like git push. When matched, the script exits with code 2 and Claude receives a BLOCKED message instead of executing the command.

How to set up a PreToolUse hook in Claude Code?▼

Add a hooks.PreToolUse entry to .claude/settings.json with matcher set to Bash and a command pointing to your hook script. The script receives JSON on stdin containing tool_input.command and blocks execution by exiting with code 2.

Can I apply git guardrails to all projects at once?▼

Yes, install the hook script to ~/.claude/hooks/ and register it in ~/.claude/settings.json instead of the project-level file. This applies the blocking rules globally across every project where Claude Code runs.

Which git commands does the guardrail hook block?▼

The default pattern list blocks git push (including --force), git reset --hard, git clean -f and -fd, git branch -D, git checkout ., and git restore .. You can edit the DANGEROUS_PATTERNS array in the script to customize the list.

Why is my Claude Code hook not blocking commands?▼

Verify the script is executable with chmod +x and that the settings.json path matches the actual script location. Test it by piping a sample JSON payload like a git push command into the script and confirming it exits with code 2.