git-guardrails-claude-code

mattpocock@mattpocock336.7Kon mattpocock/skillsSkill

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.

Install command

Run on your own machine to install this skill.

npx skills add https://github.com/mattpocock/skills --skill git-guardrails-claude-code

Use this in your own environment. Copying text here does not run it.

Made forDevelopment
What you needNode.js and an AI client that supports agent skills
Project links
Sources checked2026-11-16

How to use it

  1. Run the install command in your project folder.
  2. Restart your AI client so it picks up the skill.
  3. Ask for a task that matches the description to try it.

SKILL.md

The instructions your assistant reads, from mattpocock/skills/skills/misc/git-guardrails-claude-code/SKILL.md. Its authors wrote it, so read it before you install.

name: git-guardrails-claude-code
description: 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.

Setup Git Guardrails

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

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 .

When blocked, Claude sees a message telling it that it does not have authority to access these commands.

Steps

1. Ask scope

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

2. Copy the hook script

The bundled script is at: scripts/block-dangerous-git.sh

Copy it to the target location based on scope:

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

Make it executable with chmod +x.

3. Add hook to settings

Add to the appropriate settings file:

Project (.claude/settings.json):

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

Global (~/.claude/settings.json):

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

If the settings file already exists, merge the hook into the existing hooks.PreToolUse array. Don't overwrite other settings.

4. Ask about customization

Ask if user wants to add or remove any patterns from the blocked list. Edit the copied script accordingly.

5. Verify

Run a quick test:

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

Should exit with code 2 and print a BLOCKED message to stderr.

View on GitHub

Security checks

Automated checks, last run Nov 30, 2026. They can miss problems and do not guarantee a listing is safe. Read the source and what you are asked to run before you use it.

6 of 6 checks passed
  • PassedSetup commands and descriptionLayer 1

    The install commands and description match none of the risky patterns we look for.

    Source: AIWantsThis screening rules

  • PassedSkill instructions (SKILL.md)Layer 1

    The skill file shows no hidden text, no instruction-override phrases and no risky commands.

    Source: AIWantsThis screening rules

  • PassedGen Agent Trust Hub auditLayer 2

    Gen Agent Trust Hub reported a pass for this skill.

    Evidence (1)
    Risk level
    SAFE

    Source: Gen Agent Trust Hub, as shown on skills.sh

  • PassedSnyk auditLayer 2

    Snyk reported a pass for this skill.

    Evidence (2)
    Risk level
    LOW
    Audited
    Sep 15, 2026

    Source: Snyk, as shown on skills.sh

  • PassedSocket auditLayer 2

    Socket reported a pass for this skill.

    Evidence (1)
    Audited
    Sep 15, 2026

    Source: Socket, as shown on skills.sh

  • PassedSource repositoryLayer 2

    The repository is public, not archived and has recent activity.

    Evidence (3)
    Last push
    2026-11-30
    Archived
    no
    License
    MIT

    Source: GitHub