git-guardrails-claude-code

Block destructive git commands in Claude Code via PreToolUse hooks.

1|Updated May 7, 2026
One-click install
npx skills add https://github.com/Soham407/studio-kickstart --skill git-guardrails-claude-code-soham407
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/Soham407/studio-kickstart/tree/main/architecture/matt-pocock-git-guardrails-claude-code
Command: npx skills add https://github.com/Soham407/studio-kickstart --skill git-guardrails-claude-code-soham407

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill reduces the risk of accidental destructive git commands executed by Claude Code, protecting repositories from data loss and unwanted history changes.

Core Features & Use Cases

  • Blocks destructive git commands: Prevents git push (including forced pushes), git reset --hard, git clean -f/-fd, git branch -D, and risky restore/checkout patterns like git checkout . / git restore ..
  • Runs as a PreToolUse guardrail: Intercepts Bash tool commands so Claude Code receives an authority-denied message before execution.
  • Supports scoped installation: Installs per-project hooks via .claude/settings.json / .claude/hooks/ or globally via ~/.claude/settings.json / ~/.claude/hooks/.

Quick Start

Tell your AI assistant to install the git-guardrails-claude-code Skill for this project only by placing the hook at .claude/hooks/block-dangerous-git.sh and wiring it into the PreToolUse matcher for Bash in .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 prevent Claude Code from running destructive git commands like force push or hard reset?

To prevent destructive git commands in Claude Code, you can install a PreToolUse hook that intercepts Bash tool requests and blocks execution of commands like git push --force, git reset --hard, and git clean -f by exiting with code 2.

What git commands do safety guardrails typically block during AI-driven coding workflows?

Safety guardrails for git in AI workflows block destructive actions including forced pushes, hard resets, forceful cleaning, branch deletion, and unsafe checkout or restore patterns that overwrite uncommitted local changes.

Can I configure git safety hooks for Claude Code on a per-project basis?

Yes, you can install git safety hooks per-project by placing the shell script in .claude/hooks/ and wiring it into the PreToolUse matcher for Bash within the project's .claude/settings.json file.

How do PreToolUse hooks work to protect a repository from unwanted history changes?

PreToolUse hooks protect repositories by intercepting Bash commands before execution, matching dangerous git patterns, and returning an authority-denied exit code to block the action before Claude Code can run it.

Does git branch deletion and unsafe restore get blocked by Claude Code guardrails?

Yes, git guardrails block branch deletion commands like git branch -D and risky restore patterns such as git restore . or git checkout . to prevent accidental data loss during automated coding sessions.