git-guardrails-claude-code

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

Updated Aug 11, 2026
One-click install
npx skills add https://github.com/Kunj-Sharma03/agent-contextify --skill git-guardrails-claude-code-kunj-sharma03
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/Kunj-Sharma03/agent-contextify/tree/main/skills-main/skills/misc/git-guardrails-claude-code
Command: npx skills add https://github.com/Kunj-Sharma03/agent-contextify --skill git-guardrails-claude-code-kunj-sharma03

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 explicit approval, risking irreversible repository damage. 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 bash hook script. - Flexible Scope: Installs the guardrail either per-project (.claude/settings.json) or globally across all projects (~/.claude/settings.json). - Customizable Patterns: Lets you add or remove blocked patterns by editing the copied hook script. - Use Case: A team using Claude Code on a shared repository wants to prevent the agent from force-pushing to main or wiping uncommitted work, so they install this hook at the project level. ## Quick Start Ask Claude to set up 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 script checking each command against dangerous patterns like git push and git reset --hard. Matching commands exit with code 2 and print a BLOCKED message to stderr.

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 install git guardrails globally for all Claude Code projects?

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

Which git commands does the guardrail hook block?

The script blocks git push (including --force), git reset --hard, git clean -f and -fd, git branch -D, git checkout ., and git restore . by matching regex patterns against the command string.

How do I customize the list of blocked git patterns?

Edit the DANGEROUS_PATTERNS array in the copied block-dangerous-git.sh script to add or remove grep-compatible patterns. The script requires jq to parse the tool input JSON from stdin.