git-guardrails-claude-code

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

28|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/NauelG/astro-blocks --skill git-guardrails-claude-code-nauelg
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/NauelG/astro-blocks/tree/main/.agents/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/NauelG/astro-blocks --skill git-guardrails-claude-code-nauelg

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 confirmation, risking irreversible loss of commits, branches, or uncommitted work. This Skill installs a guardrail that intercepts and blocks those commands before they run. ## Core Features & Use Cases - Pre-execution blocking: A PreToolUse hook intercepts Bash tool calls and rejects commands matching dangerous patterns such as git push, git reset --hard, git clean -f, git branch -D, and git checkout .. - Project or global scope: Install the hook into a single project's .claude/settings.json or globally in ~/.claude/settings.json for all projects. - Customizable blocklist: Edit the bundled shell script to add or remove blocked patterns to match your team's safety policy. - Use Case: A developer lets Claude Code refactor a repository autonomously but wants to guarantee it can never force-push to main or wipe uncommitted changes; the hook exits with code 2 and a BLOCKED message whenever such a command is attempted. ## 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. When a command like git push or git reset --hard matches, the script exits with code 2 and Claude receives a blocked message.

Which git commands does the guardrail block?▼

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 script's DANGEROUS_PATTERNS array 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 your machine.

What dependencies does the git guardrail hook need?▼

The hook script requires bash and jq to parse the JSON tool input from stdin. Both are standard on macOS and Linux; jq may need installation via a package manager on minimal systems.

How do I verify the git blocking hook works?▼

Pipe a test 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.