# Git Guardrails

> Installs Claude Code PreToolUse hooks that block dangerous git commands before execution. Use when setting up local or global guardrails for git push, force push, reset --hard, clean, branch deletion, checkout ., or restore .

- **Type:** Skill
- **Install:** `agentstack add skill-canvas-xxx-agent-skills-git-guardrails`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [ntwrcht](https://agentstack.voostack.com/s/ntwrcht)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [ntwrcht](https://github.com/ntwrcht)
- **Source:** https://github.com/ntwrcht/blvck-skills/tree/master/skills/engineering/git-guardrails

## Install

```sh
agentstack add skill-canvas-xxx-agent-skills-git-guardrails
```

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

Set up a Claude Code `PreToolUse` hook that blocks high-risk git commands before Claude executes them.

## When to Use

Use this skill when the user wants Claude Code git safety hooks, local project guardrails, global guardrails, or protection from destructive commands such as push, force push, hard reset, clean, branch deletion, checkout dot, or restore dot.

This skill installs Claude Code hooks only. For ordinary repository policy, server-side git hooks, GitHub branch protection, or CI rules, provide separate guidance.

## Artifacts

- Produces: `.claude/settings.json` (hook entries merged in)
- Consumes: nothing

## Core Rule

Preserve existing Claude settings. Merge hook entries; never overwrite unrelated settings, hooks, or user scripts.

## Blocked Commands

The bundled hook blocks:

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

## Workflow

1. **Choose scope.** Ask for project-only `.claude/settings.json` or global `~/.claude/settings.json` unless the user already specified it.
2. **Copy the hook.** Use [scripts/block-dangerous-git.sh](scripts/block-dangerous-git.sh). Copy it to `.claude/hooks/block-dangerous-git.sh` for project scope or `~/.claude/hooks/block-dangerous-git.sh` for global scope.
3. **Make it executable.** Run `chmod +x `.
4. **Merge settings.** Add a `hooks.PreToolUse` entry with matcher `Bash` and command pointing at the hook. Keep existing hooks and settings.
5. **Customize if requested.** Edit the copied script only for requested additions or removals.
6. **Verify.** Pipe a blocked command payload into the hook and confirm exit code `2` with a `BLOCKED:` stderr message.

## Settings Snippets

Project command:

```json
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
```

Global command:

```json
"command": "~/.claude/hooks/block-dangerous-git.sh"
```

Verification command:

```bash
printf '%s\n' '{"tool_input":{"command":"git push origin main"}}' | 
```

## Operating Rules

- Ask before choosing local versus global scope when unspecified.
- Read existing settings before editing them.
- Preserve unrelated JSON keys and hook entries.
- Do not weaken blocked patterns unless the user explicitly asks.
- Report the installed path, settings path, and verification result.

## Source & license

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

- **Author:** [ntwrcht](https://github.com/ntwrcht)
- **Source:** [ntwrcht/blvck-skills](https://github.com/ntwrcht/blvck-skills)
- **License:** MIT

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-canvas-xxx-agent-skills-git-guardrails
- Seller: https://agentstack.voostack.com/s/ntwrcht
- 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%.
