git-guardrails-claude-code

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

1|Updated Jul 2, 2026
One-click install
npx skills add https://github.com/filippolmt/skills --skill git-guardrails-claude-code-filippolmt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/filippolmt/skills/tree/main/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/filippolmt/skills --skill git-guardrails-claude-code-filippolmt

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Claude Code can execute destructive git operations like git push --force, git reset --hard, or git clean -fd that permanently destroy work or overwrite remote history. This Skill installs a PreToolUse 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/-fd, git branch -D, git checkout ., and git restore . via a Bash hook script. - Flexible Scope: Installs the guardrail either per-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 lead wants Claude Code to never force-push to shared branches; after setup, any attempted git push exits with code 2 and a BLOCKED message. ## Quick Start Ask the assistant 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 the command against dangerous patterns. When a command like git push matches, the script exits with code 2 and Claude sees a BLOCKED message.

How to set up a PreToolUse hook in Claude Code settings?

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

Can I customize which git commands are blocked?

Yes, the hook script contains a DANGEROUS_PATTERNS array of grep patterns. Edit the copied script to add or remove entries such as git rebase or git commit --amend according to your needs.

Does the git guardrail hook work globally across all projects?

Yes, installing the script to ~/.claude/hooks and registering it in ~/.claude/settings.json applies the blocking to every project. Project-level installation in .claude/settings.json limits it to one repository.

Why is my git hook not blocking commands in Claude Code?

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