Skip to content
cccskills
FreePublished on GitHub

git-guardrails-claude-code

设置 Claude Code 钩子,在危险 Git 命令(push、reset --hard、clean、branch -D 等)执行前将其拦截。当用户想要防止破坏性 Git 操作、添加 Git 安全钩子或在 Claude Code 中阻止 git push/reset 时使用。

The English summary is being prepared. Showing the original description.

See how to install

Files included (3)

  • SKILL.md2.3 KB
  • agents/openai.yaml110 B
  • scripts/block-dangerous-git.sh507 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

设置 Git 护栏

设置一个 PreToolUse 钩子,在 Claude 执行危险 Git 命令之前拦截并阻止它们。

会被阻止的命令

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

当命令被阻止时,Claude 会看到一条消息,告知它没有权限访问这些命令。

步骤

1. 询问安装范围

询问用户:是仅针对当前项目安装(.claude/settings.json),还是所有项目安装(~/.claude/settings.json)?

2. 复制钩子脚本

打包的脚本位于:scripts/block-dangerous-git.sh

根据安装范围将其复制到目标位置:

  • 项目级:.claude/hooks/block-dangerous-git.sh
  • 全局:~/.claude/hooks/block-dangerous-git.sh

使用 chmod +x 使其可执行。

3. 将钩子添加到设置文件

添加到相应的设置文件中:

项目级(.claude/settings.json):

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

全局(~/.claude/settings.json):

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

如果设置文件已存在,将钩子合并到现有的 hooks.PreToolUse 数组中:不要覆盖其他设置。

4. 询问自定义

询问用户是否需要从阻止列表中添加或移除任何模式。根据需求编辑已复制的脚本。

5. 验证

运行一个快速测试:

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

应退出并返回代码 2,并向 stderr 打印一条 BLOCKED 消息。

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

询问哪个技能或流程适合你的情况。本仓库内技能的路由器。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

在单次长会话中协调子智能体并安排日程,持续推进一项长期目标。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

把当前对话交接给一个全新的后台 agent,让它立刻接手工作。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

从固定点(commit、branch、tag 或 merge-base)开始,沿两条轴线审查变更——规范(代码是否遵循仓库文档化的编码规范?)和规格(代码是否与原始 issue/PRD 的要求一致?)。两条审查线在并行子 agent 中运行,并以并排方式报告结果。当用户想审查一个分支、PR、进行中的变更,或要求"从 X 开始审查"时使用。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

设计深度模块的共享词汇。当用户想要设计或改进模块的接口、寻找深化机会、决定 seam 的位置、让代码更可测试或更易被 AI 导航,或者其他 skill 需要深度模块词汇时使用。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

针对棘手 bug 和性能回归的诊断循环。当用户说"诊断"/"调试这个",或报告某处崩溃/报错/不正常/缓慢时使用。

The English summary is being prepared. Showing the original description.

devcxl/mattpocock-skills-zh498Updated Oct 20, 2026

See all skills by devcxl

Report a problem with this skill