# Git Guardrails Claude Code

> Install a Claude Code hook that stops destructive git commands (push, reset --hard, clean, branch -D, and friends) before they run. Use when the user wants to guard against dangerous git operations, add git safety hooks, or block git push/reset inside Claude Code.

- **Type:** Skill
- **Install:** `agentstack add skill-officialunofficial-skills-git-guardrails-claude-code`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [officialunofficial](https://agentstack.voostack.com/s/officialunofficial)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [officialunofficial](https://github.com/officialunofficial)
- **Source:** https://github.com/officialunofficial/skills/tree/main/skills/misc/git-guardrails-claude-code

## Install

```sh
agentstack add skill-officialunofficial-skills-git-guardrails-claude-code
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Git guardrails for Claude Code

Wire up a `PreToolUse` hook that inspects every Bash command Claude is about to run and refuses the destructive git operations before they touch the repository.

## What the guard refuses

- `git push` in any form, including `--force`
- `git reset --hard`
- `git clean -f` and `git clean -fd`
- `git branch -D`
- `git checkout .` and `git restore .`

When a command matches, the hook exits with code 2 and Claude receives a message stating it is not permitted to run that command, so it stops rather than retrying.

## Steps

### 1. Confirm the scope

Ask whether the guard should cover **this project only** (`.claude/settings.json`) or **every project** (`~/.claude/settings.json`). The answer decides where the script and the hook entry go.

### 2. Place the hook script

The bundled script lives at [scripts/block-dangerous-git.sh](scripts/block-dangerous-git.sh). Copy it to match the chosen scope:

- **Project**: `.claude/hooks/block-dangerous-git.sh`
- **Global**: `~/.claude/hooks/block-dangerous-git.sh`

Then mark it executable with `chmod +x`.

### 3. Register the hook in settings

Add the hook to the settings file for the chosen scope.

**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"
          }
        ]
      }
    ]
  }
}
```

When the settings file already exists, merge this entry into the existing `hooks.PreToolUse` array and leave the rest of the file untouched.

### 4. Offer to tune the pattern list

Ask whether any patterns should be added or dropped, then edit the `DANGEROUS_PATTERNS` array in the copied script to match.

### 5. Confirm it works

Feed a sample command through the script and check the result:

```bash
echo '{"tool_input":{"command":"git push origin main"}}' | 
```

A working guard exits with code 2 and prints a `BLOCKED` line to stderr.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [officialunofficial](https://github.com/officialunofficial)
- **Source:** [officialunofficial/skills](https://github.com/officialunofficial/skills)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-officialunofficial-skills-git-guardrails-claude-code
- Seller: https://agentstack.voostack.com/s/officialunofficial
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
