Setup Git Guardrails

SkillAI & models

Installs a git claude skill, style hook that blocks dangerous git commands like force push and reset --hard.

Available today. Use it from your connected AI after setup.

Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.

Then ask your AI: use the Setup Git Guardrails skill

About this skill

Sets up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they run. Use when the user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.

What this skill tells your AI

The instructions your AI receives, as published by vinvcn/mattpocock-skills-zh-cn in skills/misc/git-guardrails-claude-code/SKILL.md and read by ahel’s review.

设置一个 PreToolUse hook,在 Claude 执行危险 git commands 前拦截并阻止它们。

What Gets Blocked

  • git push(包括 --force 在内的所有 variants)
  • git reset --hard
  • git clean -f / git clean -fd
  • git branch -D
  • git checkout . / git restore .

被阻止时,Claude 会看到一条 message,说明它无权访问这些 commands。

Steps

1. Ask scope

询问用户:只为当前 project 安装(.claude/settings.json),还是为所有 projects 安装(~/.claude/settings.json)?

2. Copy the hook script

bundled script 位于:scripts/block-dangerous-git.sh

根据 scope 复制到目标位置:

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

用 chmod +x 让它可执行。

3. Add hook to settings

添加到对应 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"
          }
        ]
      }
    ]
  }
}

如果 settings file 已存在,把 hook merge 到现有 hooks.PreToolUse array 中,不要覆盖其他 settings。

4. Ask about customization

询问用户是否要在 blocked list 中添加或移除 patterns。相应编辑复制后的 script。

5. Verify

运行快速测试:

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

应以 code 2 退出,并向 stderr 打印 BLOCKED message。

Signals

GitHub stars
4k
Forks
362
Last commit
Sep 2026

ahel review

  • K4binfo
    destructive-scoped
  • K4binfo
    destructive-scoped (in scripts/block-dangerous-git.sh)

Automated review, not a security audit. Ruleset v1+k2.

Advanced
Item type
skill
Key
git-guardrails-claude-code-vinvcn
Source
github.com/vinvcn/mattpocock-skills-zh-cn