Skills Directory精选自 GitHub 的开源 Skills

git-guardrails-claude-codecommit 3216582SKILL.md · 安全加固

Git 危险命令拦截

为 Claude Code 配置 PreToolUse hook,在执行前拦截 git push、reset --hard 等危险命令。

会修改 Claude Code 的 hooks 设置(项目级或全局),之后 Claude 将无法执行 git push 等被拦截的命令。

npx skills add mattpocock/skills --skill git-guardrails-claude-code
权限
  • read-repo
  • write-files
  • shell
  • network
兼容工具
Claude Code, Codex, Copilot, Gemini CLI
GitHub
308.7k
来源
社区 · Matt Pocock
状态
扫描通过
许可证
MIT

核心规则

已有 settings 文件时,把 hook 合并进 hooks.PreToolUse 数组,不覆盖其他设置。

执行阶段

  1. 阶段 01确认安装范围

    询问用户只为当前项目(.claude/settings.json)安装,还是为所有项目(~/.claude/settings.json)安装。

  2. 阶段 02复制 hook 脚本

    将自带的 block-dangerous-git.sh 复制到 .claude/hooks/ 或 ~/.claude/hooks/,并用 chmod +x 设为可执行。

  3. 阶段 03写入 settings

    在对应的 settings.json 中注册 matcher 为 Bash 的 PreToolUse hook,与已有配置合并。

  4. 阶段 04自定义规则

    询问用户是否要增删拦截模式,并相应修改复制后的脚本。

  5. 阶段 05验证

    向脚本输入一条模拟的 git push 请求,应以退出码 2 结束并在 stderr 输出 BLOCKED。

权限说明(据 SKILL.md 整理)

能力是否需要说明
文件写入部分需要只写入 hook 脚本(.claude/hooks/ 下)和对应的 settings.json。
命令执行部分需要只运行 chmod +x,以及用测试输入调用 hook 脚本进行验证。
网络外发不需要不需要网络访问。

SKILL.md 头部信息(YAML)

SKILL.md 头部信息(YAML)commit 3216582
---
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.
---

相关技能

规则扫描无法覆盖所有风险,安装前请阅读此技能的 SKILL.md,确认权限后再使用。