This OpenCode V2 plugin checks Git commit messages before an agent runs git commit.
It requires @opencode/plugin 2.4.1 or newer and effect 4.1.0 or newer.
The plugin inspects every shell and bash tool call before it runs, across POSIX shells and PowerShell 7 (pwsh).
If a git commit breaks a formatting rule, the plugin rejects the tool call with an error.
The error lists each violation and shows a conforming example, so the agent can fix the message and retry.
Before the first commit in each session and checkout, the agent captures a Git baseline with the commit_context tool.
The baseline records the effective commit.gpgsign setting, which determines whether a commit needs a signoff.
On Windows, context capture and command inspection target PowerShell 7 (pwsh).
The plugin does not change Git hooks or repository configuration.
Add the package to your opencode.json or opencode.jsonc file:
Set options on the plugin entry:
{
"plugins": [
{
"package": "opencode-commit-guard",
"options": {
"requireScope": true,
"allowedScopes": ["kernel", "build", "ui"],
"maxLineLength": 72,
},
},
],
}| Option | Default | Allowed values |
|---|---|---|
requireScope |
true |
Boolean. Requires a <scope>: <subject> first line. |
allowedScopes |
none | Array of non-empty scope names. An empty array allows any scope. |
maxLineLength |
72 |
Integer of 0 or more. Limits each subject and body line. Set 0 to remove limits. |
The plugin rejects unknown options, including requireSignoff.
- Ask your agent to commit changes in your repository.
- Before the first commit in a session and checkout, your agent calls
commit_contextand runs the returned capture command in the foreground shell. Approve that shell command when OpenCode prompts you. - Wait for
Frozen commit baselinein the shell output. That report confirms the active baseline and lists the commit rules for the checkout.
RECEIPT_OK confirms only that the shell wrote the capture file.
It does not authorize a commit.
Ask your agent to refresh the baseline (commit_context with refresh: true) after you switch branches, change signing settings, or change commit instructions.
- Scope: The first line uses
<scope>: <subject>, for examplekernel: fix raceorfeat(parser): add subshells. - Allowed scopes: If
allowedScopeshas entries, the scope must match one of them. - Line length: No subject or body line exceeds
maxLineLength. - Signoff: If the captured
commit.gpgsignistrue, add-sor aSigned-off-by:trailer. Signoff is not a cryptographic signature. - Literal messages: Supply messages with
-m,--message, one quoted heredoc on POSIX standard input, or a single literal here-string pipeline in PowerShell 7. The plugin rejects message files, shell expansion in messages, and--trailer. - Direct target: Run
git commitdirectly in the captured checkout. The plugin rejectsgit -C, Git directory flags, Git environment overrides, and directory-changing wrappers.
In POSIX shells, use real newlines inside $'...' for a message body:
git commit -s -m $'kernel: Fix race in thermal driver\n\nHold the lock while the sensor list changes.'In PowerShell 7 (pwsh), use single quotes or pipe a literal here-string to git commit -F -:
@'
kernel: Fix race in thermal driver
Hold the lock while the sensor list changes.
'@ | git commit -s -F -git commit --help and git commit -h do not need a baseline.
{ "$schema": "https://opencode.ai/config.json", "plugins": [ { "package": "opencode-commit-guard", }, ], }