git-guardrails-claude-code
vinvcn/mattpocock-skills-zh-cn
How to install git-guardrails-claude-code
npx skills add https://github.com/vinvcn/mattpocock-skills-zh-cn --skill git-guardrails-claude-codeFull instructions (SKILL.md)
Source of truth, from vinvcn/mattpocock-skills-zh-cn.
name: git-guardrails-claude-code description: 设置 Claude Code hooks,在危险 git commands(push, reset --hard, clean, branch -D 等)执行前阻止它们。Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.
Setup Git Guardrails
设置一个 PreToolUse hook,在 Claude 执行危险 git commands 前拦截并阻止它们。
What Gets Blocked
git push(包括--force在内的所有 variants)git reset --hardgit clean -f/git clean -fdgit branch -Dgit 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
根据 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。
Related skills
More from vinvcn/mattpocock-skills-zh-cn and the wider catalog.
grill-me
围绕 plan 或 design 持续 interview user,直到达成 shared understanding,并逐一解决 decision tree 的每个分支。Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".
grill-with-docs
Grilling session that challenges your plan against the existing domain model, sharpens terminology, and updates documentation (CONTEXT.md, ADRs) inline as decisions crystallise. Use when user wants to stress-test a plan against their project's language and documented decisions.
setup-matt-pocock-skills
Sets up an `## Agent skills` block in AGENTS.md/CLAUDE.md and `docs/agents/` so the engineering skills know this repo's issue tracker (GitHub or local markdown), triage label vocabulary, and domain doc layout. Run before first use of `to-issues`, `to-prd`, `triage`, `diagnose`, `tdd`, `improve-codebase-architecture`, or `zoom-out` — or if those skills appear to be missing context about the issue tracker, triage labels, or domain docs.
tdd
使用 red-green-refactor loop 做 test-driven development。Use when user wants to build features or fix bugs using TDD, mentions "red-green-refactor", wants integration tests, or asks for test-first development.
diagnose
面向棘手 bug 和性能回退的纪律化 diagnosis loop。Reproduce → minimise → hypothesise → instrument → fix → regression-test. Use when user says "diagnose this" / "debug this", reports a bug, says something is broken/throwing/failing, or describes a performance regression.
improve-codebase-architecture
根据 CONTEXT.md 中的 domain language 和 docs/adr/ 中的 decisions,寻找 codebase 的 deepening opportunities。Use when the user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more testable and AI-navigable.