git-guardrails-claude-code
Skill0 starsChanged 7 months agoMITView on GitHub
Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.
- Deletes or force-pushes
- Commits and pushes
142 other projects use a version of this, 140 of them edited.
Adopted by
Most recently taken up by
- quarkiverse/quarkus-reactive-messaging-nats-jetstreamedited, first seen Nov 30, 2026
- ctaxnagomi/agent-kd-skilledited, first seen Nov 29, 2026
- karanmrn/karanagentskillsedited, first seen Nov 29, 2026
- karanmrn/kstackedited, first seen Nov 29, 2026
- conalyz/conalyz_cliedited, first seen Nov 29, 2026
- jatupornrmutsb/claude-skillsedited, first seen Nov 29, 2026
Used with
Projects with it also use setup-ts-deep-modules, writing-beats and 9 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
liufeng1976Skillsetup-ts-deep-modules
Wire dependency-cruiser into a TypeScript repo so each package is a deep module — implementation hidden in subfolders, reachable only through its entry-point files. User-invoked.
Also in 51 projects that use this
LesaniSkillwriting-beats
Shape an article as a journey of beats, choose-your-own-adventure style. The user picks a starting beat from the raw material, you write only that beat, then offer options for where to pivot next, beat by beat, until the article reaches a natural end. Use when the user has raw material and wants to assemble it as a narrative rather than an argument.
Also in 67 projects that use this
LesaniSkillwriting-fragments
Grilling session that mines the user for fragments — heterogeneous nuggets of writing (claims, vignettes, sharp sentences, half-thoughts) — and appends them to a single document as raw material for a future article. Use when the user wants to develop ideas before imposing structure, or mentions "fragments", "ideate", or "raw material" for writing.
Also in 67 projects that use this
RoentekSkillloop-me
Grill me about specs for the workflows I want to build, within this workspace.
Also in 62 projects that use this
richard12511Skillclaude-handoff
Hand the current conversation off to a fresh background agent that picks up the work immediately.
Also in 50 projects that use this
boyingliu01Skillbatch-grill-me
A relentless interview that asks every frontier question at once, round by round. Thin alias of `grilling` (#540) — upstream mattpocock/skills absorbed this protocol into grilling; XP-Gate keeps this name as the sprint-flow Phase 2 entry point so orchestration docs stay stable.
Also in 5 projects that use this
- +1 more from Lesani
Other versions142 projects use a version of this.
Word for word · 0
None found.
Edited · 140
- mattpocock/skills★ 335k50% same
- vinvcn/mattpocock-skills-zh-CN★ 6.2k25% same
- devcxl/mattpocock-skills-zh★ 56525% same
- amazingloft999-droid/mattpocock-skills★ 42251% same
- InditexTech/weavejs★ 27751% same
- loulanyue/skills★ 23151% same
- tt-a1i/matt-skills-with-to-goal★ 19250% same
- aurorasoft2/Matt_Pocock_Skills★ 13351% same
- QiYueran-source/waymark★ 11250% same
- Tresnanda/kybern★ 10250% same
130 more not listed
Wrote their own version · 2
- chrislacey89/skills★ 7same name
- kanjiandahai/skills-collection★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository59 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- cavemanSkill
- context-engineeringSkill
- deprecation-migrationSkill
- design-an-interfaceSkill
- domain-modelSkill
- edit-articleSkill
- github-triageSkill
- grill-meSkill
- autoplanSkill
- benchmarkSkill
- browseSkill
- canarySkill
- carefulSkill
- codexSkill
- context-restoreSkill
- context-saveSkill
- csoSkill
- design-consultationSkill
- design-htmlSkill
- design-reviewSkill
- design-shotgunSkill
- devex-reviewSkill
- document-releaseSkill
- freezeSkill
- guardSkill
- healthSkill
- investigateSkill
- land-and-deploySkill
- learnSkill
- make-pdfSkill
- office-hoursSkill
- plan-ceo-reviewSkill
- plan-design-reviewSkill
- plan-devex-reviewSkill
- plan-eng-reviewSkill
- qa-onlySkill
- qaSkill
- retroSkill
- reviewSkill
- setup-deploySkill
- shipSkill
- unfreezeSkill
- improve-codebase-architectureSkill
- incremental-implementationSkill
- performance-optimizationSkill
- pr-triageSkill
- qaSkill
- request-refactor-planSkill
- security-hardeningSkill
- setup-pre-commitSkill
- spec-driven-developmentSkill
- tddSkill
- to-issuesSkill
- to-prdSkill
- triage-issueSkill
- ubiquitous-languageSkill
- write-a-skillSkill
- zoom-outSkill
The file
We split this skill into the rules it gives an agent
8 rules. 1 is common, 4 are distinctive, and 3 are very specific to this project.
1
Common
Most of the 129 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
After an incident where Claude ran an unwanted git operation
- Very specific: line 19
NOT: when user wants general pre-commit hooks (use setup-pre-commit)
- Distinctive: line 20
NOT: when user wants to block non-git commands — this is git-specific
- Very specific: line 35
Ask the user: this project only (.claude/settings.json) or all projects (~/.claude/settings.json)?
- Distinctive: line 69
If settings already exist, merge — don't overwrite.
- Common: line 73
Ask if user wants to add or remove patterns from the blocked list.
- Distinctive: line 81
Should exit code 2 with BLOCKED message.
- Very specific: line 112
DO NOT: use hardcoded paths for project scope — use $CLAUDE_PROJECT_DIR
“Common” is measured: kept by at least 6 in 10 of the 129 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Guardrails for Claude Code
Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them. AI agents are confident and fast — a dangerous combination when git push --force or git reset --hard is one misinterpretation away. This hook adds a hard safety layer that can't be rationalized past.
When to Use
- User wants to prevent Claude from running destructive git commands
- Setting up a new Claude Code project where git safety matters
- After an incident where Claude ran an unwanted git operation
- NOT when user wants general pre-commit hooks (use
setup-pre-commit) - NOT when user wants to block non-git commands — this is git-specific
- NOT in throwaway repos where destructive ops are fine
What Gets Blocked
git push(all variants including--force)git reset --hardgit clean -f/git clean -fdgit branch -Dgit checkout ./git restore .
Process
1. Ask scope
Ask the user: this project only (.claude/settings.json) or all projects (~/.claude/settings.json)?
2. Copy the hook script
Bundled at: scripts/block-dangerous-git.sh
Copy to target:
- Project:
.claude/hooks/block-dangerous-git.sh - Global:
~/.claude/hooks/block-dangerous-git.sh
Make executable: chmod +x.
3. Add hook to settings
Merge into the appropriate settings file's hooks.PreToolUse array:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
}
]
}
]
}
}If settings already exist, merge — don't overwrite.
4. Ask about customization
Ask if user wants to add or remove patterns from the blocked list.
5. Verify
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>Should exit code 2 with BLOCKED message.
Common Rationalizations
| Shortcut | Why It Fails |
| "I'll just tell Claude not to push in the system prompt" | System prompt instructions are soft — agents rationalize past them. A hook is a hard gate. |
"I only need to block --force, regular push is fine" | Regular push to the wrong branch is just as dangerous. The USER decides when to push, not the agent. |
| "I'll add the hook later, this project is low-risk" | Incidents happen in "low-risk" projects. Cost of installing: 2 minutes. Cost of unwanted force-push: hours. |
| "The script doesn't need to be executable" | Hook fails silently if not executable. Claude proceeds believing no hook exists. Always chmod +x. |
Red Flags
- Settings file has syntax errors after merging (validate JSON)
- Script uses hardcoded absolute path instead of
$CLAUDE_PROJECT_DIRfor project scope - Hook added but never tested — silent failures mean false sense of security
- Existing hooks overwritten instead of merged
Verification Checklist
- Script exists at target path and is executable
- Settings JSON is valid (no trailing commas, proper nesting)
- Blocked command exits code 2
- Safe command (
git status) exits code 0 - Existing settings preserved (other hooks/permissions not lost)
- User confirmed which commands to block/allow
Anti-patterns
- DO NOT overwrite existing settings.json — read, merge, write back
- DO NOT skip verification — untested hook provides false security
- DO NOT use hardcoded paths for project scope — use
$CLAUDE_PROJECT_DIR - DO NOT install globally without asking — project scope is safer default
- DO NOT block non-destructive operations (commit, status) — over-blocking makes users disable it
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

