git-guardrails-claude-code

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Claude Code environments are at risk of destructive git operations. This Skill blocks dangerous git commands before Claude executes them, reducing accidental data loss and workflow disruption.

Core Features & Use Cases

  • PreToolUse Guard: installs a predefined hook that blocks risky commands such as git push (including --force), git reset --hard, git clean, and git branch -D.
  • Scope configurability: supports per-project installation (into .claude/hooks) or global installation (into ~/.claude/hooks).
  • Feedback and verification: prints a BLOCKED message to stderr and exits with code 2 when a command is blocked.

Quick Start

Copy the bundled script to the target location and make it executable.

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 git push --force in Claude Code?

You can block dangerous git commands in Claude Code by installing a PreToolUse hook that detects risky operations and returns a BLOCKED response. This prevents destructive actions like git push --force, git reset --hard, and git clean before execution.

What destructive git operations should be blocked in automated coding environments?

Destructive git operations that should be blocked include git push --force, git reset --hard, git clean, and git branch -D. Blocking these commands prevents accidental data loss and workflow disruption in automated environments.

How do I set up a PreToolUse hook to prevent risky git actions?

To set up a PreToolUse hook, copy the bundled script to your target hook location (.claude/hooks for per-project or ~/.claude/hooks for global) and make it executable. The hook will intercept and block specified risky git actions automatically.

Does the git guardrails hook require jq to function?

Yes, the git guardrails hook requires jq to function properly. The jq dependency is necessary for the script to parse tool inputs and detect dangerous git commands within the Claude Code environment.

Can I configure git command blocking globally or per-project?

You can configure git command blocking either per-project or globally. Install the hook into .claude/hooks for project-specific scope, or into ~/.claude/hooks for global scope across all Claude Code environments.

How does Claude Code indicate that a blocked git command was intercepted?

Claude Code indicates an intercepted git command by printing a BLOCKED message to stderr and exiting with code 2. This feedback mechanism confirms that the PreToolUse hook successfully detected and stopped the dangerous operation.