agent toolingby mattpocock
Setup Git Guardrails
mattpocock/git-guardrails-claude-code
Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute.
What it changes
Passed 18 of 21 test cases with the skill, and 10 of 21 without it.
Without skill48%
With skill87%
Checks it passed that the model alone missed
- Specifies exit code 2 when blocking commands.
- Specifies PreToolUse as the configuration hook lifecycle key.
- Asks if the user wants to customize the blocked pattern list.
and 6 more in the full report
9 fixed11 passed either way3 still failing0 broke
- Pass-rate lift
- +39 pp
- Tokens
- -34%
- Agent turns
- 0%
- Response time
- -60%
Model gemini-3.6-flashMeasured 9/27/2026v120 of 23 cases passed with skill · 21 comparable
See it in action
One of 8 test cases the skill fixed. Same model, same prompt, with and without the skill.
PromptWhen installing the agent git interception hook for a single repository, which configuration file should receive the hook settings array?
What was checked, without and with the skill| Checked | Without skill | With skill |
|---|
| Specifies .claude/settings.json as the target configuration file. | Missed | Passed |
|---|
What's inside
The instructions your model reads when the skill loads.
SKILL.md90 lines2 filesincludes scripts
Setup Git Guardrails
Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them.
What Gets Blocked
git push (all variants including --force)
git reset --hard
git clean -f / git clean -fd
git branch -D
git checkout . / git restore .
When blocked, Claude sees a message telling it that it does not have authority to access these commands.
Steps
1. Ask scope
Ask the user: install for this project only (.claude/settings.json) or all projects (~/.claude/settings.json)?
2. Copy the hook script
The bundled script is at: scripts/block-dangerous-git.sh
Copy it to the target location based on scope:
- Project:
.claude/hooks/block-dangerous-git.sh
- Global:
~/.claude/hooks/block-dangerous-git.sh
Make it executable with chmod +x.
3. Add hook to settings
Add to the appropriate settings file:
Project (.claude/settings.json):
{
"hooks": {
Track record
Benchmark
18 / 21
test cases passed, vs 10 / 21 without
Adoption
- Users
- 0
- Times used
- 0
Safety and source details
SkillSafety
✓ 3 of 3 passed✓Code scan15 of 15 checks clean
0 critical · 0 warning · 0 info — scanner v5 — 8/31/2026
View 15 scanner checks
live_secretremote_code_executionreverse_shelldata_exfiltrationssrf_metadataagent_snoopinganti_refusaldestructive_commandsobfuscated_unicodeunicode_homoglyphopaque_blobsuspicious_urltool_overreachtrigger_abuseprompt_injection_phrasing
✓IntentSafe
LLM judge · does the skill do what it claims
✓ContentClean
LLM judge · policy & harmful-content review
Source
Importedmattpocock / skills
skills/misc/git-guardrails-claude-code/SKILL.md
View on GitHub ↗License MITImported 8/31/2026Version v1Bundled 1 file · scripts