git-guardrails-claude-code

Block dangerous git commands via a PreToolUse hook in Claude Code settings.

1|Updated Feb 13, 2026
One-click install
npx skills add https://github.com/paialex/ai-skills-bank --skill git-guardrails-claude-code-paialex
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/paialex/ai-skills-bank/tree/main/mattpocock_skills/misc/git-guardrails-claude-code
Command: npx skills add https://github.com/paialex/ai-skills-bank --skill git-guardrails-claude-code-paialex

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Claude Code users can accidentally perform destructive git operations. This Skill provides guardrails that block dangerous commands before they execute, reducing the risk of data loss.

Core Features & Use Cases

  • PreToolUse hook that intercepts and blocks dangerous git commands before Claude runs them.
  • Supports project-scoped or global scope configuration to apply the guardrails.
  • Provides clear feedback when a blocked command is encountered, and guides installation steps.

Quick Start

Install the PreToolUse hook by copying the block-dangerous-git.sh script to the target location and updating the Claude settings for either the project or global scope.

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

You can block dangerous git commands by installing a PreToolUse hook that intercepts operations like git push, reset --hard, clean, and branch -D before execution. Copy the hook script, make it executable, and update your .claude/settings.json to enable it.

What git operations are intercepted by a PreToolUse hook?

A PreToolUse hook intercepts destructive git operations including git push, reset --hard, clean, branch -D, and checkout/restore. It aborts these unauthorized operations before Claude runs them, providing clear feedback when a blocked command is encountered.

Can I configure git guardrails globally or only for a specific project?

You can configure git guardrails in both project scope and global scope. Update the .claude/settings.json file for project-specific protection, or update ~/.claude/settings.json to apply the PreToolUse hook guardrails across all your Claude Code sessions.

Do I need jq to set up git command blocking in Claude Code?

Yes, jq is required as a dependency to set up this git command blocking mechanism. You need it installed in your environment before copying the block-dangerous-git.sh script and updating your settings configuration to enable the PreToolUse hook.

Why should I use a hook to prevent destructive git operations instead of manual checks?

Using a PreToolUse hook provides automated guardrails that intercept and abort dangerous git commands before execution, preventing accidental data loss. Unlike manual checks, it ensures destructive operations like reset --hard and clean are consistently blocked before Claude runs them.

What are the limitations of using a shell script to intercept git commands?

The shell script hook specifically targets predefined dangerous git commands like push, reset --hard, clean, branch -D, and checkout/restore. It requires manual installation steps including copying the script, making it executable, and updating settings files for either project or global scope.