git-guardrails-claude-code

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

2|Updated Oct 16, 2021
One-click install
npx skills add https://github.com/pattobrien/dotfiles --skill git-guardrails-claude-code-pattobrien
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/pattobrien/dotfiles/tree/main/.agents/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/pattobrien/dotfiles --skill git-guardrails-claude-code-pattobrien

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 or git reset --hard that permanently lose work or overwrite shared history. This Skill installs a safety hook that intercepts and blocks these commands before they run. ## 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 hook. - Flexible Scope: Installs the guardrail for a single 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. - Use Case: A team wants Claude Code to assist with commits and diffs but never push to remote or discard local changes; this Skill enforces that boundary automatically. ## 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 or ~/.claude/settings.json with a matcher for Bash and a command pointing to your hook script. The script receives tool input as JSON on stdin and blocks execution by exiting with code 2.

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 file. The global configuration then applies the guardrails to every project where Claude Code runs.

What git commands does the guardrail script block?▼

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

Why is my Claude Code hook not blocking commands?▼

Common causes include the script lacking execute permission (run chmod +x), an incorrect path in settings.json, or missing jq for JSON parsing. Test the script directly by piping a sample JSON command to it and checking for exit code 2.