git-guardrails-claude-code

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Blocks dangerous git operations within Claude Code workflows to prevent destructive commands from executing accidentally or maliciously.

Core Features & Use Cases

  • PreToolUse hook intercepts and blocks dangerous git commands before Claude runs them.
  • Blocks commands including git push (all variants including --force), git reset --hard, git clean -f / git clean -fd, git branch -D, and git checkout . / git restore .
  • Use Case: Protects repositories when agents or developers attempt high-risk actions, ensuring branch integrity and history while enabling safe automation.

Quick Start

Copy the guardrail script to the target environment and configure Claude to use the PreToolUse hook; then validate by attempting a blocked command to confirm the protection.

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

To block dangerous git commands in Claude Code, install a PreToolUse hook script that intercepts and prevents destructive operations like git push --force and git reset --hard before execution. This ensures branch integrity during automated workflows.

What destructive git operations does a pre-tool hook intercept?

A pre-tool hook intercepts destructive git operations including git push variants, git reset --hard, git clean -f, git branch -D, and git checkout . or git restore . to prevent accidental repository history loss or branch deletion.

Can I scope git guardrails to a specific project or apply them globally?

Yes, you can scope git guardrails per-project by configuring the PreToolUse hook in .claude/settings.json, or apply them globally across all workflows by deploying the script to ~/.claude/settings.json.

Do I need jq to install git safety hooks for Claude Code?

Yes, jq is required as a dependency to install and operate the git safety hooks for Claude Code, as the PreToolUse script relies on it to parse and process the hook configuration data effectively.

How do I validate that dangerous git operations are blocked?

To validate that dangerous git operations are blocked, attempt to execute a restricted command like git reset --hard after configuring the PreToolUse hook, and confirm the script intercepts and prevents the action successfully.

Why use a PreToolUse hook instead of standard git hooks for agent safety?

A PreToolUse hook provides agent safety by intercepting destructive git commands at the Claude Code application layer before they reach the terminal, preventing high-risk actions that standard git hooks cannot block during automated workflows.