mattpocock/skills

git-guardrails-claude-code

为 Claude Code 配置 PreToolUse 钩子,在 Bash 工具执行前拦截 git push、reset --hard、clean -f、branch -D、checkout . 与 restore . 等命令。它修改 Claude 的钩子设置,不是为 Git 仓库安装服务器端权限控制。

  • SKILL.md 已保存
  • 中文用法已整理
  • 安装与运行未实测
先判断是否解决你的问题

git-guardrails-claude-code 是什么?

为 Claude Code 配置 PreToolUse 钩子,在 Bash 工具执行前拦截 git push、reset --hard、clean -f、branch -D、checkout . 与 restore . 等命令。它修改 Claude 的钩子设置,不是为 Git 仓库安装服务器端权限控制。

中文说明由本站依据来源整理;英文原文保留在页面下方。

按客户端选择安装入口

怎么接入你的 Agent?

  1. 定位完整 Skill 目录

    打开本项目来源,核对 SKILL.md 及其引用的脚本和资料。

  2. 交给你正在用的 Agent

    在下面选择客户端,展开并复制安装指令,让 Agent 读取来源后选择安装方式。

  3. 确认识别,再做具体任务

    让 Agent 回报安装目录和识别到的名称 git-guardrails-claude-code,然后按本页使用示例提供材料。

展开并复制给 Codex 的安装指令
发送给 Codex

安装并检查 git-guardrails-claude-code

请在 Codex 的当前工作环境中安装并检查 git-guardrails-claude-code 这个 Skill。

项目身份:mattpocock/skills / git-guardrails-claude-code
来源:https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/misc/git-guardrails-claude-code/SKILL.md
已定位的源文件:skills/misc/git-guardrails-claude-code/SKILL.md

1. 先阅读真实 SKILL.md 和它引用的必要文件,确认触发条件、安装方式、依赖与权限;尊重源文件要求的审批步骤。
2. 按当前客户端支持的方式安装完整 Skill 目录,保留已有配置,不只复制一段提示词。涉及缺失凭证、目标目录或权限时先列出缺项并向我确认。
3. 安装后回读实际目录、Skill 名称和识别结果,说明哪些步骤已完成,哪些只是文档检查,不得把安装成功当作任务已经实测。
4. 如来源提供了可安全验证的示例,在我提供所需输入后做一个最小任务;创建、修改、删除、部署或发送内容前,按源文件和我的授权执行。
准备输入,再按步骤执行

装好以后,具体怎么用?

准备哪些材料

  • 使用支持 PreToolUse 的 Claude Code 和能运行附带 Bash 脚本的环境。先选仅当前项目 .claude/settings.json,还是全局 ~/.claude/settings.json;保留 scripts/block-dangerous-git.sh。

会得到什么

  • 可执行的拦截脚本和合并后的 Claude Code 钩子设置,以及模拟命令的实际拦截结果。

实际使用顺序

  1. 按选定范围把附带脚本复制到 .claude/hooks/ 或 ~/.claude/hooks/,设置可执行权限。
  2. 把 matcher 为 Bash 的 command 钩子合入已有 hooks.PreToolUse 数组,保留其他配置。项目配置使用 CLAUDE_PROJECT_DIR 定位脚本。
  3. 需要时调整阻止的模式;用包含 git push origin main 的 tool_input JSON 管道输入脚本,检查退出码2及 stderr 的 BLOCKED 消息。该模拟只测试钩子,不实际推送。
使用示例

从一个具体任务开始

本站根据源文件编写的使用示例,未在本站实际运行。示例中的文件由你提供。

安装并识别 Skill 后发送

复制一个具体任务

教学示例:请用 git-guardrails-claude-code 只给当前项目加钩子。先回读现有.claude/settings.json,复制完整附带脚本并合并Bash PreToolUse,不覆盖其他hooks。用模拟tool_input测试git push,不真的执行推送;回报文件差异、退出码和BLOCKED结果。
预期结果

预期模拟命令被脚本拒绝;本站未运行本例,不据此承诺所有Git危险操作都不可绕过。

使用前先看这些限制

使用条件与边界

  • 拦截作用于配置所覆盖的 Claude Bash 调用,不会阻止你在其他终端直接运行 Git。
  • Windows 需先核对 Bash 和脚本执行方式,不能把 chmod 或 POSIX 路径当作 PowerShell 命令直接运行。
针对这个 Skill 的疑问

常见问题

加了钩子还能推送吗?

附带默认规则阻止 Claude 通过该Bash钩子执行所有git push。需要调整规则时应检查脚本,不把它理解为只拦截force push。

需要核对时再展开原文

来源原文与资料状态

源文件
已保存 SKILL.md,抓取于 2026-11-16T12:36:35.145Z
中文使用说明
已针对下方源文件版本整理用途、用法和常见问题
安装与任务测试
本站未执行安装或任务测试
来源复核
本页中文用法已对照保存版本的完整 SKILL.md 阅读整理
展开 SKILL.md 原文、章节与历史收录资料

skills/misc/git-guardrails-claude-code/SKILL.md · 抓取时间 2026-11-16T12:36:35.145Z

以下保留源文件的 description、章节及摘录,供核对中文说明;完整文件通过上方链接打开。

抓取成功不代表已完成安装或任务测试。

来源 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.

查看源文件章节 / Source sections
  • 原文:Setup Git Guardrails
  • 原文:What Gets Blocked
  • 原文:Steps
  • 原文:1. Ask scope
  • 原文:2. Copy the hook script
  • 原文:3. Add hook to settings
  • 原文:4. Ask about customization
  • 原文:5. Verify
原文:Setup Git Guardrails

Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them.

原文:What Gets Blocked

- `git push` (all variants including `--force`) - `git reset --hard` - `git clean -f` / `git clean -fd` - `git branch -D` - `git checkout .` / `git restore .` When blocked, Claude sees a message telling it that it does not have authority to access these commands.

原文:1. Ask scope

Ask the user: install for **this project only** (`.claude/settings.json`) or **all projects** (`~/.claude/settings.json`)?

原文:2. Copy the hook script

The bundled script is at: [scripts/block-dangerous-git.sh](scripts/block-dangerous-git.sh) Copy it to the target location based on scope: - **Project**: `.claude/hooks/block-dangerous-git.sh` - **Global**: `~/.claude/hooks/block-dangerous-git.sh` Make it executable with `chmod +x`.

原文:3. Add hook to settings

Add to the appropriate settings file: **Project** (`.claude/settings.json`): ```json { "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh" } ] } ] } } ``` **Global** (`~/.claude/settings.json`): ```json { "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "~/.claude/hooks/block-dangerous-git.sh" } ] } ] } } ``` If the settings file already exists, merge the hook into the existing `hooks.PreToolUse` array. Don't overwrite other settings.

原文:4. Ask about customization

Ask if user wants to add or remove any patterns from the blocked list. Edit the copied script accordingly.

文件 SHA256:69b291d655626a01602b998a1836fcb93c058ede68dfafddfd71e87f17074764

仓库许可证记录:MIT;repository-license-recorded-scope-unverified,查看来源。

Skills.sh收录简介 · 2026-07-28

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…

查看历史简介来源

这份历史简介在采集时已截断;完整用途和触发条件需打开来源核对。

历史收录数据

Skill标识git-guardrails-claude-code
来源仓库mattpocock/skills
榜单快照2026-07-28
榜单口径Skills.sh累计安装量
快照名次155
快照累计安装量173259

历史资料说明

  • 所保留的来源简介在采集时已截断;完整触发条件、依赖及排除项须阅读源文件,本站不补写缺失部分。
  • 安装量用于说明当时的收录次序,不是效果、可信度或当前可用性的证明。

此页用于识别项目与来源。安装入口可在该Skill的Skills.sh页面查看;当前目录是否仍存在、附带脚本和账户依赖尚需按具体版本确认。

返回 Skills 目录,按任务继续筛选 · MCP与Skills教程与资源