git-guardrails-claude-code

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

2|Updated Jul 6, 2026
One-click install
npx skills add https://github.com/NAMEWTA/learning-open-code --skill git-guardrails-claude-code-namewta
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-guardrails-claude-code
Source: https://github.com/NAMEWTA/learning-open-code/tree/main/translator/open-ai-skills/matt-pocock-skills/skills/misc/git-guardrails-claude-code
Command: npx skills add https://github.com/NAMEWTA/learning-open-code --skill git-guardrails-claude-code-namewta

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, git reset --hard, or git clean -fd that permanently destroy work. This Skill installs a safety hook that intercepts and blocks these commands before they run. ## Core Features & Use Cases - Pre-execution Interception: Registers a PreToolUse hook that inspects every Bash command and blocks dangerous git operations with exit code 2 and a clear BLOCKED message. - Flexible Scope: Installs at project level (.claude/settings.json) or globally (~/.claude/settings.json) depending on user preference. - Customizable Blocklist: The bundled shell script's pattern list can be edited to add or remove blocked commands. - Use Case: A developer lets Claude Code run autonomously on a repository but wants to guarantee it can never force-push to main or hard-reset uncommitted changes. ## Quick Start Set up a Claude Code hook that blocks 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?

Register a PreToolUse hook in .claude/settings.json that runs a bash script matching the Bash tool. The script parses the command with jq, checks it against dangerous patterns like git push and git reset --hard, and exits with code 2 to block execution.

How to prevent Claude Code from running git push or git reset --hard?

Install a PreToolUse hook script that greps the incoming command for patterns like git push, reset --hard, clean -fd, and branch -D. When matched, it prints a BLOCKED message to stderr and exits with code 2, denying the command.

Can Claude Code hooks be installed globally for all projects?

Yes, hooks can be registered in ~/.claude/settings.json with the script placed in ~/.claude/hooks/ to apply across all projects. Project-level installation uses .claude/settings.json and .claude/hooks/ instead.

What dependencies does a Claude Code PreToolUse hook script need?

The hook script requires bash and jq to parse the JSON tool input from stdin. Both must be available on the system PATH, and the script file must be made executable with chmod +x.

Why is my Claude Code hook not blocking git commands?

Common causes include the script lacking execute permission, incorrect JSON structure in settings.json, or the hook command path being wrong. Test by piping a sample JSON payload like a git push command directly into the script and checking for exit code 2.