cmt - AI-Powered Git Commit Message Generator
cmt
is a command-line tool that generates meaningful git commit messages using AI models (Anthropic Claude or OpenAI GPT). It analyzes your staged changes and generates a well-formatted, descriptive commit message following conventional commit standards.
Features
- 🤖 Supports multiple AI models:
- Anthropic's Claude 3.5 Sonnet (default, temperature 0.3)
- OpenAI's GPT-4 Optimized (temperature 1.0)
- 📝 Follows conventional commit format (
type: subject
) - 🎨 Beautiful colored output in interactive mode
- 📊 Optional diff statistics
- ⚙️ Configurable AI model and parameters
- 🔑 Supports environment variables for API keys
Installation
Prerequisites
- Rust and Cargo (install from rustup.rs)
- An Anthropic API key and/or OpenAI API key
Installing from crates.io
The easiest way to install cmt
is directly from crates.io:
Installing from source
Alternatively, you can build from source:
# Clone the repository
# Build and install
Configuration
Set your API key(s) either:
- As environment variables:
# For Claude (default) # For OpenAI (optional)
- Or in a
.env
file in your project directory:ANTHROPIC_API_KEY=your-api-key OPENAI_API_KEY=your-api-key
Usage
Basic Usage
# Stage your changes first
# Generate a commit message using Claude (default)
# Generate a commit message using OpenAI
# Use the generated message directly with git
Command-line Options
Usage: cmt [OPTIONS]
Options:
-m, --message-only Only output the generated message, without formatting
-s, --show-diff Show the diff statistics
--model <MODEL> Use a specific AI model (defaults to claude-3.5-sonnet-latest or gpt-4o)
--openai Use OpenAI instead of Claude (which is default)
-t, --temperature <TEMP> Adjust the creativity of the message (0.0 to 2.0)
[default: 0.3 for Claude, 1.0 for OpenAI]
-h, --help Show this help message
-V, --version Show version information
Examples
# Show diff statistics along with the message
# Use OpenAI with a specific model
# Use Claude with a specific model
# Override default temperature
# Generate just the message (useful for scripts)
Commit Message Format
The generated commit messages follow the conventional commit format:
type: subject
- Detailed change 1
- Detailed change 2
Where type
is one of:
feat
: New featuresfix
: Bug fixesdocs
: Documentation changesstyle
: Code style changes (formatting, etc.)refactor
: Code refactoringtest
: Adding or modifying testschore
: Maintenance tasks
Development
Building from source
# Clone the repository
# Build
# Run tests
# Run in development
Dependencies
git2
: Git operationsreqwest
: HTTP client for OpenAI APIclap
: Command-line argument parsingcolored
: Terminal colorsserde
: JSON serializationdotenv
: Environment variable management
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.