git-guardrails-claude-code

Block destructive git commands in Claude Code via PreToolUse hook scripts.

12|Updated Dec 25, 2024
One-click install
npx skills add https://github.com/whyte25/reusables --skill git-guardrails-claude-code-whyte25
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/whyte25/reusables/tree/main/.agents/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/whyte25/reusables --skill git-guardrails-claude-code-whyte25

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

It prevents accidental or destructive git operations executed by Claude Code, reducing the risk of repository damage during automated command runs.

Core Features & Use Cases

  • PreToolUse safety hook: Intercepts Claude Code tool commands and blocks dangerous git actions before they execute.
  • Targeted command pattern blocking: Covers destructive operations like git push (including force), reset --hard, git clean, branch -D, and destructive checkout/restore patterns.
  • Project-safe or global scope: Lets you install the guardrails for a single project or across all Claude Code projects.

Quick Start

Install the hook for this project only by placing scripts/block-dangerous-git.sh at .claude/hooks/block-dangerous-git.sh, making it executable, and adding it to .claude/settings.json under hooks.PreToolUse for Bash commands.

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 in Claude Code?

Block destructive git commands in Claude Code by installing a PreToolUse hook script that intercepts Bash tool inputs, matches dangerous patterns like git push or reset --hard, and exits nonzero to halt execution.

What git commands should safety guardrails intercept during automated version control?

Safety guardrails should intercept destructive automated version control actions including force pushes, hard resets, git clean, branch deletion, and checkout or restore operations that overwrite workspace contents.

How does a PreToolUse hook prevent accidental repository damage?

A PreToolUse hook prevents accidental repository damage by parsing tool_input.command before execution, matching it against dangerous git patterns, and outputting a clear blocked message to stderr if a match is found.

Can I apply git safety guardrails globally across all Claude Code projects?

You can apply git safety guardrails globally across all Claude Code projects or scope them to a single project by configuring the hook script placement and settings.json accordingly.

Do I need jq and grep to run command blocking hooks for git?

Yes, you need jq and grep installed because the command blocking hook script relies on them to parse the JSON tool input and match dangerous git command patterns.

What's the best way to stop force pushes and hard resets in automated devops workflows?

The best way to stop force pushes and hard resets in automated devops workflows is deploying a PreToolUse hook that scans Bash commands for destructive git patterns and blocks execution before it starts.