git-guardrails-claude-code

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

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

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, git reset --hard, or git clean -fd, causing irreversible loss of work or unintended changes to remote repositories. This Skill installs a deterministic guard that intercepts and blocks such commands before they execute. ## Core Features & Use Cases - Pre-execution blocking: Installs a PreToolUse hook that intercepts Bash tool calls and blocks git push, git reset --hard, git clean -f/-fd, git branch -D, git checkout ., and git restore .. - Flexible scope: Supports project-level installation (.claude/settings.json) or global installation across all projects (~/.claude/settings.json). - Customizable blocklist: The shell script's pattern list can be edited to add or remove blocked 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 returns exit code 2 with a BLOCKED message whenever a dangerous pattern is detected. ## Quick Start Ask Claude to install git guardrails that 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 dangerous git commands in Claude Code?

Install a PreToolUse hook that matches the Bash tool and runs a guard script before each command. The script checks the command against patterns like git push and git reset --hard, exiting with code 2 to block execution when matched.

How to prevent Claude Code from running git push?

Register a PreToolUse hook in .claude/settings.json or ~/.claude/settings.json that invokes a blocking script. When Claude attempts git push, the script prints a BLOCKED message to stderr and exits with code 2, denying the action.

Can Claude Code hooks apply globally to all projects?

Yes. Place the hook script in ~/.claude/hooks/ and register it in ~/.claude/settings.json instead of the project-level settings file. The same PreToolUse matcher configuration then protects every project on the machine.

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

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

Common causes are a missing executable bit on the script (run chmod +x), an incorrect path in settings.json, or the hook being added outside the existing hooks.PreToolUse array. Test manually by piping a JSON payload with a git push command into the script and checking for exit code 2.