git-guardrails-claude-code

Blocks dangerous git commands in Claude Code using a PreToolUse hook script.

Updated Aug 5, 2026
One-click install
npx skills add https://github.com/pd-phuc/laravel-template --skill git-guardrails-claude-code-pd-phuc
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/pd-phuc/laravel-template/tree/main/.claude/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/pd-phuc/laravel-template --skill git-guardrails-claude-code-pd-phuc

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? AI coding agents can execute destructive git commands like git push --force or git reset --hard that permanently destroy work. This Skill installs a safety hook that intercepts and blocks these commands before they run. ## Core Features & Use Cases - Command Interception: Registers a PreToolUse hook that inspects every Bash command Claude Code attempts to run. - Dangerous Pattern Blocking: Blocks git push, git reset --hard, git clean -f, git branch -D, git checkout ., and git restore . by matching against a configurable pattern list. - Flexible Scope: Installs the guardrail for a single project (.claude/settings.json) or globally across all projects (~/.claude/settings.json). - Use Case: A team lets Claude Code autonomously refactor and commit code, but wants to guarantee it can never force-push to main or wipe uncommitted changes. ## Quick Start Ask the AI to set up git guardrails that block dangerous git commands like push and reset --hard in 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 each command 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 the tool input as JSON on stdin and can approve or block execution via its exit code.

Can I apply git safety hooks 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 settings file. The global configuration then applies to every project you open in Claude Code.

What git commands does the guardrail script block?▼

The script blocks git push including force variants, 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 add or remove patterns.

Why is my Claude Code hook not blocking commands?▼

Common causes are the script lacking execute permission, an incorrect path in settings.json, or missing jq which the script uses to parse input. Run chmod +x on the script and test it manually by piping a sample JSON command to it.