# Git Guardrails

> Set up OpenCode permission rules to guard against dangerous git commands (push, reset --hard, clean, branch -D, checkout/restore .) before they execute. Use when user wants to prevent destructive git operations, add git safety guardrails, or block dangerous git commands.

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

## Install

```sh
agentstack add skill-matthewye-opencode-toolbox-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

Sets up `permission.bash` rules in `opencode.jsonc` to require confirmation (`ask`) before executing dangerous git commands.

## What Gets Guarded

- `git push` (all variants including `--force`, `--force-with-lease`)
- `git reset --hard`
- `git clean -f` / `git clean -fd`
- `git branch -D`
- `git checkout .` / `git restore .`

When guarded, OpenCode will prompt for confirmation before executing any of these commands.

## Steps

### 1. Ask scope

Ask the user: install for **all projects** (global) or **this project only**?

| Scope | Config path |
|-------|-------------|
| Global | `~/.config/opencode/opencode.jsonc` |
| Project | `/opencode.jsonc` |

### 2. Read existing config

Read the target config file. Note existing `permission` block, especially any existing `bash` rules.

If the file does not exist, create it with a minimal structure:
```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "permission": {}
}
```

### 3. Add guardrail rules

Add or update the following rules under `permission.bash`. Use `"ask"` level — the agent must request confirmation before executing these commands:

```jsonc
"permission": {
  "bash": {
    // ... existing rules ...
    "git push *": "ask",
    "git reset --hard *": "ask",
    "git clean -f*": "ask",
    "git branch -D *": "ask",
    "git checkout .*": "ask"
  }
}
```

Rules to write:

| Pattern | Guards |
|---------|--------|
| `"git push *": "ask"` | All `git push` variants |
| `"git reset --hard *": "ask"` | Hard reset only |
| `"git clean -f*": "ask"` | Forced clean |
| `"git branch -D *": "ask"` | Force delete branch |
| `"git checkout .*": "ask"` | Discard working tree changes |

**Merge carefully**: If the file already has a `permission.bash` block with existing rules, merge the new rules into it — never overwrite unrelated settings.

### 4. Ask about customization

Ask if the user wants to:
- Add additional dangerous commands to guard (e.g., `git stash drop`, `git reflog expire`)
- Remove any of the 5 default patterns
- Change any rule from `"ask"` to `"deny"` (block without confirmation)

Edit the config accordingly.

### 5. Verify

Read back the modified config file and confirm:

1. All 5 guardrail patterns are present under `permission.bash`
2. Existing unrelated rules are preserved
3. JSONC syntax is valid (no trailing commas, matching braces)

Report the final state to the user with a summary of what's now guarded.

## Source & license

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

- **Author:** [MatthewYe](https://github.com/MatthewYe)
- **Source:** [MatthewYe/opencode-toolbox](https://github.com/MatthewYe/opencode-toolbox)
- **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-matthewye-opencode-toolbox-git-guardrails
- Seller: https://agentstack.voostack.com/s/matthewye
- 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%.
