A CLI tool that generates descriptive commit messages using OpenCode's AI capabilities. Simply run git commit and let AI analyze your staged changes to create meaningful commit messages.
- AI-powered commit message generation using OpenCode
- Dual mode support: run via CLI subprocess or connect to OpenCode server
- Automatic large diff summarization (handles diffs > 32KB)
- Multiple commit styles: conventional, imperative, detailed
- Interactive confirmation: accept, edit, or regenerate messages (CLI and Git Hook)
- Git hook integration for automatic message generation
- Highly configurable via YAML, environment variables, or CLI flags
- Go 1.21 or later (for building from source)
- OpenCode installed and available in PATH
- Git repository
git clone https://github.com/avgt93/commit-gen
cd commit-gen
make installmake build # Build the binary
make install # Build and install to /usr/local/bin
make test # Run all tests
make clean # Remove build artifacts
make run # Build and run the CLI
make lint # Run linter
make fmt # Format code
make release # Build cross-platform releasesgo build -o commit-gen ./cmd/commit-gen
sudo mv commit-gen /usr/local/bin/commit-gen initThis creates a configuration file at ~/.config/commit-gen/config.yaml with default settings.
commit-gen healthcd /path/to/your/repo
commit-gen installgit add .git commitThe tool will analyze your staged changes and generate a descriptive commit message automatically. The message will open in your editor (or show a prompt in CLI) for you to review, edit, or regenerate.
Available Commands:
cache Manage session cache
completion Generate the autocompletion script for the specified shell
config Manage configuration
generate Generate a commit message from staged changes
health Check if the OpenCode backend is available
help Help about any command
init Initialize the configuration file
install Install git hook for automatic commit message generation
preview Preview changes and generated commit message
uninstall Remove the git hook
version Show version information
When running commit-gen generate (without --no-confirm) or git commit with the hook installed:
- AI analyzes staged changes and generates a message.
- An interactive prompt appears (CLI) or editor opens (Git Hook).
- Choose to:
- Accept: Use the generated message.
- Edit: Modify the message in your terminal editor.
- Regenerate: Ask AI to try again for a different result.
- Cancel: Abort the commit/generation.
# Generate and apply commit message (interactive)
commit-gen generate
# Skip confirmation/prompt
commit-gen generate --no-confirm
commit-gen generate -n
# Preview without applying
commit-gen generate --dry-runThe tool will analyze your staged changes and generate a descriptive commit message automatically.
Available Commands:
cache Manage session cache
completion Generate the autocompletion script for the specified shell
config Manage configuration
generate Generate a commit message from staged changes
health Check if the OpenCode backend is available
help Help about any command
init Initialize the configuration file
install Install git hook for automatic commit message generation
preview Preview changes and generated commit message
uninstall Remove the git hook
version Show version information
# Generate and apply commit message
commit-gen generate
# Preview without applying
commit-gen generate --dry-run
# Specify commit style
commit-gen generate --style imperative
# Use server mode instead of default run mode
commit-gen generate --mode server# Show staged diff and generated message
commit-gen preview# Initialize config file (first-time setup)
commit-gen init
# View current configuration
commit-gen config# Show cache status
commit-gen cache status
# Clear all cached sessions
commit-gen cache clear# Install hook
commit-gen install
# Remove hook
commit-gen uninstall# Check OpenCode backend availability
commit-gen healthUses opencode run CLI command directly. No server required.
commit-gen generate --mode runBenefits:
- No need to start OpenCode server
- Simpler setup
- Faster for single commits
Connects to OpenCode HTTP API server.
# Start server in another terminal
opencode serve
# Use server mode
commit-gen generate --mode serverBenefits:
- Session caching for context reuse
- Better for frequent commits
- Supports concurrent requests
Configuration hierarchy (highest to lowest priority):
- CLI flags
- Environment variables (
COMMIT_GEN_*prefix) - Config file (
~/.config/commit-gen/config.yaml) - Default values
Run commit-gen init to create the configuration file, or manually create ~/.config/commit-gen/config.yaml:
opencode:
mode: run # "run" or "server"
host: localhost # server mode only
port: 4096 # server mode only
timeout: 120
generation:
style: conventional # conventional, imperative, detailed
confirm: true # prompt to confirm/edit message before committing
model:
provider: opencode
model_id: gpt-5-nano
cache:
enabled: true # server mode only
ttl: 24h
git:
staged_only: true
editor: "" # editor for commit messages (defaults to $EDITOR or vim)
max_diff_size: 32768 # bytes before summarizing (32KB default)export COMMIT_GEN_OPENCODE_MODE=run
export COMMIT_GEN_OPENCODE_HOST=localhost
export COMMIT_GEN_OPENCODE_PORT=4096
export COMMIT_GEN_GENERATION_STYLE=conventional
export COMMIT_GEN_GENERATION_MODEL_PROVIDER=google
export COMMIT_COMMIT_GEN_GENERATION_MODEL_MODEL_ID=antigravity-gemini-3-pro
export COMMIT_GEN_GIT_MAX_DIFF_SIZE=32768Format: type(scope): description
Types: feat, fix, docs, style, refactor, perf, test, chore
Examples:
feat(auth): add user authenticationfix(api): handle null pointer exceptiondocs(readme): update installation steps
Uses the imperative mood, as if commanding someone.
Examples:
Add user authentication to login pageFix null pointer exception in API handlerUpdate README with installation steps
Format: type(scope): description with optional body
Examples:
feat(auth): add user authenticationfix(api): handle null pointer exception in getUser endpoint
When staged changes exceed 32KB (configurable via git.max_diff_size), the diff is automatically summarized for AI processing. The summary includes:
- List of changed files
- Diff statistics (insertions/deletions)
- Truncated diff content
- Note to AI about summarization
This prevents failures with large commits while still providing meaningful context.
Ensure OpenCode is installed and available:
which opencodeStart OpenCode server:
opencode serveStage your changes first:
git add .Verify installation:
cat .git/hooks/prepare-commit-msgReinstall if needed:
commit-gen uninstall
commit-gen installRun with sudo:
sudo make installOr manually copy binary:
make build
sudo cp commit-gen /usr/local/bin/commit-gen/
├── cmd/commit-gen/ # CLI entry point
├── internal/
│ ├── git/ # Git operations
│ ├── opencode/ # OpenCode client and runner
│ ├── config/ # Configuration management
│ ├── cache/ # Session caching
│ ├── generator/ # Commit message generation
│ └── hook/ # Git hook management
├── Makefile
└── README.md
# Build
make build
# Run tests
make test
# Format code
make fmt
# Run linter
make lint
# Clean build artifacts
make cleanSee AGENTS.md for detailed architecture documentation.
Contributions welcome:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
MIT
- GitHub Issues: submit an issue
- OpenCode Discord: join the community