/git-guardrails-claude-code
设置 Claude Code hooks,在危险 git commands(push、reset --hard、clean、branch -D 等)执行前阻止它们。适用于用户想防止破坏性 git 操作、添加 git safety hooks,或在 Claude Code 中阻止 git push/reset 时。
$ npx -y skills add vinvcn/mattpocock-skills-zh-cn --skill git-guardrails-claude-code --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/git-guardrails-claude-code
Context preview
The summary Claude sees to decide when to auto-load this skill.
设置 Claude Code hooks,在危险 git commands(push、reset --hard、clean、branch -D 等)执行前阻止它们。适用于用户想防止破坏性 git 操作、添加 git safety hooks,或在 Claude Code 中阻止 git push/reset 时。
SKILL.md
git-guardrails-claude-code.SKILL.mdname: git-guardrails-claude-code
description: 设置 Claude Code hooks,在危险 git commands(push、reset --hard、clean、branch -D 等)执行前阻止它们。适用于用户想防止破坏性 git 操作、添加 git safety hooks,或在 Claude Code 中阻止 git push/reset 时。
Setup Git Guardrails
设置一个 PreToolUse hook,在 Claude 执行危险 git commands 前拦截并阻止它们。
What Gets Blocked
- `git push`(包括 `--force` 在内的所有 variants)
- `git reset --hard`
- `git clean -f` / `git clean -fd`
- `git branch -D`
- `git checkout .` / `git restore .`
被阻止时,Claude 会看到一条 message,说明它无权访问这些 commands。
Steps
1. Ask scope
询问用户:只为**当前 project** 安装(`.claude/settings.json`),还是为**所有 projects** 安装(`~/.claude/settings.json`)?
2. Copy the hook script
bundled script 位于:[scripts/block-dangerous-git.sh](scripts/block-dangerous-git.sh)
根据 scope 复制到目标位置:
- **Project**: `.claude/hooks/block-dangerous-git.sh`
- **Global**: `~/.claude/hooks/block-dangerous-git.sh`
用 `chmod +x` 让它可执行。
3. Add hook to 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. Ask about customization
询问用户是否要在 blocked list 中添加或移除 patterns。相应编辑复制后的 script。
5. Verify
运行快速测试:
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>应以 code 2 退出,并向 stderr 打印 BLOCKED message。
Read more
name: git-guardrails-claude-code description: 设置 Claude Code hooks,在危险 git commands(push、reset --hard、clean、branch -D 等)执行前阻止它们。适用于用户想防止破坏性 git 操作、添加 git safety hooks,或在 Claude Code 中阻止 git push/reset 时。
Setup Git Guardrails
设置一个 PreToolUse hook,在 Claude 执行危险 git commands 前拦截并阻止它们。
What Gets Blocked
- `git push`(包括 `--force` 在内的所有 variants)
- `git reset --hard`
- `git clean -f` / `git clean -fd`
- `git branch -D`
- `git checkout .` / `git restore .`
被阻止时,Claude 会看到一条 message,说明它无权访问这些 commands。
Steps
1. Ask scope
询问用户:只为**当前 project** 安装(`.claude/settings.json`),还是为**所有 projects** 安装(`~/.claude/settings.json`)?
2. Copy the hook script
bundled script 位于:[scripts/block-dangerous-git.sh](scripts/block-dangerous-git.sh)
根据 scope 复制到目标位置:
- **Project**: `.claude/hooks/block-dangerous-git.sh`
- **Global**: `~/.claude/hooks/block-dangerous-git.sh`
用 `chmod +x` 让它可执行。
3. Add hook to 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. Ask about customization
询问用户是否要在 blocked list 中添加或移除 patterns。相应编辑复制后的 script。
5. Verify
运行快速测试:
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>应以 code 2 退出,并向 stderr 打印 BLOCKED message。
Repo: vinvcn/mattpocock-skills-zh-cn
Other skills on mattpocock-skills.
- /ask-matt
询问当前情境适合哪个技能或流程;它是本仓库所有 skills 的路由器。
Open skill - /code-review
从固定点(commit、branch、tag 或 merge-base)开始,按 Standards(代码是否符合本仓库记录的编码标准?)和 Spec(代码是否符合来源 issue/PRD 的要求?)两个轴线审查变更。两个审查会在并行子代理中运行,并并排报告。适用于用户想审查 branch、PR、进行中的变更,或要求 “review since X” 时。
Open skill - /codebase-design
用于设计深模块的共享词汇。适用于用户想设计或改进模块接口、寻找深化机会、决定 seam 放在哪里、让代码更容易测试或更适合 AI 导航,或其他技能需要深模块词汇时。
Open skill - /diagnosing-bugs
面向棘手缺陷和性能回退的诊断循环。适用于用户说 “diagnose” / “debug this”,或报告某些东西 broken、throwing、failing、slow 时。
Open skill - /domain-modeling
构建并打磨项目的领域模型。适用于用户想明确领域术语或通用语言、记录架构决策,或其他技能需要维护领域模型时。
Open skill - /grill-with-docs
一个用来打磨计划或设计的持续追问式访谈,并在过程中创建文档(ADRs 和词汇表)。
Open skill

