git-guardrails-claude-codecommit 3216582SKILL.md · Hardening
Git Guardrails for Claude Code
Sets up a Claude Code PreToolUse hook that blocks dangerous git commands such as push, reset --hard, clean and branch -D before they run.
Changes Claude Code hook settings (project or global), after which Claude can no longer run git push and the other blocked commands.
npx skills add mattpocock/skills --skill git-guardrails-claude-codeCommand selected. Copy it manually.
- Permissions
- read-repo
- write-files
- shell
- network
- Compatible with
- Claude Code, Codex, Copilot, Gemini CLI
- GitHub
- 308.7k
- Source
- Community · Matt Pocock
- Status
- Scan passed
- License
- MIT
- Category
- Hardening
Core rule
If the settings file already exists, merge the hook into hooks.PreToolUse and never overwrite other settings.
Execution Phases
Phase 01Ask scope
Ask whether to install for this project only (.claude/settings.json) or for all projects (~/.claude/settings.json).
Phase 02Copy the hook script
Copy the bundled block-dangerous-git.sh to .claude/hooks/ or ~/.claude/hooks/ and make it executable with chmod +x.
Phase 03Add hook to settings
Register a PreToolUse hook with matcher Bash in the matching settings.json, merging it with any existing hooks.
Phase 04Customize patterns
Ask whether to add or remove blocked patterns and edit the copied script accordingly.
Phase 05Verify
Pipe a sample git push request into the script; it should exit with code 2 and print a BLOCKED message to stderr.
Permissions (summarised from SKILL.md)
| Capability | Needed | Details |
|---|---|---|
| File writes | Limited | Only writes the hook script under .claude/hooks/ and the matching settings.json. |
| Command execution | Limited | Only runs chmod +x and a test invocation of the hook script. |
| Network outbound | Not required | No network access is needed. |
SKILL.md frontmatter (YAML)
---
name: git-guardrails-claude-code
description: 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.
---