git-guardrails-claude-code

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

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

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 runs them. ## Core Features & Use Cases - Command Interception: Blocks git push (including --force), git reset --hard, git clean -f/-fd, git branch -D, and git checkout/restore of the working tree via a bash hook script. - Flexible Scope: Installs the guardrail either per-project (.claude/settings.json) or globally (~/.claude/settings.json) for all projects. - Customizable Patterns: The blocked pattern list in the hook script can be edited to add or remove commands. - 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; the hook exits with code 2 and returns a BLOCKED message to the agent. ## Quick Start Ask the AI 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 to set up a PreToolUse hook in Claude Code settings?▼

Add a hooks.PreToolUse array entry to .claude/settings.json or ~/.claude/settings.json with matcher set to Bash and a command pointing to your hook script. Merge the entry into existing settings rather than overwriting other configuration.

Which git commands does the guardrail block?▼

The hook blocks git push (all variants including --force), git reset --hard, git clean -f and -fd, git branch -D, and git checkout . or git restore . which discard working tree changes. The pattern list can be customized by editing the script.

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

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

Why is my Claude Code hook not blocking commands?▼

The hook script must be executable (chmod +x) and requires jq to parse the JSON tool input. Verify the settings.json path matches the script location and test with a piped JSON payload to confirm it exits with code 2.