git-guardrails-claude-code

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

Updated May 9, 2024
One-click install
npx skills add https://github.com/AceCodePt/dotfiles --skill git-guardrails-claude-code-acecodept
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/AceCodePt/dotfiles/tree/main/.config/opencode/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/AceCodePt/dotfiles --skill git-guardrails-claude-code-acecodept

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 without confirmation, risking irreversible loss of work or accidental changes to shared repositories. This Skill installs a guardrail that intercepts and blocks those commands before they run. ## Core Features & Use Cases - Pre-execution blocking: A PreToolUse hook intercepts Bash commands and blocks git push, git reset --hard, git clean -f, git branch -D, git checkout ., and git restore . before Claude executes them. - Flexible scope: Install the hook for a single project (.claude/settings.json) or globally across all projects (~/.claude/settings.json). - Customizable patterns: Edit the bundled shell script to add or remove blocked command patterns to match your team's safety policy. - Use Case: A developer lets Claude Code refactor and commit autonomously but wants to guarantee it can never force-push to main or wipe uncommitted changes. ## Quick Start Ask the assistant to set up git guardrails that block dangerous git commands like push and reset --hard in Claude Code 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 the 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 do I add a PreToolUse hook to Claude Code settings?▼

Add an entry to the hooks.PreToolUse array in .claude/settings.json with matcher set to Bash and a command pointing to your hook script. For global coverage, place the same configuration in ~/.claude/settings.json instead.

Which 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 .. You can edit the DANGEROUS_PATTERNS array in the script to customize the list.

Can I apply git safety hooks to all projects at once?▼

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

Why is my Claude Code hook not blocking commands?▼

Common causes are the script lacking execute permission (fix with chmod +x), an incorrect path in settings.json, or the hook entry being overwritten instead of merged into an existing PreToolUse array. Test by piping a sample JSON command into the script and checking for exit code 2.