
Git Guardrails Claude Code
- 3.3k installs
- 2.8k repo stars
- Updated July 27, 2026
- vinvcn/mattpocock-skills-zh-cn
git-guardrails-claude-code is an agent skill that installs PreToolUse hooks blocking dangerous git commands in Claude Code.
About
The git-guardrails-claude-code skill sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them. Blocked patterns include all git push variants including force, git reset --hard, git clean -f and -fd, git branch -D, and git checkout dot or git restore dot. Setup asks project versus global scope, copies block-dangerous-git.sh to .claude/hooks with chmod plus x, and merges hook config into .claude/settings.json or global settings without overwriting existing hooks. Blocked commands return exit code 2 with stderr message that Claude lacks permission. Customization step allows adding or removing blocked patterns in the copied script. Verification pipes sample JSON tool_input for git push through the script expecting BLOCKED output. Use when preventing destructive git operations, adding git safety hooks, or blocking git push and reset in Claude Code environments.
- PreToolUse Bash hook blocks push, reset --hard, clean, branch -D, checkout dot.
- Project or global scope via .claude/settings.json hook merge.
- Copies block-dangerous-git.sh with chmod plus x to hooks directory.
- Exit code 2 BLOCKED stderr when dangerous git command detected.
- Verification test with echo JSON tool_input git push sample.
Git Guardrails Claude Code by the numbers
- 3,271 all-time installs (skills.sh)
- +399 installs in the week ending Aug 2, 2026 (Skillselion tracking)
- Ranked #27 of 735 Git & Pull Requests skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Aug 3, 2026 (Skillselion catalog sync)
git-guardrails-claude-code capabilities & compatibility
- Capabilities
- dangerous git command pattern blocking · project and global hook installation · settings.json pretooluse merge · script copy and chmod setup · json stdin verification test
- Use cases
- code review · security audit · devops
npx skills add https://github.com/vinvcn/mattpocock-skills-zh-cn --skill git-guardrails-claude-codeAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 3.3k |
|---|---|
| repo stars | ★ 2.8k |
| Security audit | 3 / 3 scanners passed |
| Last updated | July 27, 2026 |
| Repository | vinvcn/mattpocock-skills-zh-cn ↗ |
How do I prevent Claude from running git push, reset --hard, or clean in my project?
Install Claude Code PreToolUse hooks that block dangerous git commands including push, reset --hard, clean, and branch -D before execution.
Who is it for?
Developers using Claude Code who want guardrails against destructive git operations.
Skip if: Skip when you intentionally need autonomous git push and hard reset without human gates.
When should I use this skill?
Use when preventing destructive git operations or adding git safety hooks in Claude Code.
What you get
Installed block-dangerous-git.sh hook merged into settings with verified BLOCKED response.
- pretooluse bash hook script
- blocked-command error responses
By the numbers
- Blocks 8 dangerous git command patterns
- Hook exits with code 2 on blocked commands
Files
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。
#!/bin/bash
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command')
DANGEROUS_PATTERNS=(
"git push"
"git reset --hard"
"git clean -fd"
"git clean -f"
"git branch -D"
"git checkout \."
"git restore \."
"push --force"
"reset --hard"
)
for pattern in "${DANGEROUS_PATTERNS[@]}"; do
if echo "$COMMAND" | grep -qE "$pattern"; then
echo "BLOCKED: '$COMMAND' matches dangerous pattern '$pattern'. The user has prevented you from doing this." >&2
exit 2
fi
done
exit 0
Related skills
FAQ
Who is git-guardrails-claude-code for?
Developers and software engineers using Claude Code who want guardrails against destructive git operations.
When should I use git-guardrails-claude-code?
When preventing destructive git operations or adding git safety hooks in Claude Code.
Is git-guardrails-claude-code safe to install?
Review the Security Audits panel on this page before installing in production.