Generate commit messages from staged git diffs using OpenAI or Anthropic.
Download the latest binary from Releases, or build from source:
cargo install --git https://github.com/lourenc/comsgSet an API key in your environment:
# OpenAI (default provider)
export OPENAI_API_KEY="sk-..."
# or Anthropic
export ANTHROPIC_API_KEY="sk-ant-..."Stage some changes and run:
comsgThat's it. It reads your staged diff and prints a commit message.
-p, --provider <openai|anthropic> AI provider (default: openai)
-m, --model <MODEL> Model override
-n, --number <N> Number of suggestions (default: 1)
# Generate a single commit message
comsg
# Get 5 suggestions to pick from
comsg -n 5
# Use Anthropic instead of OpenAI
comsg -p anthropic
# Pipe a diff directly
git diff --staged | comsg
# One-liner commit
git commit -m "$(comsg)"# ~/.gitconfig
[alias]
cm = "!comsg"Then just git cm.
# ~/.config/lazygit/config.yml
customCommands:
- key: "C"
context: "files"
command: "git commit -m \"$(comsg)\""
subprocess: true#!/bin/bash
if [ "$2" = "" ]; then
MSG=$(comsg 2>/dev/null)
[ $? -eq 0 ] && [ -n "$MSG" ] && echo "$MSG" > "$1"
fi| Provider | Model |
|---|---|
| OpenAI | gpt-4o |
| Anthropic | claude-sonnet-4-20250514 |
Override with -m:
comsg -m gpt-4o-mini
comsg -p anthropic -m claude-haiku-4-20250514MIT