agentleFS
thedevappsecguythedevappsecguy/sec-skills/skills/git-guard/SKILL.md

git-guard

Skill0 starsChanged 8 months agoMITView on GitHub

Set up Claude Code hooks to block dangerous git commands before they execute, including `git push`, `git reset --hard`, `git clean`, `git branch -D`, and checkout or restore of the working tree. Use this skill when the user wants to prevent destructive git operations, protect a repo from accidental pushes or resets, add git safety hooks, or make git commands safer.

  • Deletes or force-pushes
  • Commits and pushes

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When blocked, Claude sees a message explaining that it does not have authority to run the command.

    line 18
  2. Very specific:

    Ask whether to install for this project only in .claude/settings.json or for all projects in ~/.claude/settings.json.

    line 24
  3. Distinctive:

    Add this to the appropriate settings file.

    line 41
  4. Very specific:

    If the settings file already exists, merge the hook into the existing hooks.PreToolUse array instead of overwriting other settings.

    line 83
  5. Distinctive:

    Ask whether to add or remove any blocked patterns, then edit the copied script accordingly.

    line 87
  6. Distinctive:

    Run a quick test:

    line 91

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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 Guard

Set up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them.

What Gets Blocked

  • git push, including force variants
  • git reset --hard
  • git clean -f and git clean -fd
  • git branch -D
  • git checkout . and git restore .

When blocked, Claude sees a message explaining that it does not have authority to run the command.

Steps

1. Ask scope

Ask whether to install for this project only in .claude/settings.json or for all projects in ~/.claude/settings.json.

2. Copy the hook script

The bundled script is at scripts/git-guard.sh.

Prerequisite: jq must be installed.

Copy it to the target location based on scope:

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

Make it executable with chmod +x.

3. Add the hook to settings

Add this to the appropriate settings file.

Project scope:

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

Global scope:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/git-guard.sh"
          }
        ]
      }
    ]
  }
}

If the settings file already exists, merge the hook into the existing hooks.PreToolUse array instead of overwriting other settings.

4. Ask about customization

Ask whether to add or remove any blocked patterns, then edit the copied script accordingly.

5. Verify

Run a quick test:

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

The script should exit with code 2 and print a BLOCKED message to stderr.

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.