Skip to content
alyn
vinvcn

Git Guardrails Claude Code skill

设置 Claude Code hooks,在危险 git commands(push、reset --hard、clean、branch -D 等)执行前阻止它们。适用于用户想防止破坏性 git 操作、添加 git safety hooks,或在 Claude Code 中阻止 git push/reset 时。

$npx skills add vinvcn/mattpocock-skills-zh-CN --skill git-guardrails-claude-code
View this skill on GitHubvinvcn/mattpocock-skills-zh-CN/skills/misc/git-guardrails-claude-code/SKILL.md
Pack stars
5,675
Pack installs
188k
Alyn Score
69/99
Updated
15 h ago
License
MIT
– views – installs via Alyn

Install Git Guardrails Claude Code

Pick your agent. Every command is ready to paste.

$npx skills add vinvcn/mattpocock-skills-zh-CN --skill git-guardrails-claude-code

The open skills CLI detects your agents (Claude Code, Cursor, Codex and 70+ more) and installs to the right folder. Add -g to install globally.

01

Install it

Run the command above, or upload the folder in Claude.

02

Ask naturally

Describe the task. Your agent loads git-guardrails-claude-code when the request matches its description.

03

Name it if needed

If it does not trigger, say “use the git-guardrails-claude-code skill”. In Codex, type $git-guardrails-claude-code.

The skill itself

SKILL.md

FolderGitHub

设置 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):

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

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

4. 询问是否定制

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

5. 验证

运行快速测试:

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

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

Tips for Git Guardrails Claude Code

  • • Start a fresh session after installing so your agent picks up the new skill.
  • • This skill ships scripts. Read them before the first run, and run it in a project without secrets first.
  • • It is part of a pack with 30 skills. Install only the ones you need with --skill to keep triggers precise.
  • • If two skills overlap, mention the one you want by name.

Questions about Git Guardrails Claude Code

What does the Git Guardrails Claude Code skill do?

设置 Claude Code hooks,在危险 git commands(push、reset --hard、clean、branch -D 等)执行前阻止它们。适用于用户想防止破坏性 git 操作、添加 git safety hooks,或在 Claude Code 中阻止 git push/reset 时。

How do I install Git Guardrails Claude Code?

Run "npx skills add vinvcn/mattpocock-skills-zh-CN --skill git-guardrails-claude-code" in your project. The skills CLI installs it for Claude Code, Cursor, Codex and 70+ other agents. In Claude on the web, upload the skill folder as a ZIP under Customize > Skills.

Does Git Guardrails Claude Code work in Cursor and Codex?

Yes. Git Guardrails Claude Code uses the open SKILL.md format, so it works in Claude Code, Claude, Cursor, OpenAI Codex, Gemini CLI, GitHub Copilot and other agents that support agent skills.

Is Git Guardrails Claude Code free?

Git Guardrails Claude Code is open source on GitHub under the MIT license. It is free to install; check the license before commercial use.

Who made Git Guardrails Claude Code?

Git Guardrails Claude Code is published by vinvcn in the vinvcn/mattpocock-skills-zh-CN repository, together with 29 other skills.

Similar skills. From other creators.