git-guardrails-claude-code

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

Updated May 7, 2026
One-click install
npx skills add https://github.com/hgxszhj/mattpocock_skills --skill git-guardrails-claude-code-hgxszhj
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/hgxszhj/mattpocock_skills/tree/main/skills/misc/git-guardrails-claude-code
Command: npx skills add https://github.com/hgxszhj/mattpocock_skills --skill git-guardrails-claude-code-hgxszhj

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them. This guards against destructive git operations during Claude Code sessions.

Core Features & Use Cases

  • Blocks dangerous commands like git push, git reset --hard, git clean, git branch -D, and git checkout/restore to prevent accidental destructive actions.
  • Provides guidance to install the hook either per-project (.claude/settings.json) or globally (~/.claude/settings.json) and to verify the protection.
  • Includes a ready-to-use script (scripts/block-dangerous-git.sh) and a simple verification workflow.

Quick Start

Copy the bundled script to the target location (.claude/hooks for project scope or ~/.claude/hooks for global scope), update the appropriate Claude settings.json to reference the block-dangerous-git.sh script, then verify by attempting a blocked command.

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 like git push or reset --hard in Claude Code?

You can block dangerous git commands in Claude Code by installing a PreToolUse hook that intercepts operations like git push and git reset --hard. The hook enforces guardrails by running a shell script before tool execution.

Can I set up git hooks globally for all my Claude Code projects?

Yes, you can configure git hooks globally for Claude Code projects by copying the block-dangerous-git.sh script to ~/.claude/hooks and updating the global ~/.claude/settings.json to register the PreToolUse hook.

What specific destructive git operations does a PreToolUse hook prevent?

A PreToolUse hook prevents destructive git operations including git push, git reset --hard, git clean, git branch -D, and git checkout/restore, stopping them before execution during Claude Code sessions.

Do I need jq to configure git guardrails in Claude Code?

Yes, jq is required as a dependency to set up git guardrails in Claude Code. You need jq installed in your environment to run the bundled block-dangerous-git.sh script effectively.

How do I verify that my Claude Code git guardrails are working?

To verify git guardrails are working in Claude Code, attempt to run a blocked command like git reset --hard. The PreToolUse hook should intercept and block the operation before it executes.

What is the best way to prevent accidental git clean during AI development sessions?

The best way to prevent accidental git clean during AI development is implementing a PreToolUse hook guardrail. This intercepts the command in Claude Code before execution, blocking destructive actions automatically.