git-guardrails-claude-code

Configures Claude Code hooks to block dangerous git commands before execution.

1|Updated Jul 23, 2026
One-click install
npx skills add https://github.com/sanjanb/my-agent-harness --skill git-guardrails-claude-code-sanjanb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/sanjanb/my-agent-harness/tree/main/skills/mp-git-guardrails-claude-code
Command: npx skills add https://github.com/sanjanb/my-agent-harness --skill git-guardrails-claude-code-sanjanb

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? AI coding agents can execute destructive git commands like git push --force or git reset --hard without user consent, risking irreversible loss of work or unintended changes to remote repositories. ## Core Features & Use Cases - PreToolUse Hook Setup: Installs a bash hook that intercepts Bash tool calls and blocks dangerous git commands before they run. - Flexible Scope: Supports project-level installation (.claude/settings.json) or global installation (~/.claude/settings.json). - Customizable Blocklist: Blocks git push, git reset --hard, git clean -f/-fd, git branch -D, and git checkout ./git restore ., with the option to add or remove patterns. - Use Case: A developer lets Claude Code run autonomously on a repository but wants a hard guarantee that the agent can never force-push to main or wipe uncommitted changes. ## Quick Start Set up Claude Code hooks to 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 git push in Claude Code?

Install a PreToolUse hook that intercepts Bash tool calls and matches the command against dangerous patterns like git push. The hook script exits with code 2 and prints a BLOCKED message to stderr, preventing execution.

How to set up a PreToolUse hook in Claude Code settings?

Add a hooks.PreToolUse entry to .claude/settings.json or ~/.claude/settings.json 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 are blocked?

Yes, the hook script contains a DANGEROUS_PATTERNS array of grep patterns. Edit the copied script to add or remove patterns such as git rebase or git commit --amend according to your needs.

Does the git guardrails hook work globally across all projects?

Yes, installing the script to ~/.claude/hooks/ and registering it in ~/.claude/settings.json applies the blocking to every project. Project-level installation in .claude/ restricts it to a single repository.

Why is my Claude Code hook not blocking commands?

Common causes include the script lacking execute permission (run chmod +x), an incorrect path in settings.json, or the hook not being merged into the existing PreToolUse array. Test by piping a sample JSON command into the script and checking for exit code 2.