git-guardrails-claude-code
Skill27 starsChanged 3 months agoMITView on GitHub
设置 Claude Code 钩子,在危险的 git 命令(push、reset --hard、clean、branch -D 等)执行前将其拦截。当用户想阻止破坏性 git 操作、添加 git 安全钩子,或在 Claude Code 中拦截 git push/reset 时使用。
- Deletes or force-pushes
- Commits and pushes
Files
设置 Git 防护栏
设置一个 PreToolUse 钩子,在 Claude 执行危险的 git 命令之前将其拦截并阻止。
哪些命令会被阻止
git push(包括--force在内的所有变体)git reset --hardgit clean -f/git clean -fdgit branch -Dgit checkout ./git restore .
被阻止时,Claude 会看到一条消息,告知它无权访问这些命令。
步骤
1. 询问适用范围
询问用户:只为当前项目安装(.claude/settings.json),还是为所有项目安装(~/.claude/settings.json)?
2. 复制钩子脚本
随附脚本位于:scripts/block-dangerous-git.sh
根据适用范围将其复制到目标位置:
- 项目级:
.claude/hooks/block-dangerous-git.sh - 全局级:
~/.claude/hooks/block-dangerous-git.sh
用 chmod +x 赋予可执行权限。
3. 在设置中添加钩子
添加到相应的设置文件:
项目级(.claude/settings.json):
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
}
]
}
]
}
}全局级(~/.claude/settings.json):
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/block-dangerous-git.sh"
}
]
}
]
}
}如果设置文件已存在,将该钩子合并进现有的 hooks.PreToolUse 数组——不要覆盖其他设置。
4. 询问是否自定义
询问用户是否想从阻止列表中添加或移除某些模式。相应地编辑复制后的脚本。
5. 验证
运行一个快速测试:
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>应以退出码 2 退出,并向 stderr 打印一条 BLOCKED 消息。
Other versions114 projects use a version of this.
Word for word · 0
None found.
Edited · 109
- mattpocock/skills★ 309k17% same
- vinvcn/mattpocock-skills-zh-CN★ 5.5k29% same
- devcxl/mattpocock-skills-zh★ 52243% same
- amazingloft999-droid/mattpocock-skills★ 42217% same
- InditexTech/weavejs★ 26617% same
- loulanyue/skills★ 23117% same
- tt-a1i/matt-skills-with-to-goal★ 19217% same
- aurorasoft2/Matt_Pocock_Skills★ 13317% same
- VisualxIntelligence/mattpocok-skills★ 5517% same
- Vepricov/claude-brainlab★ 3518% same
99 more not listed
Wrote their own version · 5
- chrislacey89/skills★ 4same name
- mesqueeb/moonjelly-reef★ 3same name
- wakqasahmed/ai-engineering-workflow-skills★ 2same name
- wakqasahmed/skills★ 2same name
- snowfluke/engineering-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Used alongsideProjects with it also use ubiquitous-language, batch-grill-me and 2 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
kennethkeimSkillubiquitous-language
Extract a DDD-style ubiquitous language glossary from the current conversation, flagging ambiguities and proposing canonical terms. Saves to UBIQUITOUS_LANGUAGE.md. Use when user wants to define domain terms, build a glossary, harden terminology, create a ubiquitous language, or mentions "domain model" or "DDD".
Also in 32 projects that use this
boyingliu01Skillbatch-grill-me
A relentless interview that asks every frontier question at once, round by round. Thin alias of `grilling` (#540) — upstream mattpocock/skills absorbed this protocol into grilling; XP-Gate keeps this name as the sprint-flow Phase 2 entry point so orchestration docs stay stable.
Also in 6 projects that use this
FabienDehopreSkilldecision-mapping
Turn a loose idea into a sequenced map of investigation tickets, then drive them to resolution one at a time.
Also in 4 projects that use this
HK-hubSkillprd-to-plan
Turn a PRD into a multi-phase implementation plan using tracer-bullet vertical slices, saved as a local Markdown file in ./plans/. Use when user wants to break down a PRD, create an implementation plan, plan phases from a PRD, or mentions "tracer bullets".
Also in 8 projects that use this
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ask-mattSkill
- codebase-designSkill
- code-reviewSkill
- diagnosing-bugsSkill
- domain-modelingSkill
- grill-with-docsSkill
- implementSkill
- improve-codebase-architectureSkill
- prototypeSkill
- researchSkill
- resolving-merge-conflictsSkill
- setup-matt-pocock-skillsSkill
- tddSkill
- to-specSkill
- to-ticketsSkill
- triageSkill
- wayfinderSkill
- wizardSkill
- claude-handoffSkill
- loop-meSkill
- setup-ts-deep-modulesSkill
- writing-beatsSkill
- writing-fragmentsSkill
- writing-shapeSkill
- migrate-to-shoehornSkill
- scaffold-exercisesSkill
- setup-pre-commitSkill
- grillingSkill
- grill-meSkill
- handoffSkill
- teachSkill
- to-questionnaireSkill
- wait-whatSkill
- writing-for-agentsSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

