An AI-powered Git commit message generator that analyzes your staged changes and creates conventional commit messages using Claude AI.
git-cmt automatically generates meaningful commit messages based on your staged changes using Anthropic's Claude AI. It follows the Conventional Commits specification and provides an interactive commit experience.
This project was created for the 2025-08-17 issue of The Applied Go Weekly Newsletter
Feel free to play with the code to change providers and models, try different prompts, and more. It's just around 110 lines of code.
BTW, parts of this README are LLM-generated, so I apologize in advance for the verbosity, but I didn't want to cut down the amount of information too much, to increase the chance that you'll be finding what you're looking for.
- 🤖 AI-powered: Uses Claude 3.5 Haiku to analyze code changes (but you can switch models and providers using LangChainGo's selection of provider-specific sub-packages)
- 📝 Conventional Commits: Generates messages following the
type(scope): description
format - 🎯 Smart Analysis: Understands code changes and creates contextually appropriate messages
- ⚡ Interactive: Opens your editor for final review before committing
- 🔍 Diff-aware: Only analyzes currently staged changes
- 📏 Length-aware: Keeps commit messages concise (50 chars max for description)
- Go 1.25.0 or later (surely works with earlier versions, too, just change the Go version in
go.mod
and test it out) - Git
- An Anthropic API key (or, if you change the code to use another provider, their API key. Or, if you use a local AI... no API key)
go install github.com/appliedgocode/git-cmt
git clone https://github.com/appliedgocode/git-cmt
cd git-cmt
go build -o git-cmt
# Move to a directory in your PATH
sudo mv git-cmt /usr/local/bin/
- Set your Anthropic API key:
export ANTHROPIC_API_KEY="your-api-key-here"
-
Stage your changes:
git add <whatever you have to add>
-
Generate and commit:
./git-cmt
-
Review and edit the generated message in your default editor
-
Save and close to complete the commit
- Diff Analysis: Reads staged changes using
git diff --cached -b
- AI Processing: Sends the diff to Claude AI with structured prompts
- Message Generation: Creates a commit object with type, scope, and description
- Interactive Commit: Opens your editor with the generated message for review
- Final Commit: Executes
git commit
with your approved message
The AI generates messages following this structure:
type(scope): description
Types: feat, fix, docs, style, refactor, test, chore
Scope: Optional component/module name
Description: Clear, concise summary (max 50 chars)
If you're new to Conventional Commits, start here.
$ ./git-cmt
# Generated: feat(auth): add OAuth2 login integration
$ ./git-cmt
# Generated: fix(api): resolve null pointer in user validation
$ ./git-cmt
# Generated: docs(readme): update installation instructions
ANTHROPIC_API_KEY
: Required for Claude API accessEDITOR
: Controls which editor opens for message review (defaults to system default)
- Change the provider and/or model
- Change
anthropic.WithModel()
to use different Claude models - Use a different LangChainGo subpackage (
openai
,ollama
,...) to switch the provider - Use the
openai
package andopenai.WithURL()
to use an OpenAI-compatible API of a third-party provider
- Change
- Update the prompt template in
generateMessage()
for custom behavior - Let
git-cmt
present an empty commit message if the call to the LLM fails, instead of erroring out - Make provider and model configurable in a config file
- Use a secrets manager to securely obtain the API key instead of an environment variable
- No staged changes: Exits with helpful message
- API key missing: Prompts to set
ANTHROPIC_API_KEY
- API failures: Provides detailed error messages
- Invalid JSON: Shows raw response for debugging
github.com/tmc/langchaingo
- LLM integration- Claude AI via Anthropic API
├── main.go # Core application logic
├── go.mod # Go module definition
├── go.sum # Dependency checksums
└── README.md # This file
go build
This project is open source. Check the repository for specific license details.
"No staged changes found"
- Ensure you've run
git add
to stage files
"ANTHROPIC_API_KEY not set"
- Set the environment variable with your API key
"LLM request failed"
- Check your internet connection
- Verify your API key is valid
- Ensure you have credits on your Anthropic account
Editor not opening
- Set your preferred editor:
export EDITOR="code --wait"