Git guardrails claude code
Skill popsiclelmlm/skills-cn/skills/misc/git-guardrails-claude-code
Chinese maintenance notes and installer for practical engineering agent skills.
npx -y skills add popsiclelmlm/skills-cn --skill git-guardrails-claude-codeAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
设置 Claude Code hooks,在危险 git commands(push、reset --hard、clean、branch -D 等)执行前阻止它们。当用户想防止破坏性 git 操作、添加 git safety hooks,或在 Claude Code 中阻止 git push/reset 时使用。
SKILL.md
2.3 KB, as published. Nobody here has run it
Setup Git Guardrails
设置一个 PreToolUse hook,在 Claude 执行危险 git commands 前拦截并阻止它们。
What Gets Blocked
git push(包括--force在内的所有变体)git reset --hardgit clean -f/git clean -fdgit branch -Dgit checkout ./git restore .
被阻止时,Claude 会看到一条消息,说明它没有权限访问这些 commands。
Steps
1. Ask scope
询问用户:只为当前项目(.claude/settings.json)安装,还是为所有项目(~/.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 合并到现有 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。