git-guardrails-claude-code

Installs a Claude Code PreToolUse hook that blocks dangerous git commands before execution.

Updated Sep 20, 2024
One-click install
npx skills add https://github.com/AnasIsmai1/dotfiles --skill git-guardrails-claude-code-anasismai1
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/AnasIsmai1/dotfiles/tree/main/agents/.agents/skills/git-guardrails-claude-code
Command: npx skills add https://github.com/AnasIsmai1/dotfiles --skill git-guardrails-claude-code-anasismai1

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Claude Code can execute destructive git commands like git push --force or git reset --hard that permanently lose work or overwrite remote history. This Skill installs a hook that intercepts and blocks those commands before they run. ## Core Features & Use Cases - PreToolUse Hook Installation: Copies a bash script into .claude/hooks/ and registers it in settings.json so it runs before every Bash tool call. - Dangerous Command Blocking: Blocks git push, git reset --hard, git clean -f/-fd, git branch -D, git checkout ., and git restore . by matching patterns against the command string. - Project or Global Scope: Installs per-project (.claude/settings.json) or globally (~/.claude/settings.json), merging into existing settings without overwriting other hooks. - Use Case: A team lets Claude Code run autonomously on a shared repo but wants to guarantee it can never force-push to main or wipe uncommitted changes. ## Quick Start Ask Claude to set up git guardrails that block dangerous git commands like push and reset --hard in this project.

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?▼

Install a PreToolUse hook that matches the Bash tool and runs a script checking each command against dangerous patterns like git push and git reset --hard. When a match is found, the script exits with code 2 and Claude sees a blocked message.

How do I add a PreToolUse hook to Claude Code settings?▼

Add a hooks.PreToolUse array entry in .claude/settings.json (project) or ~/.claude/settings.json (global) with matcher "Bash" and a command pointing to your hook script. Merge it into existing settings rather than overwriting other hooks.

Can I customize which git commands get blocked?▼

Yes. The hook script stores blocked patterns in a DANGEROUS_PATTERNS bash array. Edit the copied script to add or remove patterns, and the changes take effect on the next command without restarting anything.

Does the git blocking hook work globally across all projects?▼

Yes, if installed globally. Copy the script to ~/.claude/hooks/ and register it in ~/.claude/settings.json instead of the project-level settings file, and it will apply to every project.

Why is my Claude Code hook not blocking git push?▼

Verify the script is executable with chmod +x, that the settings.json path matches the actual script location, and that jq is installed since the script parses tool input with it. Test by piping a sample JSON command into the script and checking for exit code 2.