
Git Guardrails Claude Code
This sets up a pre-execution hook that blocks Claude Code from running destructive git commands like push, reset --hard, clean -f, and branch -D. You get to choose whether to install it per project or globally, and it intercepts the bash tool before anything dangerous runs. It's straightforward: the hook script checks the command against a blocklist and exits with code 2 if there's a match. Honestly, this is the kind of thing you want if you're letting Claude make changes in a repo where one wrong push could ruin someone's day. You can customize which patterns to block after installation.
- skills.sh installs
- 5.7K
- GitHub stars
- 5.7K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add vinvcn/mattpocock-skills-zh-cn --skill git-guardrails-claude-code --agent claude-codeInstalls into .claude/skills of the current project.
Files
设置 Git Guardrails
设置一个 PreToolUse hook,在 Claude 执行危险 git commands 前拦截并阻止它们。
会被阻止的命令
git push(包括--force在内的所有 variants)git reset --hardgit clean -f/git clean -fdgit branch -Dgit checkout ./git restore .
被阻止时,Claude 会看到一条 message,说明它无权访问这些 commands。
步骤
1. 询问安装范围
询问用户:只为当前 project 安装(.claude/settings.json),还是为所有 projects 安装(~/.claude/settings.json)?
2. 复制 hook 脚本
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. 把 hook 加入 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):
Sponsors
Details
- Repository
- github.com/vinvcn/mattpocock-skills-zh-cn
- Categories
- Frontend Development, Git & Pull Requests
- First seen
- Jun 3, 2026
More from vinvcn/mattpocock-skills-zh-cn
All 39- Scaffold Exercises5.7K
- Setup Pre Commit5.7K
- Migrate To Shoehorn5.6K
- Teach5.4K
- Grilling4.7K
- Domain Modeling4.4K
- Code Review4.4K
- Ask Matt4.4K
- Diagnosing Bugs4.4K
- Implement4.3K
- Codebase Design4.3K
- Research4.2K
- Writing Shape3.7K
- Writing Fragments3.7K
- Writing Beats3.7K
- Resolving Merge Conflicts3.5K
- To Prd2.2K
- Design An Interface2.1K
- To Issues2.1K
- Qa2.1K
- Edit Article2.1K
- Obsidian Vault2.1K
- Request Refactor Plan2.1K
- Ubiquitous Language2.1K