git-guardrails-claude-code

Block destructive git commands in Claude Code via PreToolUse hooks.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill prevents Claude Code from running destructive or dangerous git operations that can irreversibly alter or delete repository history and files.

Core Features & Use Cases

  • Safety hook via PreToolUse: Intercepts Claude Code tool invocations and blocks risky git commands before execution.
  • Command pattern blocking: Targets operations such as forced pushes, hard resets, aggressive cleans, branch deletion, and checkout/restore of the working tree.
  • Project- or global-scope installation: Lets you apply guardrails to a single repository or across all repositories on your machine.

Quick Start

Ask Claude Code to install Git Guardrails for this project only so it blocks dangerous commands inside .claude/settings.json.

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?

You can block destructive git commands by installing a PreToolUse hook script that intercepts Claude Code tool requests. This hook enforces a blocked-pattern list within your .claude/settings.json file to prevent risky operations before execution.

What git operations does a PreToolUse hook intercept?

A PreToolUse hook intercepts repository-affecting operations such as forced pushes, hard resets, aggressive cleans, branch deletion, and checking out or restoring paths in the working tree before Claude Code executes them.

Can I apply git safety guardrails to a single project instead of globally?

Yes, you can configure git safety guardrails for project-specific scope or globally across all repositories. Project scope applies settings within the local .claude/settings.json file, while global scope affects your entire machine.

Do I need jq and grep installed to use git guardrails?

Yes, the git guardrails hook script requires both jq and grep to be installed. These dependencies are used to parse tool request payloads and match blocked command patterns before execution.

How do I set up command pattern blocking for dangerous git operations?

To set up command pattern blocking, install the PreToolUse hook script and configure matcher-to-command routing in your .claude/settings.json file. This routes dangerous git operations to the blocked-pattern list for interception.

Why should I use a hook to prevent forced pushes instead of git configs?

A PreToolUse hook prevents Claude Code from autonomously executing destructive git commands like forced pushes or hard resets. Unlike standard git configs, it intercepts AI tool requests directly before execution to protect repository history.