git-guardrails-claude-code

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

10|3|Updated Jul 18, 2019
One-click install
npx skills add https://github.com/tanqimin/MyFavsORM --skill git-guardrails-claude-code-tanqimin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/tanqimin/MyFavsORM/tree/main/.agents/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/tanqimin/MyFavsORM --skill git-guardrails-claude-code-tanqimin

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 destroy work. 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, git branch -D, git checkout ., and git restore . via a PreToolUse Bash hook. - Flexible Scope: Installs the guardrail either per-project (.claude/settings.json) or globally (~/.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 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 Claude to set up git guardrails that block dangerous git commands 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 script checking each command against dangerous patterns. The hook exits with code 2 and prints a BLOCKED message to stderr when a command like git push or git reset --hard is detected.

Which git commands does the guardrail block?

It blocks git push (including --force), git reset --hard, git clean -f and -fd, git branch -D, git checkout ., and git restore .. The pattern list lives in the shell script and can be edited to add or remove entries.

Can I install the git hook globally for all projects?

Yes. Copy the script to ~/.claude/hooks/ and register it in ~/.claude/settings.json instead of the project-level .claude/settings.json. The global hook then applies to every project you open with Claude Code.

How do I test that the PreToolUse hook works?

Pipe a JSON payload like {"tool_input":{"command":"git push origin main"}} into the script. It should exit with code 2 and print a BLOCKED message to stderr; safe commands exit with code 0.

What are the limitations of pattern-based git command blocking?

The hook relies on grep pattern matching against the command string, so obfuscated or aliased commands may bypass it. It also requires jq to parse the JSON input and only intercepts commands run through Claude Code's Bash tool.