git-guardrails-claude-code

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill prevents destructive git operations from running in Claude Code, reducing the risk of accidental data loss, force pushes, and repository damage.

Core Features & Use Cases

  • Dangerous Command Blocking: Stops commands such as push, reset --hard, clean -f, branch -D, checkout ., and restore . before execution.
  • Claude Code Hook Setup: Configures a PreToolUse hook for either a single project or all projects, with settings that can be merged safely into existing Claude configuration.
  • Customization and Verification: Lets you adjust the blocked patterns and verify the hook with a quick test that should return a blocked response.

Quick Start

Ask to install the git guardrails hook for either this project or all projects, and I will set up the Claude Code blocker for dangerous git commands.

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 like force push and hard reset in Claude Code?

To block dangerous git commands in Claude Code, you can install a PreToolUse hook that intercepts Bash commands and returns a BLOCKED message with exit code 2 before execution. This prevents force pushes, hard resets, and destructive cleans.

Can I customize which git commands are blocked during local development sessions?

Yes, you can customize blocked git patterns in the shell script. The setup lets you adjust patterns to stop commands like push, reset --hard, clean -f, branch -D, checkout ., and restore . before they execute.

How does a PreToolUse hook intercept Bash commands in Claude Code?

A PreToolUse hook intercepts Bash commands by integrating a shell script with Claude settings file configuration. When a command matches dangerous patterns, the script returns a BLOCKED message with exit code 2 to stop execution.

Do I need jq and grep to set up git command blocking in Claude Code?

Yes, you need jq and grep installed as dependencies to run the git command blocking hook. These tools process command pattern matching and settings file integration for the PreToolUse hook in Claude Code.

How do I verify that dangerous git command blocking is working in my repository?

To verify git command blocking, run a quick test with a dangerous command like reset --hard. The hook should intercept the Bash command and return a BLOCKED response with exit code 2, confirming your repository protection is active.

Can I apply git guardrails to a single project or all projects in Claude Code?

You can apply git guardrails to either a single project or all projects. The PreToolUse hook settings can be merged safely into existing Claude configuration, allowing flexible scope for repository protection during development.