git-guardrails-claude-code

Configure Claude Code PreToolUse hooks to block destructive git commands before execution.

20|2|Updated May 16, 2026
One-click install
npx skills add https://github.com/reddb-io/red-skills --skill git-guardrails-claude-code-reddb-io
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/reddb-io/red-skills/tree/main/plugins/dev/skills/misc/git-guardrails-claude-code
Command: npx skills add https://github.com/reddb-io/red-skills --skill git-guardrails-claude-code-reddb-io

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? AI coding agents can run destructive git commands like git push, git reset --hard, or git clean -f without human approval, risking lost work or unwanted remote changes. This Skill installs a hook that intercepts and blocks those commands before they execute. ## Core Features & Use Cases - PreToolUse Hook Setup: Copies a bundled bash script and registers it in Claude Code settings, either per-project (.claude/settings.json) or globally (~/.claude/settings.json). - Dangerous Command Blocking: Blocks git push (including --force), git reset --hard, git clean -f/-fd, git branch -D, and git checkout ./git restore .. - Primary Branch Guard: When the dev plugin is enabled, blocks branch switching in the primary checkout while keeping commits, worktrees, and read-only git operations allowed. - Use Case: A team lets Claude Code run autonomously on a repository but wants to guarantee the agent can never force-push to main or wipe uncommitted changes. ## Quick Start Ask the AI 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 guard script before execution. The script inspects the command and exits with code 2 to block patterns like git push, reset --hard, and clean -f.

How to prevent an AI agent from running git push?▼

Register a PreToolUse hook in Claude Code settings.json that intercepts Bash commands and rejects any git push variant, including --force. The agent receives a message stating it lacks authority for that command.

Can I install git safety hooks globally for all projects?▼

Yes, the hook supports two scopes: project-level via .claude/settings.json or global via ~/.claude/settings.json. The hook block is identical; only the script path in the command differs.

Does the git guardrail hook block normal commits and worktrees?▼

No, git commit, git worktree add, read-only git operations, and registered worktrees under .red/tmp/worktrees remain allowed. Only destructive commands and primary-checkout branch switching are blocked.

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.