vinvcn avatar

Git Guardrails Claude Code

This sets up a pre-execution hook that blocks Claude Code from running destructive git commands like push, reset --hard, clean -f, and branch -D. You get to choose whether to install it per project or globally, and it intercepts the bash tool before anything dangerous runs. It's straightforward: the hook script checks the command against a blocklist and exits with code 2 if there's a match. Honestly, this is the kind of thing you want if you're letting Claude make changes in a repo where one wrong push could ruin someone's day. You can customize which patterns to block after installation.

skills.sh installs
5.7K
GitHub stars
5.7K
last updated
Aug 21, 2026

Install

$ npx -y skills add vinvcn/mattpocock-skills-zh-cn --skill git-guardrails-claude-code --agent claude-code

Installs into .claude/skills of the current project.

Files

设置 Git Guardrails

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

会被阻止的命令

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

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

步骤

1. 询问安装范围

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

2. 复制 hook 脚本

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. 把 hook 加入 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):

Sponsors

Details

Repository
github.com/vinvcn/mattpocock-skills-zh-cn
Categories
Frontend Development, Git & Pull Requests
First seen
Jun 3, 2026

More from vinvcn/mattpocock-skills-zh-cn

All 39
1affaan-m avatardart-flutter-patternsaffaan-m/eccProduction-ready Dart and Flutter patterns covering null safety, immutable state, async composition, widget architecture, popular state management frameworks (B5.7Kskills.sh installs
2vinvcn avatarsetup-pre-commitvinvcn/mattpocock-skills-zh-cn在当前仓库设置 Husky pre-commit hooks,集成 lint-staged (Prettier)、类型检查和测试。适用于用户想添加 pre-commit hooks、设置 Husky、配置 lint-staged,或在提交时运行格式化、类型检查和测试时。5.7Kskills.sh installs
3affaan-m avatarecc-guideaffaan-m/eccGuide users through ECC's current agents, skills, commands, hooks, rules, install profiles, and project onboarding by reading the live repository surface before5.5Kskills.sh installs
4web-infra-dev avatarandroid-device-automationweb-infra-dev/midscene-skillsVision-driven Android device automation using Midscene. Operates entirely from screenshots — no DOM or accessibility labels required. Can interact with all visi5.5Kskills.sh installs
5max-sixty avatarworktrunkmax-sixty/worktrunkGuidance for Worktrunk (the `wt` CLI) — git worktree management, hooks, and config. Load when editing .config/wt.toml or ~/.config/worktrunk/config.toml; adding5.5Kskills.sh installs
6ghostsecurity avatarghost-scan-codeghostsecurity/skillsGhost Security - SAST code scanner. Finds security vulnerabilities in source code by planning and executing targeted scans for issues like SQL injection, XSS, B5.5Kskills.sh installs