git-guardrails

Configure Claude Code hooks to block dangerous Git commands before execution.

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

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 loss of work or unintended changes to shared repositories. This Skill installs a safety net that intercepts and blocks those commands before they execute. ## Core Features & Use Cases - PreToolUse Hook Installation: Sets up a Claude Code hook that intercepts Bash tool calls and blocks dangerous Git commands before they run. - Flexible Scope: Install the guardrail for a single project (.claude/settings.json) or globally across all projects (~/.claude/settings.json). - Customizable Blocklist: Edit the bundled shell script to add or remove blocked patterns such as git push, git reset --hard, git clean -f, git branch -D, and git checkout .. - Use Case: A team lets Claude Code run autonomously on a repository but wants to guarantee it can never force-push to main or wipe uncommitted changes; this Skill enforces that policy at the tool level. ## Quick Start Ask Claude to set up Git guardrails that block dangerous commands like git push and git reset --hard for this project.

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?▼

Install a PreToolUse hook that intercepts Bash tool calls and matches them against a blocklist of patterns like git push and git reset --hard. When a match is found, the hook exits with code 2 and Claude receives a message that the command is not authorized.

How to prevent Claude Code from running git push?▼

Add a PreToolUse hook with a Bash matcher that runs a script checking the command against the pattern 'git push'. The script prints a BLOCKED message to stderr and exits with code 2, stopping the command before it executes.

Can I install Git safety hooks globally for all projects?▼

Yes. Place the hook script in ~/.claude/hooks/ and register it in ~/.claude/settings.json instead of the project-level .claude/settings.json. The hook then applies to every project where Claude Code runs.

Which Git commands does the guardrail block by default?▼

The default blocklist covers git push (including --force), git reset --hard, git clean -f and -fd, git branch -D, git checkout ., and git restore .. You can edit the script's DANGEROUS_PATTERNS array to add or remove entries.

Why is my Git hook not blocking commands in Claude Code?▼

Verify the script is executable with chmod +x and that the hook path in settings.json matches the actual script location. Test it by piping a JSON payload like {"tool_input":{"command":"git push origin main"}} into the script; it should exit with code 2.