git-guardrails-claude-code

Block dangerous Git commands via a Claude Code PreToolUse hook.

1|Updated May 6, 2026
One-click install
npx skills add https://github.com/ThorStarlord/interface-skills --skill git-guardrails-claude-code-thorstarlord
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/ThorStarlord/interface-skills/tree/main/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/ThorStarlord/interface-skills --skill git-guardrails-claude-code-thorstarlord

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Prevents accidental or unsafe repository damage by blocking destructive Git commands that an AI agent might attempt during automated work.

Core Features & Use Cases

  • Claude Code PreToolUse guardrails: Intercepts Bash tool invocations and denies commands that match a dangerous pattern list.
  • Destructive action protection: Blocks high-risk operations such as git push (including force variants), git reset --hard, git clean -fd / git clean -f, git branch -D, and working-tree destructive checkout/restore patterns.
  • Safer agent collaboration: Helps users keep AI autonomy within approved boundaries so “fixing the code” doesn’t become “rewriting history” or wiping files.

Quick Start

Install the hook for this project only by copying scripts/block-dangerous-git.sh to .claude/hooks/block-dangerous-git.sh, making it executable, and wiring it into .claude/settings.json under hooks.PreToolUse for matcher "Bash".

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 destructive git commands executed by Claude Code?

You can block destructive git commands by installing a PreToolUse hook script that intercepts Bash tool inputs and denies risky patterns like force pushes, hard resets, and branch deletions before they run.

What git commands should I prevent AI agents from running in my repository?

Dangerous git commands to block include git push --force, git reset --hard, git clean -fd, git branch -D, and destructive checkout or restore operations that rewrite history or wipe untracked files.

How do I configure Claude Code settings to intercept unsafe Bash commands?

To intercept unsafe Bash commands, copy the hook script to .claude/hooks/, make it executable, and register it under hooks.PreToolUse with the Bash matcher in your .claude/settings.json file.

Can I use a PreToolUse hook to add DevOps guardrails for automated repository safety?

Yes, a PreToolUse hook adds DevOps guardrails by acting as a denylist-based safety gate that prevents automated AI agent actions from performing unauthorized repository damage.

Do I need jq installed to set up git guardrails for Claude Code?

Yes, jq is a required dependency for this git guardrail setup, as the hook script uses it to parse and evaluate the Bash command tool inputs intercepted during the PreToolUse event.