agentleFS
chiruu12chiruu12/claude-skills-template/.claude/skills/git-guardrails-claude-code/SKILL.md

git-guardrails-claude-code

Skill0 starsChanged 7 months agoMITView on GitHub

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.

  • Deletes or force-pushes
  • Commits and pushes

142 other projects use a version of this, 140 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use setup-ts-deep-modules, writing-beats and 9 more.

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.
  • liufeng1976Skill

    setup-ts-deep-modules

    Wire dependency-cruiser into a TypeScript repo so each package is a deep module — implementation hidden in subfolders, reachable only through its entry-point files. User-invoked.

    Also in 51 projects that use this

  • LesaniSkill

    writing-beats

    Shape an article as a journey of beats, choose-your-own-adventure style. The user picks a starting beat from the raw material, you write only that beat, then offer options for where to pivot next, beat by beat, until the article reaches a natural end. Use when the user has raw material and wants to assemble it as a narrative rather than an argument.

    Also in 67 projects that use this

  • LesaniSkill

    writing-fragments

    Grilling session that mines the user for fragments — heterogeneous nuggets of writing (claims, vignettes, sharp sentences, half-thoughts) — and appends them to a single document as raw material for a future article. Use when the user wants to develop ideas before imposing structure, or mentions "fragments", "ideate", or "raw material" for writing.

    Also in 67 projects that use this

  • RoentekSkill

    loop-me

    Grill me about specs for the workflows I want to build, within this workspace.

    Also in 62 projects that use this

  • richard12511Skill

    claude-handoff

    Hand the current conversation off to a fresh background agent that picks up the work immediately.

    Also in 50 projects that use this

  • boyingliu01Skill

    batch-grill-me

    A relentless interview that asks every frontier question at once, round by round. Thin alias of `grilling` (#540) — upstream mattpocock/skills absorbed this protocol into grilling; XP-Gate keeps this name as the sprint-flow Phase 2 entry point so orchestration docs stay stable.

    Also in 5 projects that use this

  • +1 more from Lesani

The file

We split this skill into the rules it gives an agent

8 rules. 1 is common, 4 are distinctive, and 3 are very specific to this project.

  • 1

    Common

    Most of the 129 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After an incident where Claude ran an unwanted git operation

    line 18
  2. Very specific:

    NOT: when user wants general pre-commit hooks (use setup-pre-commit)

    line 19
  3. Distinctive:

    NOT: when user wants to block non-git commands — this is git-specific

    line 20
  4. Very specific:

    Ask the user: this project only (.claude/settings.json) or all projects (~/.claude/settings.json)?

    line 35
  5. Distinctive:

    If settings already exist, merge — don't overwrite.

    line 69
  6. Common:

    Ask if user wants to add or remove patterns from the blocked list.

    line 73
  7. Distinctive:

    Should exit code 2 with BLOCKED message.

    line 81
  8. Very specific:

    DO NOT: use hardcoded paths for project scope — use $CLAUDE_PROJECT_DIR

    line 112

“Common” is measured: kept by at least 6 in 10 of the 129 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.

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

Git Guardrails for Claude Code

Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them. AI agents are confident and fast — a dangerous combination when git push --force or git reset --hard is one misinterpretation away. This hook adds a hard safety layer that can't be rationalized past.

When to Use

  • User wants to prevent Claude from running destructive git commands
  • Setting up a new Claude Code project where git safety matters
  • After an incident where Claude ran an unwanted git operation
  • NOT when user wants general pre-commit hooks (use setup-pre-commit)
  • NOT when user wants to block non-git commands — this is git-specific
  • NOT in throwaway repos where destructive ops are fine

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 .

Process

1. Ask scope

Ask the user: this project only (.claude/settings.json) or all projects (~/.claude/settings.json)?

2. Copy the hook script

Bundled at: scripts/block-dangerous-git.sh

Copy to target:

  • Project: .claude/hooks/block-dangerous-git.sh
  • Global: ~/.claude/hooks/block-dangerous-git.sh

Make executable: chmod +x.

3. Add hook to settings

Merge into the appropriate settings file's hooks.PreToolUse array:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
          }
        ]
      }
    ]
  }
}

If settings already exist, merge — don't overwrite.

4. Ask about customization

Ask if user wants to add or remove patterns from the blocked list.

5. Verify

echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>

Should exit code 2 with BLOCKED message.

Common Rationalizations

ShortcutWhy It Fails
"I'll just tell Claude not to push in the system prompt"System prompt instructions are soft — agents rationalize past them. A hook is a hard gate.
"I only need to block --force, regular push is fine"Regular push to the wrong branch is just as dangerous. The USER decides when to push, not the agent.
"I'll add the hook later, this project is low-risk"Incidents happen in "low-risk" projects. Cost of installing: 2 minutes. Cost of unwanted force-push: hours.
"The script doesn't need to be executable"Hook fails silently if not executable. Claude proceeds believing no hook exists. Always chmod +x.

Red Flags

  • Settings file has syntax errors after merging (validate JSON)
  • Script uses hardcoded absolute path instead of $CLAUDE_PROJECT_DIR for project scope
  • Hook added but never tested — silent failures mean false sense of security
  • Existing hooks overwritten instead of merged

Verification Checklist

  • Script exists at target path and is executable
  • Settings JSON is valid (no trailing commas, proper nesting)
  • Blocked command exits code 2
  • Safe command (git status) exits code 0
  • Existing settings preserved (other hooks/permissions not lost)
  • User confirmed which commands to block/allow

Anti-patterns

  • DO NOT overwrite existing settings.json — read, merge, write back
  • DO NOT skip verification — untested hook provides false security
  • DO NOT use hardcoded paths for project scope — use $CLAUDE_PROJECT_DIR
  • DO NOT install globally without asking — project scope is safer default
  • DO NOT block non-destructive operations (commit, status) — over-blocking makes users disable it

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.