Skip to content
OpenSmartRoute
Skillv1.0.0

git-guardrails-claude-code

Installs Claude Code PreToolUse safeguards against destructive Git commands; use to protect repositories, not for general Git workflow guidance.

by akillness(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from akillness/jeo-skills (.agent-skills/git-guardrails-claude-code/SKILL.md). Install upstream with npx skills add akillness/jeo-skills --skill git-guardrails-claude-code. Copyright stays with the author.

Git Guardrails for Claude Code

Prevent Claude Code from executing destructive git operations via PreToolUse hooks.

When to use this skill

  • Protecting critical repositories from accidental destructive git commands
  • Setting up safety nets before giving Claude Code broad git permissions
  • After an incident involving unintended git destructive operations

When not to use this skill

  • General git workflow guidance → use git-workflow
  • Non-Claude-Code platforms → hooks are Claude Code-specific

Blocked operations

The guardrail blocks:

  • git push --force / git push -f
  • git reset --hard
  • git clean -f / git clean -fd
  • git branch -D
  • git checkout -- . / git checkout -- <file>
  • git restore (destructive forms)

Installation

Step 1 — Choose scope

Project-level (recommended for critical repos):

mkdir -p .claude/hooks

Global (for all Claude Code sessions):

mkdir -p ~/.claude/hooks

Step 2 — Create the blocking script

Save as .claude/hooks/git-guardrails.sh (or ~/.claude/hooks/git-guardrails.sh):

#!/bin/bash
# Blocks destructive git operations

COMMAND="$1"

if echo "$COMMAND" | grep -qE 'git (push --force|push -f|reset --hard|clean -f|clean -fd|branch -D|checkout -- |restore )'; then
  echo "BLOCKED: Claude does not have authority to run destructive git operations."
  echo "Command attempted: $COMMAND"
  echo "If you need this operation, run it yourself in the terminal."
  exit 2
fi

exit 0
chmod +x .claude/hooks/git-guardrails.sh

Step 3 — Register the hook in settings

Add to .claude/settings.json (project) or ~/.claude/settings.json (global):

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/git-guardrails.sh"
          }
        ]
      }
    ]
  }
}

For global installation, use the full path: ~/.claude/hooks/git-guardrails.sh

Step 4 — Verify

echo "git reset --hard" | .claude/hooks/git-guardrails.sh
# Should exit with status 2 and print BLOCKED message

Customization

Edit the regex pattern in the script to add or remove blocked operations:

# Add git tag -d to blocked list:
grep -qE 'git (push --force|push -f|reset --hard|clean -f|clean -fd|branch -D|checkout -- |restore |tag -d)'

Instructions

  1. Identify the task trigger and expected output.
  2. Follow the workflow steps in this skill from top to bottom.
  3. Validate outputs before moving to the next step.
  4. Capture blockers and fallback path if any step fails.

Examples

  • Example: Apply this skill to a small scope first, then scale to full scope after validation passes.

Best practices

  • Keep outputs deterministic and auditable.
  • Prefer small reversible changes over broad risky edits.
  • Record assumptions explicitly.

References

  • Project standards: .agent-skills/skill-standardization/SKILL.md
  • Validator script: .agent-skills/skill-standardization/scripts/validate_skill.sh

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/akillness-jeo-skills-git-guardrails-claude-code/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

akillness-jeo-skills-git-guardrails-claude-code.ocm.jsonjson
{
  "ocm": "1",
  "id": "akillness-jeo-skills-git-guardrails-claude-code",
  "kind": "skill",
  "name": "git-guardrails-claude-code",
  "description": "Installs Claude Code PreToolUse safeguards against destructive Git commands; use to protect repositories, not for general Git workflow guidance.",
  "publisher": "akillness",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "git",
      "safety",
      "hooks",
      "destructive-operations",
      "guardrails",
      "claude-code",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Installs Claude Code PreToolUse safeguards against destructive Git commands; use to protect repositories, not for general Git workflow guidance."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/akillness/jeo-skills",
      "path": ".agent-skills/git-guardrails-claude-code/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/akillness/jeo-skills/blob/HEAD/.agent-skills/git-guardrails-claude-code/SKILL.md",
      "key": "akillness/jeo-skills/.agent-skills/git-guardrails-claude-code/SKILL.md"
    },
    "compatibility": "Claude Code only — uses Claude Code's PreToolUse hook system. Can be installed per-project (.claude/hooks/) or globally (~/.claude/hooks/). Pairs with git-workflow for safe branching practices.\n",
    "allowed_tools": [
      "Read",
      "Grep",
      "Glob",
      "Bash",
      "Write",
      "Edit"
    ]
  },
  "instructions": "# Git Guardrails for Claude Code\n\nPrevent Claude Code from executing destructive git operations via PreToolUse hooks.\n\n## When to use this skill\n\n- Protecting critical repositories from accidental destructive git commands\n- Setting up safety nets before giving Claude Code broad git permissions\n- After an incident involving unintended git destructive operations\n\n## When not to use this skill\n\n- General git workflow guidance → use `git-workflow`\n- Non-Claude-Code platforms → hooks are Claude Code-specific\n\n## Blocked operations\n\nThe guardrail blocks:\n- `git push --force` / `git push -f`\n- `git r",
  "cost": {
    "context_tokens": 769
  }
}

Fetch it by URL: GET /api/v1/registry/akillness-jeo-skills-git-guardrails-claude-code/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.