git-safety-guardrails
Skill8 starsChanged 2 months agoMITView on GitHub
Safeguard repositories against destructive, irreversible, or history-rewriting Git operations. Use when running force pushes, hard resets, branch deletions, cleans, destructive restores, or history re-writes — even if the user says \"clean up git history\". Do NOT use for routine safe git status, fetch, diff, or branch queries.
- Deletes or force-pushes
- Commits and pushes
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Scope Clarification: Always ask the user whether to apply guardrails locally to the project (.claude/settings.json) or globally …
- Distinctive: line 18
Mandatory Interception Test: Verify that the safety hook triggers correctly on simulated forbidden commands before concluding setup.
- Distinctive: line 45
Action: Ask the user whether to configure guardrails for this project only or globally.
- Very specific: line 46
Key Point: Default to project-level .claude/settings.json unless the user specifies global.
- Distinctive: line 51
Key Point: Ensure parent directories exist before copying.
- Very specific: line 58
Action: Add the PreToolUse hook entry to .claude/settings.json, merging into existing arrays if present.
- Very specific: line 59
Key Point: Use "$CLAUDE_PROJECT_DIR"/.claude/hooks/block-dangerous-git.sh path expansion.
- Distinctive: line 63
Action: Test the hook with a simulated blocked command:
- Distinctive: line 67
Key Point: Verify that the command exits with code 2 and outputs a descriptive blocked message.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Safety Guardrails
Install and maintain deterministic pre-execution guardrails that intercept and block dangerous, destructive, or history-rewriting Git commands before autonomous agents can execute them.
Core Invariants
- Deterministic Interception: Automatically block destructive Git commands (
git push --force,git reset --hard,git clean -f/-fd,git branch -D,git checkout .,git restore .) before execution. - Explicit Authority Gate: Intercepted commands return an explicit non-zero exit code notifying the agent that it lacks authority to execute destructive operations.
- Scope Clarification: Always ask the user whether to apply guardrails locally to the project (
.claude/settings.json) or globally (~/.claude/settings.json). - Settings Merge Safety: Seamlessly merge guardrail hooks into existing
PreToolUseconfigurations without overwriting other tools or settings. - Mandatory Interception Test: Verify that the safety hook triggers correctly on simulated forbidden commands before concluding setup.
Architecture & Map of Content (MOC)
[ Agent Tool Call (Bash/Git) ] ──► [ PreToolUse Hook: `block-dangerous-git.sh` ]
│
┌─────────────────────────┴─────────────────────────┐
▼ ▼
[ Safe Git Operation ] [ Destructive Command ]
- `git status`, `git diff` - `git push --force`, `reset --hard`
- ALLOWED to execute - BLOCKED (Exit Code 2)| Component | Responsibility | Location |
| Classifier Hook Script | Inspect and block forbidden git patterns | scripts/block-dangerous-git.sh |
| Python Command Parser | Parse complex shell command chains | scripts/classify_git_command.py |
| Settings Integration | Hook registration in agent environment | .claude/settings.json or ~/.claude/settings.json |
Step-by-Step Procedure (TWI)
Step 1: Confirm Guardrail Scope
- Action: Ask the user whether to configure guardrails for this project only or globally.
- Key Point: Default to project-level
.claude/settings.jsonunless the user specifies global. - Why: Scoped installation avoids unexpected side-effects across external personal repositories.
Step 2: Copy Hook Script & Make Executable
- Action: Copy
scripts/block-dangerous-git.shto.claude/hooks/block-dangerous-git.shand runchmod +x. - Key Point: Ensure parent directories exist before copying.
- Inline Checklist:
- Target directory created
- Script copied and executable permissions set (
chmod +x) - Python classifier script colocated if needed
Step 3: Register Hook in Settings Configuration
- Action: Add the PreToolUse hook entry to
.claude/settings.json, merging into existing arrays if present. - Key Point: Use
"$CLAUDE_PROJECT_DIR"/.claude/hooks/block-dangerous-git.shpath expansion. - Why: Relative path expansions ensure the hook functions across different working directory contexts.
Step 4: Verify Guardrail Interception (Test Gate)
- Action: Test the hook with a simulated blocked command:
echo '{"tool_input":{"command":"git push origin main --force"}}' | .claude/hooks/block-dangerous-git.sh - Key Point: Verify that the command exits with code 2 and outputs a descriptive blocked message.
- Why: Proving the hook intercepts dangerous commands guarantees that unverified agents cannot accidentally wipe Git history.
Anti-Rationalization Guardrails
| Tempting Rationalization | Binding Rule | Engineering Rationale |
"Allow git reset --hard if the working tree has uncommitted bugs." | Block all hard resets; require explicit stashes or reverts. | Hard resets permanently delete uncommitted code and worktree context. |
| "Allow force pushes on feature branches." | Block all force pushes by default. | Force pushing can overwrite teammate commits and destroy branch history. |
| "Skip verifying the hook script with simulated input." | Mandatory simulated test pass. | Syntax errors in hook scripts cause them to fail open, leaving the repo unprotected. |
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- shalomb/agent-skills★ 3same 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 repository42 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ai-data-remediationSkill
- ai-engineeringSkill
- codebase-designSkill
- code-reviewSkill
- diagnosing-bugsSkill
- domain-modelingSkill
- engineering-workflow-guideSkill
- goalSkill
- grillingSkill
- grill-meSkill
- grill-with-docsSkill
- handoffSkill
- implementSkill
- implement-specSkill
- improve-codebase-architectureSkill
- j-spaceSkill
- migrate-to-shoehornSkill
- ml-best-practicesSkill
- prototypeSkill
- researchSkill
- resolving-merge-conflictsSkill
- retroSkill
- scaffold-exercisesSkill
- setup-engineering-workflowsSkill
- setup-pre-commitSkill
- setup-ts-deep-modulesSkill
- skill-conductorSkill
- tddSkill
- teachSkill
- to-questionnaireSkill
- to-specSkill
- to-ticketsSkill
- triageSkill
- wait-whatSkill
- wayfinderSkill
- wizardSkill
- workflow-designerSkill
- writing-beatsSkill
- writing-for-agentsSkill
- writing-fragmentsSkill
- writing-shapeSkill
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.

