# Git Guardrails for Claude Code (git-guardrails-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.

- Category: [Hardening](https://www.myskills.tools/en/categories/hardening/)
- Source: Community · Matt Pocock
- Repository: https://github.com/mattpocock/skills/tree/main/skills/misc/git-guardrails-claude-code (commit 3216582)
- SKILL.md: https://github.com/mattpocock/skills/blob/main/skills/misc/git-guardrails-claude-code/SKILL.md
- Install command: `npx skills add mattpocock/skills --skill git-guardrails-claude-code`
- License: MIT
- Compatible with: Claude Code, Codex, Copilot, Gemini CLI
- Permissions: read-repo ✓, write-files ✓, shell ✓, network ✗
- Status: Scan passed
- A rule scan cannot catch every risk. Read this skill's SKILL.md and check its permissions before installing.
- ⚠ Changes Claude Code hook settings (project or global), after which Claude can no longer run git push and the other blocked commands.

## Core rule

If the settings file already exists, merge the hook into hooks.PreToolUse and never overwrite other settings.

## Execution Phases

1. **Ask scope** — Ask whether to install for this project only (.claude/settings.json) or for all projects (~/.claude/settings.json).
2. **Copy the hook script** — Copy the bundled block-dangerous-git.sh to .claude/hooks/ or ~/.claude/hooks/ and make it executable with chmod +x.
3. **Add hook to settings** — Register a PreToolUse hook with matcher Bash in the matching settings.json, merging it with any existing hooks.
4. **Customize patterns** — Ask whether to add or remove blocked patterns and edit the copied script accordingly.
5. **Verify** — 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)

```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.
---
```

Home: https://www.myskills.tools/en/ · URL: https://www.myskills.tools/en/skills/git-guardrails-claude-code/
