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 数组,不覆盖其他设置。
执行阶段
阶段 01确认安装范围
询问用户只为当前项目(.claude/settings.json)安装,还是为所有项目(~/.claude/settings.json)安装。
阶段 02复制 hook 脚本
将自带的 block-dangerous-git.sh 复制到 .claude/hooks/ 或 ~/.claude/hooks/,并用 chmod +x 设为可执行。
阶段 03写入 settings
在对应的 settings.json 中注册 matcher 为 Bash 的 PreToolUse hook,与已有配置合并。
阶段 04自定义规则
询问用户是否要增删拦截模式,并相应修改复制后的脚本。
阶段 05验证
向脚本输入一条模拟的 git push 请求,应以退出码 2 结束并在 stderr 输出 BLOCKED。
权限说明(据 SKILL.md 整理)
| 能力 | 是否需要 | 说明 |
|---|---|---|
| 文件写入 | 部分需要 | 只写入 hook 脚本(.claude/hooks/ 下)和对应的 settings.json。 |
| 命令执行 | 部分需要 | 只运行 chmod +x,以及用测试输入调用 hook 脚本进行验证。 |
| 网络外发 | 不需要 | 不需要网络访问。 |
SKILL.md 头部信息(YAML)
---
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,确认权限后再使用。