agentleFS
imMamdouhaboammarimMamdouhaboammar/matts-skills-into-chatgpt/skills/git-safety-guardrails/SKILL.md

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
  1. Very specific:

    Scope Clarification: Always ask the user whether to apply guardrails locally to the project (.claude/settings.json) or globally …

    line 16
  2. Distinctive:

    Mandatory Interception Test: Verify that the safety hook triggers correctly on simulated forbidden commands before concluding setup.

    line 18
  3. Distinctive:

    Action: Ask the user whether to configure guardrails for this project only or globally.

    line 45
  4. Very specific:

    Key Point: Default to project-level .claude/settings.json unless the user specifies global.

    line 46
  5. Distinctive:

    Key Point: Ensure parent directories exist before copying.

    line 51
  6. Very specific:

    Action: Add the PreToolUse hook entry to .claude/settings.json, merging into existing arrays if present.

    line 58
  7. Very specific:

    Key Point: Use "$CLAUDE_PROJECT_DIR"/.claude/hooks/block-dangerous-git.sh path expansion.

    line 59
  8. Distinctive:

    Action: Test the hook with a simulated blocked command:

    line 63
  9. Distinctive:

    Key Point: Verify that the command exits with code 2 and outputs a descriptive blocked message.

    line 67

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. 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.
  2. Explicit Authority Gate: Intercepted commands return an explicit non-zero exit code notifying the agent that it lacks authority to execute destructive operations.
  3. Scope Clarification: Always ask the user whether to apply guardrails locally to the project (.claude/settings.json) or globally (~/.claude/settings.json).
  4. Settings Merge Safety: Seamlessly merge guardrail hooks into existing PreToolUse configurations without overwriting other tools or settings.
  5. 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)
ComponentResponsibilityLocation
Classifier Hook ScriptInspect and block forbidden git patternsscripts/block-dangerous-git.sh
Python Command ParserParse complex shell command chainsscripts/classify_git_command.py
Settings IntegrationHook 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.json unless 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.sh to .claude/hooks/block-dangerous-git.sh and run chmod +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.sh path 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 RationalizationBinding RuleEngineering 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.