feat(commit): add AI-generated commit message support.#5389
feat(commit): add AI-generated commit message support.#5389Blankeos wants to merge 2 commits intojesseduffield:masterfrom
Conversation
Add configuration options for generating commit messages using AI via
CLI commands or OpenAI-compatible APIs. Includes support for .env files
and {env:VAR} syntax for secure API key management.
| # AI commit message generation config | ||
| ai: | ||
| # CLI-based generation: runs a command with the staged diff piped to stdin. | ||
| # Example: "claude -p 'Generate a conventional commit message for this diff:'" | ||
| cli: | ||
| # The shell command to run. The staged diff is piped to stdin. | ||
| command: "" | ||
|
|
||
| # OpenAI-compatible API generation | ||
| api: | ||
| # OpenAI-compatible base URL, e.g. "https://api.openai.com/v1" | ||
| endpoint: "" | ||
|
|
||
| # Model name, e.g. "gpt-4o" or "llama3" | ||
| model: "" | ||
|
|
||
| # API key value. Use {env:MY_API_KEY} to read from an environment variable. | ||
| apiKey: "" | ||
|
|
||
| # System prompt. Defaults to a conventional commit prompt if omitted. | ||
| systemPrompt: "" |
There was a problem hiding this comment.
Personally, I don't think we should make the integration like this. All we need is a command that can be triggered to generate a commit. Then the user can configure it however they want. No need for custom integrations and vendor specific things.
There was a problem hiding this comment.
generate a PR.
I hope you mean generate a commit . And also.. if I get this right, you're saying:
- ✅
ai.cli.command- is good - ❌
ai.apifields - is bad because lazygit shouldn't have integrations like this.
I agree I think it'll keep this PR a lot leaner. And less burden on lazygit.
# OpenAI-compatible API generation
api:
# OpenAI-compatible base URL, e.g. "https://api.openai.com/v1"
endpoint: ""
# Model name, e.g. "gpt-4o" or "llama3"
model: ""
# API key value. Use {env:MY_API_KEY} to read from an environment variable.
apiKey: ""
# System prompt. Defaults to a conventional commit prompt if omitted.
systemPrompt: ""
I thought of adding it because people might just wanna hook up their own ai integrations as quickly as possible without installing a coding agent / anything. If that's the case, there should probably be a recommended minimal cli used alongside here just for this purpose. The closest I know is (https://github.com/simonw/llm). But tbh I think I could just make one in rust.
There was a problem hiding this comment.
Sorry I meant commit indeed.
Yeah I have the feeling this will never be accepted with all that custom logic. So the simpler the change will be, the better.
There was a problem hiding this comment.
I made that minimal CLI: https://github.com/Blankeos/modelcli
I'll go ahead and tweak an alternate PR with those minimal changes.
|
I made a simplified PR here btw: #5395 A command-only version. No more of the OpenAI compatible endpoint. |
|
Better, this one can be closed then |
PR Description
Adds support for generating commit messages from staged changes using AI, via two approaches:
claude -p "...", codex,opencode run "...",codex exec "...", etc.) - utilizing non-interactive cli modes of your favorite agents!It's also intuitive because it's editable, it just fills out the commit input fields so you can check before committing. Other custom workarounds before this PR had no choice but to run
git commitimmediately.Note: You must configure under
git.commit.aiin your lazygit config. API keys can be referenced via{env:MY_VAR} to keep secrets out of config files — lazygit also supports a .env file in the
config directory for this. Inspired by OpenCode
A new keybinding in the commit message panel triggers generation and shows a "Generating..."
status while waiting. Editing and submitting are blocked until the response arrives.
lazygitPR-opt.mp4
Please check if the PR fulfills these requirements
go generate ./...)