git-guardrails-claude-code
/git-guardrails-claude-code
Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.
- Author
- stevesolun ↗
- Repository
- ctx ↗
- Licence
- MIT
- Last repository change
- 21.08.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 1
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 21.08.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
- 1 scripts in this package. Review them before installing, as Claude may execute them.
Scripts: scripts/block-dangerous-git.sh
What it does and when to use it
Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.
Original author description
Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.
How it works
- What Gets Blocked
- Steps
SKILL.md preview
---
name: git-guardrails-claude-code
description: Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.
---
# Setup Git Guardrails
Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them.
## What Gets Blocked
- `git push` (all variants including `--force`)
- `git reset --hard`
- `git clean -f` / `git clean -fd`
- `git branch -D`
- `git checkout .` / `git restore .`
When blocked, Claude sees a message telling it that it does not have authority to access these commands.
## Steps
### 1. Ask scope
Ask the user: install for **this project only** (`.claude/settings.json`) or **all projects** (`~/.claude/settings.json`)?
### 2. Copy the hook script
The bundled script is at: [scripts/block-dangerous-git.sh](scripts/block-dangerous-git.sh)
Copy it to the target location based on scope:
- **Project**: `.claude/hooks/block-dangerous-git.sh`
- **Global**: `~/.claude/hooks/block-dangerous-git.sh`
Make it executable with `chmod +x`.
### 3. Add hook to settings
Add to the appropriate settings file:
**Project** (`.claude/settings.json`):
```json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
}
]
}
]
}
}
```
**Global** (`~/.claude/settings.json`):
```json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/block-dangerous-git.sh"
}
]
}
]
}
}
```
If the settings file already exists, merge the hook into existing `hooks.PreToolUse` array — don't overwrite other settings.
### 4. Ask about customization
Ask if user wants to add or remove any patterns from the blocked list. Edit the copied script accordingly.
### 5. Verify
Run a quick test:
```bash
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>
```
Should exit with code 2 and print a BLOCKED message to stderr.
Files in this package (2)
- SKILL.md 2 KB
- scripts/block-dangerous-git.sh 1 KB
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · stevesolun/ctx | 100 | MIT |
| mattpocock/skills | 100 | MIT |
| soultech-oh-ux/goodseed | 100 | MIT |
| sideshowroberto/vfx-agent-toolkit | 100 | MIT |
| akillness/jeo-skills | 95 | MIT |
Database snapshot: 13.11.2026 · package version 146bb85ecdb5 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100git-guardrails
Install a hook, for one project or for every project, that blocks destructive git commands before an agent runs them: git push, force push, reset --hard, clean -f, branch -D, checkout . and restore . Claude Code's PreToolUse hook is the worked example. Use when the user wants to… - 90git-safety
Git safety rules. INVOKE WHEN: git push, force push, git reset, git clean, destructive git, push force, reset hard. NEVER force push or do destructive git operations. - 100git-guardrails
Install a hook that blocks destructive git commands before an AI agent runs them. Use when an agent force-pushed or ran reset --hard, when adding git safety hooks, or when protecting main from agent pushes. - 100git-guardrails
Use when you want mechanical, non-bypassable enforcement of git safety rules — a PreToolUse hook that blocks force-push, reset --hard, clean -f, branch -D, checkout ./-f, switch --discard-changes, restore ., worktree remove --force, git add -A/., and --no-verify before they run.… - 100git-guardrails
Install a PreToolUse hook that vetoes destructive git: no-verify, branch -D, clean -f, reset --hard, history rewrite, force-push. Meant for any repo or agent that the hub guard misses. Use it to protect a project from destructive git, or to enforce no-force-push outside the hub, at the tool layer. - 100git-guard
Ask before a destructive git write and summarize the diff first. Use before git push --force, git push --force-with-lease, push or amend of main, master, or release/*, git push --delete, git push origin :branch, git reset --hard, git clean -fdx, git filter-repo, git remote…