cmt - AI-Powered Git Commit Message Generator
cmt
is a command-line tool that generates meaningful git commit messages using AI models. 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 Sonnet 3.7 (default)
- OpenAI's GPT-4o
- 📝 Follows conventional commit format (
type: subject
) - 💡 Contextual hints to guide message generation
Installation
Using Install Script (Recommended)
The easiest way to install cmt
is using our install script:
|
This will automatically download and install the latest version for your platform.
Installing from crates.io
You can also install cmt
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
CLI tool that generates commit messages using AI
Usage: cmt [OPTIONS]
Options:
-m, --message-only
Only output the generated commit message, without formatting
--no-diff-stats
Hide the diff statistics for staged changes
--show-raw-diff
Show the raw git diff that will be sent to the AI model
--context-lines <CONTEXT_LINES>
Number of context lines to show in the git diff [default: 12]
--model <MODEL>
Use a specific AI model (defaults to claude-3-7-sonnet-latest or gpt-4o depending on provider)
-t, --temperature <TEMPERATURE>
Adjust the creativity of the generated message (0.0 to 2.0)
--hint <HINT>
Add a hint to guide the AI in generating the commit message
--max-lines-per-file <MAX_LINES_PER_FILE>
Number of maximum lines to show per file in the git diff [default: 500]
--max-line-width <MAX_LINE_WIDTH>
Maximum line width for diffs [default: 300]
--template <TEMPLATE>
Use a specific template for the commit message
--list-templates
List all available templates
--list-models
List all available models for the selected provider
--create-template <CREATE_TEMPLATE>
Create a new template
--template-content <TEMPLATE_CONTENT>
Content for the new template (used with --create-template)
--show-template <SHOW_TEMPLATE>
Show the content of a specific template
--include-recent-commits
Include recent commits for context
--recent-commits-count <RECENT_COMMITS_COUNT>
Number of recent commits to include for context [default: 5]
--init-config
Create a new configuration file
--config-path <CONFIG_PATH>
Path to save the configuration file (defaults to .cmt.toml in current directory)
--provider <PROVIDER>
Use a specific provider (claude, openai, etc.) [default: claude]
-h, --help
Print help
-V, --version
Print version
Examples
# Generate a commit message with diff statistics (default)
# Show the raw git diff that will be sent to the AI
# Generate a commit message without diff statistics
# Use OpenAI with a custom temperature
# Provide a hint for context
# List all available templates
# List all available models for the current provider
# List all available models for a specific provider
# Show the content of a specific template
# Create a custom template
# Use a specific template
# Combine multiple options
# Use with git commit directly
How It Works
- When you run
cmt
, it analyzes your staged git changes - The changes are sent to the selected AI model (Claude or OpenAI) along with:
- A system prompt that guides the model to generate conventional commits
- Your optional hint for additional context
- The staged changes as the user prompt
- The AI generates a commit message following the conventional commit format
- The message is displayed (with optional diff statistics) or output directly for use with git
You can view available models for each provider using the --list-models
flag, which dynamically fetches the latest available models from the provider's API.
Template Management
cmt
supports customizable templates for formatting commit messages. Templates use the Handlebars templating language.
Available Templates
By default, cmt
comes with three built-in templates:
conventional
(default): Standard conventional commit formatsimple
: A simplified format without the commit typedetailed
: Extended format with support for breaking changes and issue references
You can list all available templates with:
Creating Custom Templates
You can create your own templates in the ~/.config/cmt/templates/
directory:
# Create a custom template
Templates are stored as .hbs
files and can use the following variables:
{{type}}
: The commit type (feat, fix, docs, etc.){{subject}}
: The commit subject line{{details}}
: The detailed description of changes{{scope}}
: The scope of the change (optional){{breaking}}
: Breaking change information (optional){{issues}}
: Related issue references (optional)
Using Templates
To use a specific template:
You can also set a default template in your .cmt.toml
configuration file:
= "my-template"
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
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.