AI Commit 🤖
Generate intelligent, conventional commit messages using Claude AI. No more struggling with commit message writer's block!
Features
- ✨ AI-Powered: Uses Claude AI to analyze your git diff and generate meaningful commit messages
- 📝 Conventional Commits: Follows conventional commit format (feat, fix, docs, etc.)
- 🔒 Secure: API keys stored securely with proper file permissions
- 🚀 Fast: Quick generation with Claude 3 Haiku
- 🎯 Smart: Contextual analysis of your actual code changes
- 💎 Ruby Gem: Simple installation and usage
Installation
Install the gem:
gem install smart-commit
Or add to your Gemfile:
gem 'smart-commit'
Setup
First, configure your Anthropic API key:
smart-commit setup
You'll be prompted to enter your API key. Get one at Anthropic Console.
Usage
Basic Usage
-
Stage your changes:
git add .
-
Generate a commit message:
smart-commit generate
-
The tool will analyze your diff and suggest a commit message:
✨ Generated commit message: feat: add user authentication with JWT tokens To commit with this message, run: git commit -m "feat: add user authentication with JWT tokens"
Commands
-
smart-commit setup
- Configure your API key -
smart-commit generate
- Generate commit message from staged changes -
smart-commit config
- Show current configuration -
smart-commit help
- Show help information
Examples
The AI generates contextual commit messages based on your actual changes:
# Adding a new feature
git add lib/user_auth.rb
smart-commit generate
# → "feat: add JWT-based user authentication system"
# Fixing a bug
git add lib/payment_processor.rb
smart-commit generate
# → "fix: handle null payment amounts in processor"
# Documentation updates
git add README.md
smart-commit generate
# → "docs: update installation instructions"
# Refactoring code
git add lib/user_model.rb
smart-commit generate
# → "refactor: extract user validation into separate method"
Configuration
API Key Storage
- Config stored in:
~/.smart-commit/config.yml
- File permissions:
600
(secure) - Environment variable:
ANTHROPIC_API_KEY
(fallback)
Customizing the Prompt
The commit message generation prompt can be customized by editing:
lib/ai/commit/claude_client.rb
in the build_prompt
method.
Requirements
- Ruby 3.1.0+
- Git repository
- Anthropic API key
- Staged changes in git
Development
After checking out the repo:
bin/setup # Install dependencies
rake test # Run tests
bin/console # Interactive prompt
bundle exec exe/smart-commit # Run locally
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/bmirzamani/smart-commit.
License
The gem is available as open source under the terms of the MIT License.
Changelog
See CHANGELOG.md for version history.
Made with ❤️ by Behrang Mirzamani