git-guardrails-claude-code
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.
- Kind
- Skill
- Works with
- Claude Code
- Source
- mattpocock/skills @ 24fe0ef7737e
- Path
- skills/misc/git-guardrails-claude-code/SKILL.md
- Jobs
- Guardrails, Git workflow
- Topics
- Guardrails & permissions
Credit
- Made by
- mattpocock
- Original
- github.com/mattpocock/skills/blob/24fe0ef7737efae15c87225755e…
- License
- MIT
Listed by Skill Manifest; not made by us.
InstallCopy it from the source repository, or sign in and let the assistant adapt it for your project.
Install factsScanned 3 Nov 2026
- Adds
- .claude/skills/git-guardrails-claude-code/ (the skill folder)
- 1 file(s) the skill refers to
- 2 other files in the folder: agents/openai.yaml, scripts/block-dangerous-git.sh
- Runs scripts
- Yes
- scripts/block-dangerous-git.sh
- shell block in the text
- script file in the folder (scripts/block-dangerous-git.sh)
- Uses the network
- Yes
- git clone / pull / push
- git clone / pull / push (scripts/block-dangerous-git.sh)
- Needs secrets
- None found
- Reads environment variables
- INPUT
- DANGEROUS_PATTERNS
- COMMAND
- Reads outside the project
- ~/.claude/settings.json (SKILL.md)
- ~/.claude/hooks/block-dangerous-git.sh (SKILL.md)
- Value without its scripts
- High
- The main file never tells the agent to run a bundled script, so the text works without them.
- scripts/block-dangerous-git.sh
- Source revision
- 24fe0ef7737e
- Licence
- MIT
- Last activity
- 25 Nov 2026
- Source changed after the scan
- Yes
- Last push 25 Nov 2026, scanned 3 Nov 2026; read it again before you rely on this scan
- Review
- Reviewed
Found by a static scan of the stored text; nothing is run. “None found” is not a guarantee, so read what you install before you run it.
# 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](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`):
```json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
…