Skip to content

Releases

v0.2.0

Choose a tag to compare

@github-actions github-actions released this 20 Sep 13:08
474f573

OpenCode V2 plugin that controls git mutations (commit, push, merge, rebase, reset, …) based on the current branch or repository, so protected branches stay clean. Each operation is allowed, asked, or denied.

Requires OpenCode V2. OpenCode V2 changed the plugin API; V1 plugin implementations do not run in V2.

Highlights

  • Branch-aware policy. Intercepts the shell permission and resolves the branch with git branch --show-current at command time.
  • Three effects. allow runs the operation, ask opens the permission prompt, and deny blocks it with an explanation.
  • Hierarchical rules. repos[<directory>] overrides branches[<branch>], which overrides default.
  • Compound commands covered. Every resource of cd /tmp && git commit is checked; precedence is deny > ask > allow.
  • Fail-closed by default. With no options, every git mutation is denied.
  • Read-only commands pass. status, log, diff, fetch, and unknown commands are untouched.

Install

opencode plugin add opencode-branch-guard

Or add it to opencode.jsonc:

{
  "$schema": "https://opencode.ai/config.json",
  "plugins": ["opencode-branch-guard"]
}

Example configuration

Allow work on normal branches and ask on protected branches:

{
  "$schema": "https://opencode.ai/config.json",
  "plugins": [
    {
      "package": "opencode-branch-guard",
      "options": {
        "default": {
          "allow": ["add", "checkout", "switch", "commit", "merge", "push", "rebase", "stash"]
        },
        "branches": {
          "main": {
            "allow": [],
            "ask": ["commit", "push", "merge", "rebase"]
          }
        }
      }
    }
  ]
}

Recognized git operations

add, branch, checkout, cherry-pick, clean, commit, merge, mv, push, rebase, reset, restore, revert, rm, stash, switch, tag.

Anything else passes as read-only. Branch names match exactly; there are no globs.

Notes

The plugin inspects the shell command string. It is a guardrail against accidental mutations, not a security boundary. See the Limitations section for known bypasses.

Full changelog

https://github.com/hugobatista/opencode-branch-guard/commits/v0.2.0