Git Guardrails Skill for Claude Code: Block Risky Git
Sets up a Claude Code hook that blocks git push, reset --hard and other destructive git commands before Claude can run them.
- Installs
- 524.8K
- on skills.sh
- Stars
- 309.2K
- on GitHub
- Files
- 2
- besides SKILL.md
- Updated
- Nov 2026
- last repo commit
git-guardrails-claude-code adds a PreToolUse hook to Claude Code. The hook checks each Bash command before it runs and blocks git push (including --force), git reset --hard, git clean -f, git branch -D, git checkout . and git restore .. When a command is blocked, Claude is told it does not have authority to run it.
It starts when you ask for git safety hooks or want to stop Claude from pushing or resetting. It asks whether to install for this project (.claude/settings.json) or for all projects (~/.claude/settings.json), copies a bundled shell script, merges the hook into your settings, lets you edit the blocked list, then tests the hook with a sample git push.
Good for
- Claude Code users who let the agent run commands without watching every step
- Developers who never want an agent to push or force-push for them
- Anyone who wants the guard for one repo only, or for every repo
Install git-guardrails-claude-code
Claude Code
- 1
Copy this prompt.
Install the git-guardrails-claude-code skill in Claude Code. Run this command: npx skills add https://github.com/mattpocock/skills --skill git-guardrails-claude-code Then check that it loaded and tell me how to use it.
- 2
Paste it into Claude Code. It shows the change and asks before running it.
Requires Node.js.
From its listing on skills.sh. Source.
What's in the skill
When it loads
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.
Sections in SKILL.md
- What Gets Blocked
- Steps
- 1. Ask scope
- 2. Copy the hook script
- 3. Add hook to settings
- 4. Ask about customization
- 5. Verify
Key facts
- Installs on skills.sh
- 524,797 (Nov 2, 2026)
- GitHub stars
- 309,237 on mattpocock/skills (Nov 2, 2026)
- License
- MIT
- Last repo commit
- Nov 1, 2026
- skills.sh audits
- Gen Agent Trust Hub: pass, Socket: pass, Snyk: pass
What it includes
Asks if the hook is for this project or all projects
Project install writes to .claude/settings.json. Global install writes to ~/.claude/settings.json.
Files ·
Ask scopeCopies block-dangerous-git.sh and makes it executable
The bundled script goes to .claude/hooks/ (project) or ~/.claude/hooks/ (global), then gets chmod +x.
Runs code ·
Copy the hook scriptMerges a PreToolUse hook for Bash into settings.json
It merges into any existing hooks.PreToolUse list and leaves your other settings alone.
Files ·
Add the hook to settingsLets you add or remove blocked commands
You can change the list; the skill edits the copied script to match.
Files ·
Customize patternsPipes a sample git push into the script
The script should exit with code 2 and print a BLOCKED message to stderr.
Runs code ·
Verifygit push, reset --hard, clean -f, branch -D, checkout ., restore .
This is the default list the hook blocks. Claude sees a message that it has no authority to run them.
Runs code ·
Blocked commands
From the official docs
Permissions
Medium risk
It changes your Claude Code settings and adds a script that runs before every Bash command. Read the script and the settings diff once, and test it with the sample command in the skill.
What it can do
- Read your data
- Create and change things
- Delete things
- Read-only mode
Watch out for
It edits your Claude Code settings file
It merges a hook into the settings file you pick. Check the diff, especially if you already use hooks.
A shell script runs before each Bash command
The hook calls the bundled script on every Bash tool call. Read the script before you rely on it.
Only the listed commands are blocked
Other destructive commands are not covered unless you add them in the customize step.
Technical details
| Scopes |
|
|---|
Questions
What does git-guardrails-claude-code do?
It installs a Claude Code hook that blocks dangerous git commands before they run. The list covers git push (all variants), git reset --hard, git clean -f, git branch -D, git checkout . and git restore ..
How do I install it?
Follow the install box at the top of the page. After that, ask Claude Code to set up git guardrails and pick project or global scope when it asks.
Project or global: which should I pick?
Project writes the hook to .claude/settings.json and covers only that repo. Global writes to ~/.claude/settings.json and covers every project on your machine.
Can I change what it blocks?
Yes. After installing, the skill asks if you want to add or remove patterns and edits the copied script for you.
Does it work in Codex or Cursor?
The skill writes Claude Code hook settings, so it is for Claude Code. SKILL.md names no other tool.
Does it need an API key?
SKILL.md asks for none. It bundles one shell script and edits local settings files.
Is it safe?
It adds a blocking hook, which lowers risk, but it also edits your settings and installs a script that runs on every Bash call. Review the diff and script, then run the test command the skill suggests: a sample git push should exit with code 2 and print BLOCKED.
Information
updated Nov 2, 2026
- Repository
- mattpocock/skills
- Folder
skills/misc/git-guardrails-claude-code
Sources
Docs, issue trackers and discussions this page is built from.
Show all 2Hide
- git-guardrails-claude-code SKILL.md · github.com
- skills.sh listing · skills.sh