Skip to content

About

OpenCode V2 plugin that enforces git commit format rules and signing baselines during agent sessions

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

opencode-commit-guard

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.

Overview

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.

Installation

Add the package to your opencode.json or opencode.jsonc file:

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

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.

Usage

  1. Ask your agent to commit changes in your repository.
  2. Before the first commit in a session and checkout, your agent calls commit_context and runs the returned capture command in the foreground shell. Approve that shell command when OpenCode prompts you.
  3. Wait for Frozen commit baseline in 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.

Formatting rules

  • Scope: The first line uses <scope>: <subject>, for example kernel: fix race or feat(parser): add subshells.
  • Allowed scopes: If allowedScopes has entries, the scope must match one of them.
  • Line length: No subject or body line exceeds maxLineLength.
  • Signoff: If the captured commit.gpgsign is true, add -s or a Signed-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 commit directly in the captured checkout. The plugin rejects git -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.

About

OpenCode V2 plugin that enforces git commit format rules and signing baselines during agent sessions

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages