Repository navigation
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
shellpermission and resolves the branch withgit branch --show-currentat command time. - Three effects.
allowruns the operation,askopens the permission prompt, anddenyblocks it with an explanation. - Hierarchical rules.
repos[<directory>]overridesbranches[<branch>], which overridesdefault. - Compound commands covered. Every resource of
cd /tmp && git commitis checked; precedence isdeny > 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-guardOr add it to opencode.jsonc:
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
{ "$schema": "https://opencode.ai/config.json", "plugins": ["opencode-branch-guard"] }