git-guardrails-claude-code

Blocks dangerous git commands in Claude Code using a PreToolUse hook script.

Updated Jun 28, 2026
One-click install
npx skills add https://github.com/AO-HyS/aohys.com --skill git-guardrails-claude-code-ao-hys
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/AO-HyS/aohys.com/tree/main/.agents/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/AO-HyS/aohys.com --skill git-guardrails-claude-code-ao-hys

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? AI coding agents can execute destructive git commands like git push --force or git reset --hard without explicit user consent, risking irreversible repository damage. This Skill installs a guardrail that intercepts and blocks those 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 hook at project level (.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 run autonomously on a repository but wants to guarantee it can never force-push to main or wipe uncommitted work. ## Quick Start Ask the assistant 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 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. The script exits with code 2 to block execution and prints a message to stderr.

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 hook then applies to every Claude Code session on the machine.

What dependencies does the blocking script require?▼

The script requires bash, jq for parsing the JSON tool input, and grep for pattern matching. These are standard on macOS and Linux systems; jq may need installation on minimal environments.

Why is the hook not blocking git commands after setup?▼

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