A standalone CLI tool that generates conventional commit messages using AI. Commitgen analyzes your git changes and creates descriptive, properly formatted commit messages automatically.
- Features
- Installation
- Usage
- Provider Management
- Configuration
- Output Format
- Development
- Advanced Usage
- Contributing
- Requirements
- License
- Multiple Analysis Modes: Staged files, all changes, or untracked files
- Conventional Commits: Follows
type(scope): descriptionformat - Smart Scope Detection: Automatically extracts service/module from file paths
- Flexible AI Providers: Built-in support for Claude, Gemini, Copilot, OpenCode, Kilo, Cursor, Aider, and more
- Custom Providers: Add any AI CLI tool as a provider
- Interactive: Preview and confirm commit messages before committing
npm install -g @freepik/commitgenpnpm install -g @freepik/commitgenyarn global add @freepik/commitgen# Generate commit message from staged files (default)
commitgen
# Or explicitly
commitgen commit staged
commitgen commit s
# Generate from all changes (stages + commits)
commitgen commit all
commitgen commit a
# Generate from untracked files only
commitgen commit untracked
commitgen commit u# Use Claude (default)
commitgen
commitgen --provider claude
# Use Gemini
commitgen --provider gemini
# Use Copilot
commitgen --provider copilot
# Use OpenCode
commitgen --provider opencode
# Use provider with specific subcommand
commitgen commit staged --provider gemini
commitgen commit all --provider copilot
# Use Kilo
commitgen --provider kilo
# Use Cursor
commitgen --provider cursorcommitgen provider listOutput:
Available providers:
* claude: claude
gemini: gemini
copilot: copilot
opencode: opencode run
kilo: kilo
cursor: cursor-agent
aider: aider
* = default provider
Config file: ~/.commitgen/config.json
commitgen provider default kiloAdd any AI CLI tool as a provider:
# Basic provider
commitgen provider add myai --command myai-cli
# Provider with arguments
commitgen provider add custom-ai --command custom-ai --args="--non-interactive" --args="--model=gpt-4"commitgen provider remove myaiCommitgen uses your existing AI CLI commands and configuration. Make sure you have:
- AI CLI commands available in your PATH (built-in support for):
claudefor Claudegeminifor Geminicopilotfor Copilotopencodefor OpenCodekilofor Kilocursor-agentfor Cursoraiderfor Aidercontinuefor Continuecodeiumfor Codeium
- Proper API keys configured for your chosen AI provider
- Git repository initialized
Configuration is stored in ~/.commitgen/config.json:
{
"defaultProvider": "claude",
"providers": {
"my-custom-ai": {
"command": "my-ai-cli",
"args": ["--non-interactive"]
}
}
}Commitgen generates conventional commit messages following this format:
type(scope): description
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, etc.)refactor: Code refactoringtest: Test additions/changeschore: Maintenance tasks
Examples:
feat(service:rating): add get RestaurantQuickReview with cachingfix(api:user): resolve null pointer in validationdocs(readme): update setup instructions
go build -o commitgen main.gogo test ./...go build -o commitgen main.go
./commitgen install- Go 1.19+
- Git
- AI CLI commands with proper API configuration (any of these):
claudefor Claude (Anthropic)geminifor Gemini (Google)copilotfor Copilot (GitHub)opencodefor OpenCodekilofor Kilocursor-agentfor Cursoraiderfor Aider- Or any custom AI CLI tool (add with
commitgen provider add)
- Unix-like system (Linux, macOS)
Commitgen automatically analyzes git changes and provides context to the AI model:
- Staged changes: Uses
git diff --cachedto review staged modifications - All changes: Combines modified files and untracked files for comprehensive analysis
- Untracked files: Reads content of new files that haven't been added to git yet
"not in a git repository"
- Make sure you're in a directory with a
.gitfolder - Run
git initif starting a new repository
"no changes found to analyze"
- Stage some files with
git add <files> - Or use
commitgen commit allto include unstaged changes - Use
commitgen commit untrackedfor new files
"failed to call [provider] API"
- Ensure the AI CLI command is available in your PATH
- Verify API keys are properly configured
- Test the AI CLI command directly:
claudeorgeminiorcopilotoropencode
OpenCode
# Install OpenCode
curl -fsSL https://opencode.ai/install.sh | bash
# Login
opencode auth loginClaude (Default)
# Install claude
pip install claude
# Configure API key in environment
export ANTHROPIC_API_KEY="your-key-here"Gemini
# Install Gemini CLI
npm install -g @google-cloud/vertexai
# Configure authentication
gcloud auth application-default loginCopilot
# Install GitHub CLI with Copilot extension
gh extension install github/gh-copilot
# Login to GitHub
gh auth loginYou can integrate commitgen into your git workflow using hooks:
# Set up prepare-commit-msg hook
echo '#!/bin/bash
if [ -z "$2" ]; then
./commitgen --provider claude > .git/COMMIT_EDITMSG.tmp
if [ -f .git/COMMIT_EDITMSG.tmp ]; then
cat .git/COMMIT_EDITMSG.tmp > "$1"
rm .git/COMMIT_EDITMSG.tmp
fi
fi' > .git/hooks/prepare-commit-msg
chmod +x .git/hooks/prepare-commit-msgContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
commitgen commit staged) - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE file for details.