| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
gen-commit-msg is a Go CLI that generates Git commit message candidates from staged changes using OpenCode, then lets you pick the best one in a terminal UI (or outputs one message in non-interactive mode).
The tool is built for editor-first commit workflows: generate inside the commit message editor, review, then edit before finalizing the commit.
Many AI commit-message tools are either:
This project intentionally does neither.
gen-commit-msg only generates message text and writes it to stdout (or a file via --output).
On startup, the tool ensures an OpenCode agent file exists.
This file contains the agent configuration and generation instructions used for commit message creation.
You can customize it when needed:
Important behavior:
Build from source:
make buildBinary will be created as ./gen-commit-msg.
Generate up to 5 candidates and choose one:
gen-commit-msgGenerate exactly one candidate (no selection list):
gen-commit-msg --subject-max 1Write result to a file instead of stdout:
gen-commit-msg --output /tmp/commit-msg.txtThen use your normal commit command:
git commitThis utility is designed to be called from a commit message buffer.
The snippet below runs gen-commit-msg, captures output to a temp file, and inserts the generated message at the top of the current gitcommit buffer.
let s:gen_commit_msg_height = 5
let s:gen_commit_msg_subject_max = 5
function! <SID>GenCommitMsgCallback(orig_bufnr, term_bufnr, tmpfile, job, status)
if a:status == 0
if filereadable(a:tmpfile) && getfsize(a:tmpfile) > 0
let l:output = readfile(a:tmpfile)
call appendbufline(a:orig_bufnr, 0, l:output)
call win_execute(bufwinid(a:orig_bufnr), 'call cursor(1, 1)')
endif
endif
call delete(a:tmpfile)
if a:status == 0 || a:status == 130
execute 'silent! bwipeout! ' . a:term_bufnr
else
echohl WarningMsg | echo 'Command failed with status: ' . a:status | echohl None
endif
endfunction
function! <SID>GenCommitMsg()
let l:tmpfile = tempname()
let l:cmd = 'gen-commit-msg --subject-max ' . shellescape(s:gen_commit_msg_subject_max) . ' --output ' . shellescape(l:tmpfile)
let l:orig_bufnr = bufnr('%')
execute 'topleft ' . s:gen_commit_msg_height . 'split | enew'
let l:Callback = function('<SID>GenCommitMsgCallback', [l:orig_bufnr, bufnr('%'), l:tmpfile])
call term_start([&shell, &shellcmdflag, l:cmd], {'curwin': 1, 'exit_cb': l:Callback})
endfunction
augroup GitCommitMapping
autocmd!
autocmd FileType gitcommit nnoremap <buffer> <Leader>O :call <SID>GenCommitMsg()<CR>
augroup ENDPress <leader>O in a commit buffer to generate candidates and insert the selected message.
Flag precedence is:
CLI flag > environment variable > default
| Flag | Env var | Default | Description |
|---|---|---|---|
| --subject-min, -m | GCM_SUBJECT_MIN | 1 | Minimum subject candidate count |
| --subject-max, -x | GCM_SUBJECT_MAX | 5 | Maximum subject candidate count (max 20) |
| --body | GCM_BODY | true | Generate commit body |
| --quiet, -q | GCM_QUIET | false | Hide progress view |
| --agent, -a | GCM_AGENT | gen-commit-msg | OpenCode agent name |
| --install-agent | GCM_INSTALL_AGENT | if-not-exists | always, if-not-exists, no |
| --pause | GCM_PAUSE | on-error | Pause before exit: on, off, on-error |
| --output, -o | GCM_OUTPUT | "" | Write selected message to file |
| --log-level, -l | GCM_LOG_LEVEL | none | trace, debug, info, warn, error, none |
| --log-file | GCM_LOG_FILE | stderr | Log destination (- for stdout) |
| --version, -V | — | — | Print version and exit |
| --help, -h | — | — | Print help and exit |
Additional runtime env vars:
Pipeline (interactive mode):
The staged context includes summaries (--name-status, --stat, --numstat, --summary, --dirstat) and full staged patch (git diff --cached ...).
Common commands:
make fmt
make vet
make lint
make test
make build
make allSingle package tests:
go test -count=1 -race ./internal/config/cmd/gen-commit-msg/main.go # CLI orchestration
internal/config/ # flags + env parsing
internal/git/ # repo checks + staged context collection
internal/agent/ # OpenCode agent prompt management
internal/server/ # opencode serve lifecycle
internal/opencode/ # OpenCode session/prompt client
internal/tui/ # progress + selection Bubble Tea UI
internal/logging/ # slog setup and custom trace level
MIT (see LICENSE).
| Back | FazBrowse Home | New Git URL |