Installs Claude Code PreToolUse safeguards against destructive Git commands; use to protect repositories, not for general Git workflow guidance.
Scanned 9/11/2026
Install to Claude Code
npx -y skills add akillness/jeo-skills --skill git-guardrails-claude-code --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Git Guardrails Claude Code?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/akillness-git-guardrails-claude-code)More formats (shields.io, HTML) on the badges page.
---
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.
allowed-tools: Read Grep Glob Bash Write Edit
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.
metadata:
tags: git, safety, hooks, destructive-operations, guardrails, claude-code
platforms: Claude
version: "1.0"
source: mattpocock/skills
---
# 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):
```bash
mkdir -p .claude/hooks
```
**Global** (for all Claude Code sessions):
```bash
mkdir -p ~/.claude/hooks
```
### Step 2 — Create the blocking script
Save as `.claude/hooks/git-guardrails.sh` (or `~/.claude/hooks/git-guardrails.sh`):
```bash
#!/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
```
```bash
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):
```json
{
"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
```bash
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:
```bash
# 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`
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!