git-guardrails
Skill1 starsChanged 7 months agoMITView on GitHub
Install a Claude Code PreToolUse hook that blocks dangerous git operations (force push, reset --hard, clean -f, branch -D, checkout ., restore .) before they execute. Use when setting up git safety hooks or preventing destructive git commands in Claude Code.
- Deletes or force-pushes
- Commits and pushes
9 other projects use a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- apravint/iram-ostheir own version, first seen Nov 8, 2026
- christofferbergj/agent-skillstheir own version, first seen Nov 1, 2026
- aveproject/avetheir own version, first seen Oct 31, 2026
- ethanfoell/skillstheir own version, first seen Oct 20, 2026
- DROOdotFOO/agent-skillstheir own version, first seen Sep 1, 2026
- karthikrshet/aiskillstheir own version, first seen Aug 20, 2026
Used with
Projects with it also use zoom-out and code-review.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
victorgarciaesgiSkillzoom-out
Tell the agent to zoom out and give broader context or a higher-level perspective. Use when you're unfamiliar with a section of code or need to understand how it fits into the bigger picture.
Also in 3 projects that use this
GoogleSkillcode-review
Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.
Also in 4 projects that use this
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 1
- Code-Shock/claude-skills★ 510% same
Wrote their own version · 8
- aveproject/ave★ 24same name
- uwvwko-zzz/mattpocock-skills-openclaw★ 9same name
- apravint/iram-os★ 7same name
- karthikrshet/aiskills★ 4same name
- christofferbergj/agent-skills★ 1same name
- DROOdotFOO/agent-skills★ 1same name
- ethanfoell/skills★ 0same name
- saeed-vayghan/mitra★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository206 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- project-healthSkill
- skill-validatorSkill
- accessibilitySkill
- agent-debugSkill
- agent-evaluateSkill
- ai-governanceSkill
- ai-system-reviewSkill
- api-docs-generateSkill
- api-examplesSkill
- api-mockSkill
- api-test-generateSkill
- api-validateSkill
- architecture-diagramSkill
- ask-mattSkill
- assumption-mapSkill
- boilerplateSkill
- brainstormSkill
- branch-finishSkill
- briefingSkill
- browser-testing-with-devtoolsSkill
- bundle-analyzeSkill
- cache-strategySkill
- canarySkill
- carefulSkill
- cavemanSkill
- changelog-autoSkill
- chaos-testSkill
- ci-setupSkill
- ci-sweepSkill
- cleanprojectSkill
- click-path-auditSkill
- codebase-designSkill
- code-review-checklistSkill
- code-tourSkill
- commitSkill
- completion-verifySkill
- complexity-reduceSkill
- component-librarySkill
- config-cleanupSkill
- config-generateSkill
- conflict-resolveSkill
- container-optimizeSkill
- context-budgetSkill
- context-engineeringSkill
- context-restoreSkill
- context-saveSkill
- continuous-learningSkill
- contributingSkill
- cost-trackSkill
- councilSkill
- create-todosSkill
- cross-modal-reviewSkill
- database-connectSkill
- db-diagramSkill
- ddd-modelSkill
- debug-root-causeSkill
- debug-sessionSkill
- debug-systematicSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.
0
Common
Most of the 9 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 70
Read or create the settings file, then add the hook:
“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Guardrails
Install a PreToolUse hook in Claude Code that intercepts and blocks dangerous git operations before they run.
Arguments: $ARGUMENTS - global to install in ~/.claude/settings.json, or blank for project-level .claude/settings.json
Behavior
1. Determine Scope
if [[ "$ARGUMENTS" == "global" ]]; then
SETTINGS="$HOME/.claude/settings.json"
HOOKS_DIR="$HOME/.claude/hooks"
else
SETTINGS=".claude/settings.json"
HOOKS_DIR=".claude/hooks"
fi
mkdir -p "$HOOKS_DIR"2. Create the Block Script
cat > "$HOOKS_DIR/block-dangerous-git.sh" << 'SCRIPT'
#!/bin/bash
set -e
input=$(cat)
command=$(echo "$input" | jq -r '.command // empty')
# Only check Bash tool calls
[ -z "$command" ] && exit 0
dangerous_patterns=(
"git push"
"push --force"
"git reset --hard"
"reset --hard"
"git clean -fd"
"git clean -f"
"git branch -D"
"git checkout \."
"git restore \."
)
for pattern in "${dangerous_patterns[@]}"; do
if echo "$command" | grep -E "$pattern" > /dev/null 2>&1; then
echo "BLOCKED: '$command' matches dangerous pattern '$pattern'. The user has prevented this operation." >&2
exit 2
fi
done
exit 0
SCRIPT
chmod +x "$HOOKS_DIR/block-dangerous-git.sh"
echo "Hook script created: $HOOKS_DIR/block-dangerous-git.sh"3. Register in Claude Code Settings
Read or create the settings file, then add the hook:
# Read existing settings or start fresh
if [ -f "$SETTINGS" ]; then
CURRENT=$(cat "$SETTINGS")
else
CURRENT='{}'
fi
# Use jq to safely add the PreToolUse hook (preserves existing config)
HOOK_PATH="$(pwd)/$HOOKS_DIR/block-dangerous-git.sh"
[[ "$ARGUMENTS" == "global" ]] && HOOK_PATH="$HOME/.claude/hooks/block-dangerous-git.sh"
echo "$CURRENT" | jq \
--arg hook "$HOOK_PATH" \
'.hooks.PreToolUse += [{"matcher": "Bash", "hooks": [{"type": "command", "command": $hook}]}]' \
> "$SETTINGS"
echo "Hook registered in: $SETTINGS"4. Verify
# Test the script directly
echo '{"command": "git push origin main"}' | bash "$HOOKS_DIR/block-dangerous-git.sh"
# Should exit 2 and print BLOCKED message to stderr
echo '{"command": "git status"}' | bash "$HOOKS_DIR/block-dangerous-git.sh"
# Should exit 0 (allowed)5. Report
Git guardrails installed:
Hook script: .claude/hooks/block-dangerous-git.sh
Settings: .claude/settings.json
Scope: project
Blocked operations:
git push / push --force
git reset --hard
git clean -f / -fd
git branch -D
git checkout . / git restore .
To customize: edit .claude/hooks/block-dangerous-git.sh
To test: echo '{"command": "git push"}' | bash .claude/hooks/block-dangerous-git.sh
To remove: delete the hook entry from .claude/settings.jsonBlocked Operations
| Pattern | Why dangerous |
git push / push --force | Overwrites remote history; hard to recover from |
git reset --hard | Discards uncommitted work permanently |
git clean -f / -fd | Deletes untracked files/dirs permanently |
git branch -D | Deletes branch without merge check |
git checkout . / git restore . | Discards all working tree changes |
Customization
Edit the dangerous_patterns array in the hook script to add or remove patterns. The script uses grep -E for matching, so regex patterns are supported.
Examples
/git-guardrails ← project-level (.claude/settings.json)
/git-guardrails global ← user-level (~/.claude/settings.json)Edge Cases
jqnot installed: Reports the required JSON change to make manually- Hook already exists: Detects duplicate matcher and skips re-adding
- Global scope: Uses
~/.claude/paths instead of project-local
Token Optimization
Expected range: 300–500 tokens
Early exit: Detects if hook already registered in settings before making changes.
Template-based: Script content is fixed — no LLM generation needed.
Patterns used: Early exit, template-based generation, Bash for system queries
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

