Install
$ agentstack add skill-wenwuzhidao-mattpocock-skills-zh-git-guardrails-claude-code ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
设置 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](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"}}' |
应以退出码 2 退出,并向 stderr 打印一条 BLOCKED 消息。
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: WenWuZhiDao
- Source: WenWuZhiDao/mattpocock-skills-zh
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.