AI-powered Git commit message generator that analyzes your staged changes and outputs conventional commit messages.
- Generates 10 commit message suggestions from your staged diff
- Providers: GitHub Copilot (default), OpenAI, OpenRouter
- Interactive config to pick provider/model and set keys
- Simple output suitable for piping into TUI menus (one message per line)
go install github.com/m7medvision/lazycommit@latest
Or build from source:
git clone https://github.com/m7medvision/lazycommit.git
cd lazycommit
go build -o lazycommit main.go
- Root command:
lazycommit
- Subcommands:
lazycommit commit
— prints 10 suggested commit messages to stdout, one per line, based ongit diff --cached
.lazycommit config get
— prints the active provider and model.lazycommit config set
— interactive setup for provider, API key, and model.
Exit behaviors:
- If no staged changes: prints "No staged changes to commit." and exits 0.
- On config/LLM errors: prints to stderr and exits non‑zero.
Generate suggestions after staging changes:
git add .
lazycommit commit
Pipe the first suggestion to commit (bash example):
MSG=$(lazycommit commit | sed -n '1p')
[ -n "$MSG" ] && git commit -m "$MSG"
Pick interactively with fzf
:
git add .
lazycommit commit | fzf --prompt='Pick commit> ' | xargs -r -I {} git commit -m "{}"
- Config directory (
~/.config/.lazycommit.yaml
active_provider: copilot # default if a GitHub token is found
providers:
copilot:
api_key: "$GITHUB_TOKEN" # Uses GitHub token; token is exchanged internally
model: "gpt-4o" # or "openai/gpt-4o"; both accepted
openai:
api_key: "$OPENAI_API_KEY"
model: "gpt-4o"
openrouter:
api_key: "$OPENROUTER_API_KEY" # or a literal key
model: "openai/gpt-4o" # OpenRouter model IDs, e.g. anthropic/claude-3.5-sonnet
Notes:
- Copilot: requires a GitHub token with models scope. The tool can also discover IDE Copilot tokens, but models scope is recommended.
- Environment variable references are supported by prefixing with
$
(e.g.,$OPENAI_API_KEY
).
lazycommit config set # interactive provider/model/key picker
lazycommit config get # show current provider/model
Because lazycommit commit
prints plain lines, it plugs nicely into menu UIs.
Add this to ~/.config/lazygit/config.yml
:
customCommands:
- key: "<c-a>" # ctrl + 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 }}"
Tips:
- For
lazycommit commit
, you can omitfilter
and just usevalueFormat: "{{ .raw }}"
andlabelFormat: "{{ .raw | green }}"
. - If you pipe a numbered list tool (e.g.,
bunx bunnai
), keep the regex groupsnumber
andmessage
as shown.
- Copilot (default when a GitHub token is available): uses
gpt-4o
unless overridden. Acceptsopenai/gpt-4o
and normalizes it togpt-4o
. - OpenAI: choose from models defined in the interactive picker (e.g., gpt‑4o, gpt‑4.1, o3, o1, etc.).
- OpenRouter: pick from OpenRouter-prefixed IDs (e.g.,
openai/gpt-4o
,anthropic/claude-3.5-sonnet
). Extra headers are set automatically.
- Reads
git diff --cached
. - Sends a single prompt to the selected provider to generate 10 lines.
- Prints the lines exactly, suitable for piping/selecting.
- "No staged changes to commit." — run
git add
first. - "API key not set" — set the appropriate key in
.lazycommit.yaml
or env var and rerun. - Copilot errors about token exchange — ensure your GitHub token has models scope or is valid; try setting
GITHUB_TOKEN
.
MIT