git-guardrails-claude-code

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

2|Updated May 12, 2026
One-click install
npx skills add https://github.com/tajo9128/BioDockify-Pharma-AI --skill git-guardrails-claude-code-tajo9128
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/tajo9128/BioDockify-Pharma-AI/tree/main/.agents/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/tajo9128/BioDockify-Pharma-AI --skill git-guardrails-claude-code-tajo9128

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? AI coding assistants can execute destructive git operations like force pushes, hard resets, and branch deletions that permanently destroy work. This Skill installs a safety hook that intercepts and blocks these commands before they run. ## Core Features & Use Cases - Command Interception: A PreToolUse hook inspects every Bash command and blocks git push, git reset --hard, git clean -f/-fd, git branch -D, and git checkout/restore of the working tree. - Flexible Scope: Install the guardrail for a single project (.claude/settings.json) or globally across all projects (~/.claude/settings.json). - 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 autonomously refactor a repository and wants to guarantee it can never force-push to main or wipe uncommitted changes. ## Quick Start Set up git guardrails in Claude Code to 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 runs a bash script inspecting every Bash tool call. The script matches commands against patterns like git push and git reset --hard, exiting with code 2 to block execution and printing a message to stderr.

How to set up a PreToolUse hook in Claude Code settings?

Add a hooks.PreToolUse entry to .claude/settings.json with matcher set to Bash and a command pointing to your hook script. For project scope use .claude/settings.json; for all projects use ~/.claude/settings.json.

Which git commands does the guardrail script block?

The script blocks git push (including --force), git reset --hard, git clean -f and -fd, git branch -D, and git checkout . or git restore . which discard working tree changes. You can edit the DANGEROUS_PATTERNS array to customize the list.

Can I apply git safety hooks to all projects at once?

Yes, copy the hook script to ~/.claude/hooks/ and register it in ~/.claude/settings.json instead of the project-level file. The hook then intercepts dangerous git commands in every Claude Code session.

Why is my Claude Code hook not blocking git push?

Verify the script is executable with chmod +x and that the settings.json path matches the actual script location. Test manually by piping a JSON payload like {"tool_input":{"command":"git push"}} into the script; it should exit with code 2.