Skip to main content
skill Claude Code

git-guardrails-claude-code — Claude Code skill guide

This skill adds a Claude Code hook that stops risky Git commands before they run. Use it when an agent must not push or discard working-tree changes.

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add mattpocock/skills
/plugin install mattpocock-skills@mattpocock
Open on GitHub

What git-guardrails-claude-code does

git-guardrails-claude-code adds a PreToolUse hook for Bash. It intercepts git push, including variants with --force, before Claude Code runs it. The hook also blocks git reset --hard, git clean -f and git clean -fd, git branch -D, git checkout ., and git restore ..

The skill asks whether to install for the current project in .claude/settings.json or for all projects in ~/.claude/settings.json. It copies scripts/block-dangerous-git.sh into .claude/hooks or ~/.claude/hooks, makes it executable with chmod +x, then adds it to hooks.PreToolUse. Existing settings are kept and the hook is merged into the current array.

You can edit the copied script to change blocked patterns, then test it with a tool_input.command payload. Install this for teams that want human approval over destructive Git actions; skip it when the agent is intentionally allowed to push or clean the worktree.

What it helps with

  • block git push before an agent runs it
  • prevent git reset --hard
  • stop cleanup through git clean -f
  • deny branch deletion with git branch -D
  • attach Git command checks to PreToolUse

Example prompts for the agent

  • “Install git-guardrails-claude-code for this project only.”
  • “Set up a global hook that blocks `git push`.”
  • “Check that the hook rejects `git push origin main`.”

How to install git-guardrails-claude-code

1Plugin marketplace

/plugin marketplace add mattpocock/skills
/plugin install mattpocock-skills@mattpocock

This installs the whole mattpocock-skills plugin with all its skills

2Skills CLI (Vercel)

npx skills add mattpocock/skills --skill git-guardrails-claude-code -a claude-code

3Manually: put the files in place

~/.claude/skills/git-guardrails-claude-code/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/git-guardrails-claude-code/

From the same set32

The whole set →
grill-me Matt Pocock grill-me interviews you about a plan or design to expose gaps and sharpen decisions. Use it before implementation starts. Claude Code 1,424,476installs grill-with-docs Matt Pocock This skill interviews you about a plan or design and creates ADRs and a glossary along the way. Use it when decisions need sharper definition. Claude Code 1,219,756installs improve-codebase-architecture Matt Pocock This skill scans a codebase for architectural friction, then builds a visual HTML report with refactoring candidates. Use it before a deeper architecture review. Claude Code 1,163,035installs tdd Matt Pocock Guides the red-green TDD loop: ensures tests are written first, keep them at public interfaces, and avoid coupling to implementation details. Claude Code 1,141,062installs setup-matt-pocock-skills Matt Pocock This skill configures a repository for Matt Pocock's engineering skills by setting its issue tracker, triage labels, and domain docs layout. Run it before using the other skills. Claude Code 1,052,851installs handoff Matt Pocock Creates a handoff document from the current conversation so another agent can continue the work. Use it when a task moves to a new session or agent. Claude Code 1,038,491installs triage Matt Pocock This skill moves issues and external PRs through triage states, verification, and agent briefs. It fits maintainers managing an issue queue. Claude Code 990,453installs prototype Matt Pocock Creates throwaway prototypes for checking state logic or exploring UI before committing the decision to the main codebase. Claude Code 986,201installs

Similar

Questions about git-guardrails-claude-code

How do I install git-guardrails-claude-code in Claude Code?

Add the skill with npx skills add mattpocock/skills --skill git-guardrails-claude-code -a claude-code. Then choose .claude/settings.json for one project or ~/.claude/settings.json for all projects.

What does git-guardrails-claude-code do?

It configures a PreToolUse hook for Bash that stops risky Git commands before Claude Code executes them. When a command is blocked, Claude receives a message that it lacks authority to use it.

Which Git commands does the hook block?

The hook blocks git push, git reset --hard, git clean -f variants, git branch -D, git checkout ., and git restore .. You can change the blocked patterns in the copied script.

Source text

SKILL.md · MIT
---
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.
---

# 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",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
          }
        ]
      }
    ]
  }
}
```

**Global** (`~/.claude/settings.json`):

```json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/block-dangerous-git.sh"
          }
        ]
      }
    ]
  }
}
```

If the settings file already exists, merge the hook into the existing `hooks.PreToolUse` array. Don't overwrite other settings.

### 4. Ask about customization

Ask if user wants to add or remove any patterns from the blocked list. Edit the copied script accordingly.

### 5. Verify

Run a quick test:

```bash
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>
```

Should exit with code 2 and print a BLOCKED message to stderr.

© Matt Pocock · MIT · mattpocock/skills

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor