git-guardrails-claude-code

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

Updated Jun 24, 2026
One-click install
npx skills add https://github.com/kashman001/ai-workspace-template --skill git-guardrails-claude-code-kashman001
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/kashman001/ai-workspace-template/tree/main/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/kashman001/ai-workspace-template --skill git-guardrails-claude-code-kashman001

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? AI coding agents 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: Registers a PreToolUse hook that inspects every Bash command Claude Code attempts to run. - Dangerous Pattern Blocking: Blocks git push (including --force), git reset --hard, git clean -f/-fd, git branch -D, and git checkout/restore of the working tree. - Flexible Scope: Installs per-project (.claude/settings.json) or globally (~/.claude/settings.json), with a customizable blocklist. - Use Case: A team lets Claude Code autonomously edit and commit code, but wants to guarantee it can never force-push to main or wipe uncommitted changes during a session. ## Quick Start Ask Claude Code 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 git push in Claude Code?▼

Install a PreToolUse hook that runs a bash script checking each Bash command against dangerous patterns like git push. When matched, the script exits with code 2 and Claude receives a blocked message instead of executing the command.

How do I add a PreToolUse hook to Claude Code settings?▼

Add a hooks.PreToolUse array entry with matcher "Bash" and a command pointing to your hook script in .claude/settings.json for project scope or ~/.claude/settings.json for global scope. Merge it into existing settings rather than overwriting them.

Which git commands does the guardrails hook block?▼

The hook blocks git push (including --force), git reset --hard, git clean -f and -fd, git branch -D, and git checkout . or git restore . that discard working tree changes. You can edit the script's pattern list to customize it.

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

Why is the git guardrails hook not blocking commands?▼

Common causes are the script missing executable permission (run chmod +x), an incorrect path in settings.json, or jq not being installed since the script uses jq to parse the tool input JSON. Test by piping a sample command JSON into the script.