AI for generating commit message and PR title
lazycommit
AI-powered Git commit message generator. It reads your staged diff, asks an LLM through any OpenAI-compatible API, and prints clean commit message suggestions โ one per line, ready to pipe into lazygit, fzf, or any TUI menu.
Features
- Suggests a configurable number of commit messages from
git diff --cached - Suggests pull request titles from the merge-base diff against a target branch
- Works with any OpenAI-compatible endpoint: OpenAI, Ollama (local, keyless), OpenRouter, LM Studio, enterprise proxies
- Model fallback chain, request retry, and timeouts built in
- Any output language (English, Arabic, Korean, ...)
- Plain-line output designed for piping into TUI menus
Installation
go install github.com/m7medvision/lazycommit@latest
Or build from source:
git clone https://github.com/m7medvision/lazycommit.git
cd lazycommit
make build
Quick start
lazycommit config set # choose model, endpoint, key, language
git add .
lazycommit commit
CLI
lazycommit commitโ prints commit message suggestions for the staged diff, one per line.lazycommit pr <target-branch>โ prints pull request title suggestions for the diff against<target-branch>.lazycommit config setโ interactive setup (model, endpoint, API key, language).lazycommit config getโ shows the active backend, model, and language; API keys are masked.
- No staged changes: prints
No staged changes to commit.and exits 0. - Configuration or backend errors: message on stderr, non-zero exit, stdout stays clean.
Configuration
Two files, deliberately split:
1. Backend settings โ ~/.config/lazycommit/config.yaml
API keys and endpoints. Do not commit this file. It is written with owner-only permissions.
active_backend: openai-compatible
backends:
openai-compatible:
model: gpt-4o-mini
apikey: "$OPENAIAPIKEY" # plain value or $ENVVAR reference
# base_url: https://api.openai.com/v1 # optional, default is official OpenAI
# fallback_models: # tried in order when the model fails
# - gpt-4o
2. Prompt settings โ ~/.config/lazycommit/prompts.yaml
Shareable, safe for dotfiles:
language: English
num_suggestions: 10
system_message: ...
commitmessagetemplate: "... %s" # %s is replaced by the diff
prtitletemplate: "... %s"
Any repository can override prompt settings with a lazycommit.prompts.yaml in its root; unset fields fall through to the global file, then to built-in defaults:
# my-korean-project/lazycommit.prompts.yaml
language: Korean
num_suggestions: 5
Endpoint examples
Ollama (local, no key):
active_backend: openai-compatible
backends:
openai-compatible:
model: llama3.1:8b
base_url: http://localhost:11434/v1
OpenRouter:
active_backend: openai-compatible
backends:
openai-compatible:
model: openai/gpt-4o-mini
apikey: "$OPENROUTERAPI_KEY"
base_url: https://openrouter.ai/api/v1
Integration with TUI Git clients
lazycommit commit prints plain lines, so it plugs directly into menu UIs.
fzf
git add .
lazycommit commit | fzf --prompt='Pick commit> ' | xargs -r -I {} git commit -m "{}"
Lazygit
Add to ~/.config/lazygit/config.yml:
customCommands:
- key: "<c-a>"
description: "pick AI commit"
command: 'git commit -m "{{.Form.Msg}}"'
context: "files"
prompts:
- type: "menuFromCommand"
title: "AI commits"
key: "Msg"
command: "lazycommit commit"
filter: "^(?P<raw>.+)$"
valueFormat: "{{ .raw }}"
labelFormat: "{{ .raw | green }}"
Variant that lets you edit the message before committing:
- key: "<c-b>"
description: "Pick AI commit (edit before committing)"
context: "files"
command: >
bash -c 'msg="{{.Form.Msg}}"; echo "$msg" > .git/COMMITEDITMSG && ${EDITOR:-nvim} .git/COMMITEDITMSG && if [ -s .git/COMMIT_EDITMSG ]; then
git commit -F .git/COMMIT_EDITMSG;
else
echo "Commit message is empty, commit aborted.";
fi'
prompts:
- type: "menuFromCommand"
title: "AI commits"
key: "Msg"
command: "lazycommit commit"
filter: "^(?P<raw>.+)$"
valueFormat: "{{ .raw }}"
labelFormat: "{{ .raw | green }}"
output: terminal
Troubleshooting
No staged changes to commit.โ rungit addfirst.has no model configuredโ runlazycommit config set.environment variable X is not setโ your config references$X; export it or store the key directly.
License
MIT