An AI-powered git commit message generator with repository context awareness, built with Python and Typer.
As developers, we know the importance of good commit messages. They serve as a historical record, help with debugging, facilitate code reviews, and make collaboration seamless. But let's be honest - writing detailed, meaningful commit messages consistently is hard.
Time Pressure & Context Switching: When you're juggling multiple projects simultaneously, switching between different codebases, technologies, and contexts, it becomes increasingly difficult to craft thoughtful commit messages. What used to be a natural part of your workflow becomes a bottleneck.
Cognitive Load: After spending hours deep in code, the last thing you want to do is context-switch to writing prose. Your brain is in "code mode," not "documentation mode."
Consistency Across Projects: Each project has its own conventions, tech stack, and commit patterns. Maintaining consistency becomes nearly impossible when you're working on 3-4 different repositories in a single day.
The Vicious Cycle: Poor commit messages lead to poor project history. When you need to understand what changed and why (during debugging, code reviews, or onboarding new team members), cryptic messages like "fix stuff" or "update" provide zero value.
Smart Commit understands your repository context - the tech stack, recent commit patterns, file changes, and project structure. It generates meaningful, detailed commit messages that:
- Capture the "Why": Not just what changed, but the reasoning behind the change
- Maintain Consistency: Follows your project's established patterns and conventions
- Save Mental Energy: Let AI handle the prose while you focus on the code
- Preserve History: Create a rich, searchable project timeline that actually helps future you
Example of the difference:
Instead of:
fix auth bug
update dependencies
refactor components
You get:
fix(auth): resolve JWT token expiration handling
- Fix race condition in token refresh mechanism
- Add proper error handling for expired tokens
- Update token validation middleware
- Add unit tests for edge cases
This resolves the issue where users were unexpectedly logged out
during active sessions due to improper token lifecycle management.
Smart Commit turns your commit history into a valuable project resource that tells the story of your codebase evolution.
- π§ AI-Powered: Uses OpenAI GPT and Anthropic Claude models to generate meaningful commit messages
- π Repository Context: Analyzes your repo structure, tech stack, and recent commits
- βοΈ Configurable: Global and local configuration with conventional commit support
- π₯οΈ CLI Interface: Rich, interactive command-line interface with Typer
- π§ MCP Server: Model Context Protocol server for integration with AI assistants
- π― Smart Filtering: Ignore patterns and custom rules per repository
- π Interactive Editing: Edit generated messages before committing
- ποΈ Context Files: Include project documentation for enhanced understanding
- π¨ Custom Templates: Configurable commit message formats and examples
- Python 3.10 or higher
- Git repository (for generating commit messages)
- API key for your chosen AI provider (100+ models supported thanks to LiteLLM)
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install and run as a tool (system-wide install)
uv tool install smart-commit-ai
# Use the tool in any repository
sc generate
pip install smart-commit-ai
# Install with Anthropic support
pip install smart-commit-ai[anthropic]
# Install with all optional dependencies
pip install smart-commit-ai[all]
smart-commit
is configured primarily through environment variables, which is secure and flexible.
# Set your AI model and API key
export AI_MODEL="openai/gpt-4o" # Or "claude-3-sonnet-20240229", "gemini/gemini-1.5-pro", etc.
export AI_API_KEY="your-super-secret-api-key"
# You can add these to your .bashrc, .zshrc, or shell profile to make them permanent.
The AI_MODEL
can be set to any model supported by litellm
. For a full list of available providers and model names, please refer to the LiteLLM Provider Documentation.
You can also run the setup command to save a fallback configuration file:
# This will guide you through saving a config file.
smart-commit setup
# Generate commit message for staged changes
smart-commit generate
# Add additional context
smart-commit generate --message "Fixes issue with user authentication"
# Auto-commit without confirmation
smart-commit generate --auto
# Dry run (generate message only)
smart-commit generate --dry-run
# Non-interactive mode
smart-commit generate --no-interactive
# Initialize configuration (with optional sample repo config)
smart-commit config --init
# Edit configuration
smart-commit config --edit
# Show current configuration
smart-commit config --show
# Local repository configuration
smart-commit config --init --local
# Shows detailed information about the current repository
smart-commit context
# Shows detailed information about a specific repository
smart-commit context /path/to/repo
Smart-commit supports both global and local configurations:
- Global:
~/.config/smart-commit/config.toml
- Local:
.smart-commit.toml
in your repository
The configuration now includes enhanced features for better commit message generation:
[ai]
model = "gpt-4o"
api_key = "your-api-key"
max_tokens = 500
temperature = 0.1
[template]
max_subject_length = 50
max_recent_commits = 5 # Number of recent commits to analyze
include_body = true
include_reasoning = true
conventional_commits = true
# Custom example formats for AI guidance
example_formats = [
"""feat: add user authentication system
- Implement JWT-based authentication
- Add login and logout endpoints
- Include password hashing with bcrypt
- Add authentication middleware for protected routes
This enables secure user sessions and protects sensitive endpoints from unauthorized access."""
]
# Enhanced commit type prefixes with descriptions
[template.custom_prefixes]
feat = "for new features"
fix = "for bug fixes"
docs = "for documentation changes"
style = "for formatting changes"
refactor = "for code refactoring"
test = "for test changes"
chore = "for maintenance tasks"
perf = "for performance improvements"
build = "for build system changes"
ci = "for CI/CD changes"
revert = "for reverting changes"
# Repository-specific configuration with enhanced context
[repositories.my-project]
name = "my-project"
description = "My awesome project"
absolute_path = "/absolute/path/to/project" # Explicit path for accessing context files globally
tech_stack = ["python", "react", "docker"]
ignore_patterns = ["*.log", "node_modules/**"]
context_files = ["README.md", "CHANGELOG.md"] # Files included in AI context
# Comprehensive commit conventions
[repositories.my-project.commit_conventions]
breaking = "Use BREAKING CHANGE: in footer for breaking changes that require major version bump"
scope = "Use scope in parentheses after type: feat(auth): add login system"
subject_case = "Use imperative mood in lowercase: 'add feature' not 'adds feature' or 'added feature'"
subject_length = "Keep subject line under 50 characters for better readability"
body_format = "Wrap body at 72 characters, use bullet points for multiple changes"
body_separation = "Separate subject from body with a blank line"
present_tense = "Use present tense: 'change' not 'changed' or 'changes'"
no_period = "Do not end the subject line with a period"
why_not_what = "Explain why the change was made, not just what was changed"
atomic_commits = "Make each commit a single logical change"
test_coverage = "Include test changes when adding new functionality"
docs_update = "Update documentation when changing public APIs or behavior"
Smart-commit automatically detects and uses:
- π Technology Stack: Languages, frameworks, and tools
- πΏ Branch Information: Active branches and current branch
- π Recent Commits: Configurable number of recent commits for pattern analysis
- π File Structure: Repository organization
- π Project Metadata: README descriptions and project info
- π Context Files: Project documentation included in AI context
- π― Absolute Paths: Precise file location for multi-repo setups
- π« Ignore Patterns: Custom patterns to exclude files from analysis
- ποΈ Commit Conventions: Project-specific commit message guidelines
Smart-commit includes MCP (Model Context Protocol) server support for integration with AI assistants like Claude Desktop.
# Run the MCP server directly
python -m smart_commit.mcp
# Or use it in your MCP client configuration
Add to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"smart-commit": {
"command": "python",
"args": ["-m", "smart_commit.mcp"]
}
}
}
analyze_repository
: Analyze repository structure and contextgenerate_commit_message
: Generate AI-powered commit messagesget_staged_changes
: Get current staged changesconfigure_smart_commit
: Update configuration settingsget_repository_context
: Get detailed repository informationquick_setup
: Quick configuration setupshow_configuration
: Display current configuration
repository://current
: Current repository informationconfig://smart-commit
: Smart-commit configuration
commit_message_template
: Template for commit message generationrepository_analysis_prompt
: Template for repository analysis
Add patterns to ignore specific files or changes:
[repositories.my-project]
ignore_patterns = [
"*.log",
"node_modules/**",
"dist/**",
"*.generated.*"
]
Include specific files for additional AI context:
[repositories.my-project]
absolute_path = "/home/user/projects/my-project"
context_files = [
"README.md",
"CHANGELOG.md",
"docs/contributing.md",
"API_REFERENCE.md"
]
The AI will read these files and use their content to better understand your project structure and generate more relevant commit messages.
Define project-specific commit types with clear descriptions:
[template.custom_prefixes]
feat = "for new features"
fix = "for bug fixes"
hotfix = "for critical production fixes"
security = "for security-related changes"
deps = "for dependency updates"
config = "for configuration changes"
Configure how many recent commits to analyze for pattern consistency:
[template]
max_recent_commits = 10 # Analyze last 10 commits for patterns
This helps maintain consistency with your existing commit style and conventions.
# Stage your changes
git add .
# Generate commit message
smart-commit generate
Example output:
Generated commit message:
feat: add user authentication system
- Implement JWT-based authentication
- Add login and logout endpoints
- Create user session management
- Add password hashing with bcrypt
This change introduces a complete authentication system to secure
user access and manage sessions effectively.
# Generate with additional context
smart-commit generate -m "Resolves GitHub issue #123"
# Auto-commit
smart-commit generate --auto
# Verbose output
smart-commit generate --verbose
# Initialize local config for your project
smart-commit config --init --local
# Will prompt: "Include sample repository configuration? [y/N]"
# This will create configuration including context files
# Edit .smart-commit.toml to specify your context files:
[repositories.my-project]
name = "my-project"
description = "My awesome project description"
absolute_path = "/full/path/to/project"
context_files = ["README.md", "docs/ARCHITECTURE.md"]
For developers working on multiple repositories:
# Global config at ~/.config/smart-commit/config.toml
[repositories.frontend-app]
name = "frontend-app"
description = "React frontend application"
absolute_path = "/home/dev/projects/frontend-app"
tech_stack = ["react", "typescript", "tailwind"]
context_files = ["README.md", "package.json"]
[repositories.backend-api]
name = "backend-api"
description = "Python FastAPI backend"
absolute_path = "/home/dev/projects/backend-api"
tech_stack = ["python", "fastapi", "postgresql"]
context_files = ["README.md", "requirements.txt", "docs/API.md"]
[repositories.mobile-app]
name = "mobile-app"
description = "React Native mobile application"
absolute_path = "/home/dev/projects/mobile-app"
tech_stack = ["react-native", "typescript", "expo"]
context_files = ["README.md", "app.json", "docs/SETUP.md"]
This allows Smart Commit to automatically understand the context of whichever repository you're working in and generate appropriate commit messages.
EDITOR
: Preferred editor for interactive message editing (default: nano)
"No staged changes found"
- Make sure you've staged your changes with
git add
- Check if you're in a git repository
"API key not configured"
- Run
smart-commit setup
to configure your API key
"AI provider error"
- Verify your API key is valid and has sufficient credits
- Check your internet connection
- Try switching to a different model
"Configuration not found"
- Run
smart-commit config --init
to create initial configuration - Check if the config file exists at
~/.config/smart-commit/config.toml
"Context file not found"
- Verify the
absolute_path
in your repository configuration is correct - Check that context files exist at the specified locations
- Use relative paths from the repository root if
absolute_path
is not set
# Run with verbose output for debugging
smart-commit generate --verbose
# Show configuration details
smart-commit config --show
# Analyze repository context
smart-commit context
# Clone the repository
git clone https://github.com/subhayu99/smart-commit.git
cd smart-commit
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install development dependencies
uv pip install -e ".[dev]"
# Install with all optional dependencies
uv pip install -e ".[all]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=smart_commit
# Format code
black smart_commit/
isort smart_commit/
# Type checking
mypy smart_commit/
# Run pre-commit hooks
pre-commit run --all-files
# Build the package
uv build
# Publish to PyPI (maintainers only)
uv publish
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests if applicable
- Run the test suite (
pytest
) - Commit your changes with a descriptive message
- Push to your branch (
git push origin feature/amazing-feature
) - Create a Pull Request
MIT License - see LICENSE file for details.
- Plugin system for custom commit message formats
- Integration with popular Git GUIs
- Commit message templates and presets
- Team/organization shared configurations
- Webhook support for CI/CD integration
- VS Code extension
- Git hooks integration
- Support for more AI models (Gemini, local models)
- Commit message quality scoring
- Integration with issue tracking systems
- π Documentation
- π Bug Reports
- π‘ Feature Requests
- π¬ Discussions
Made with β€οΈ by Subhayu Kumar Bala