AI-powered Git commit message generator using Claude
Project description
Smart Commit Generator
A lightweight CLI tool that analyzes your Git changes and uses Claude AI to generate clear, meaningful, and standardized commit messages following the Conventional Commits specification.
No more vague commits like "fix stuff" or "update files" — get professional commit messages automatically.
Example Output
────────────────────────────────────────────────────────────
fix(auth): replace hardcoded credentials with environment variables
Hardcoded admin credentials posed a security risk and would fail
in production. Auth now reads from ADMIN_USER and ADMIN_PASS
environment variables.
────────────────────────────────────────────────────────────
Commit Types Generated
| Type | When Used |
|---|---|
feat |
A new feature |
fix |
A bug fix |
refactor |
Code change with no feature or bug impact |
docs |
Documentation changes only |
style |
Formatting, spacing (no logic change) |
test |
Adding or fixing tests |
chore |
Build process, dependencies, tooling |
perf |
Performance improvement |
ci |
CI/CD configuration changes |
revert |
Reverting a previous commit |
Requirements
- Python 3.10 or higher
- Git installed
- An Anthropic API key → console.anthropic.com
Installation
Step 1 — Clone or download the project
# Clone
git clone https://github.com/your-username/smart-commit-generator.git
cd smart-commit-generator
# Or just download and navigate into the folder
cd path/to/smart-commit-generator
Step 2 — Install dependencies and register the CLI
pip install -e .
This installs the smart-commit command globally so you can run it from any folder.
Step 3 — Set your Anthropic API key
Get your key from console.anthropic.com → API Keys → Create Key.
Setting the API Key
Windows
Option A — Temporary (current terminal session only)
CMD:
set ANTHROPIC_API_KEY=sk-ant-your-key-here
PowerShell:
$env:ANTHROPIC_API_KEY = "sk-ant-your-key-here"
Option B — Permanent (recommended)
- Press
Win + R, typesysdm.cpl, press Enter - Go to Advanced tab → click Environment Variables
- Under User variables, click New
- Set:
- Variable name:
ANTHROPIC_API_KEY - Variable value:
sk-ant-your-key-here
- Variable name:
- Click OK on all dialogs
- Restart your terminal — it now works in CMD, PowerShell, VS Code, Git Bash, etc.
macOS / Linux
Option A — Temporary (current terminal session only)
export ANTHROPIC_API_KEY="sk-ant-your-key-here"
Option B — Permanent (recommended)
Add the export line to your shell profile file:
For zsh (default on macOS):
echo 'export ANTHROPIC_API_KEY="sk-ant-your-key-here"' >> ~/.zshrc
source ~/.zshrc
For bash:
echo 'export ANTHROPIC_API_KEY="sk-ant-your-key-here"' >> ~/.bashrc
source ~/.bashrc
Verify it's set:
echo $ANTHROPIC_API_KEY
Usage
Navigate to any Git repository and run:
Basic — Analyze staged changes
# 1. Stage your files
git add .
# 2. Generate commit message
smart-commit
Auto-commit — Generate and commit in one step
git add .
smart-commit --apply
Analyze all changes (no need to stage first)
smart-commit --all
Copy message to clipboard
smart-commit --copy
Use a different Claude model
# Faster and cheaper
smart-commit --model claude-sonnet-4-6
# Fastest and most cost-effective
smart-commit --model claude-haiku-4-5
# Most powerful (default)
smart-commit --model claude-opus-4-6
Skip recent commit history context
smart-commit --no-context
All Options
smart-commit [options]
Options:
--all, -a Analyze all changes (staged + unstaged)
--apply Commit immediately with the generated message
--copy, -c Copy the generated message to clipboard
--model, -m Claude model to use:
claude-opus-4-6 (default, most powerful)
claude-sonnet-4-6 (faster, cheaper)
claude-haiku-4-5 (fastest, most cost-effective)
--no-context Skip reading recent commits for style matching
-h, --help Show help message
Step-by-Step Workflow
Scenario 1 — You made changes and want to commit
# Step 1: Check what changed
git status
# Step 2: Stage everything (or specific files)
git add .
# git add src/auth.py ← stage a specific file
# Step 3: Preview the generated commit message
smart-commit
# Step 4: If happy with it, commit
smart-commit --apply
Scenario 2 — Quick commit without previewing
git add .
smart-commit --apply
Scenario 3 — Generate message without staging first
smart-commit --all
# Preview only — does NOT commit automatically
Scenario 4 — Generate, copy, then paste manually
git add .
smart-commit --copy
git commit # opens editor with your clipboard content
How It Works
- Runs
git diff --cached(orgit diffwith--all) to get your changes - Runs
git statusto see which files are affected - Reads your last 5 commit messages to match your repo's style
- Sends everything to Claude AI with a structured prompt
- Claude returns a conventional commit message
- The message is displayed — and optionally applied or copied
Models Comparison
| Model | Speed | Cost | Best For |
|---|---|---|---|
claude-opus-4-6 |
Moderate | Higher | Complex changes, best quality |
claude-sonnet-4-6 |
Fast | Medium | Most everyday commits |
claude-haiku-4-5 |
Fastest | Lowest | Simple changes, high volume |
Troubleshooting
smart-commit: command not found
Re-install the package:
cd path/to/smart-commit-generator
pip install -e .
On macOS, if pip installs to a path not on your $PATH:
pip install -e . --user
# Then add to PATH:
export PATH="$HOME/.local/bin:$PATH"
ANTHROPIC_API_KEY environment variable not set
The key isn't set in your current terminal session.
Windows CMD:
set ANTHROPIC_API_KEY=sk-ant-your-key-here
Windows PowerShell:
$env:ANTHROPIC_API_KEY = "sk-ant-your-key-here"
macOS/Linux:
export ANTHROPIC_API_KEY="sk-ant-your-key-here"
For a permanent fix, see the Setting the API Key section above.
No staged changes
You need to stage files before running smart-commit:
git add .
smart-commit
Or analyze unstaged changes directly:
smart-commit --all
Not inside a git repository
Make sure you're inside a git project folder:
cd path/to/your/project
git status # should show repo status, not an error
smart-commit
Clipboard not working on macOS/Linux
- macOS: Should work out of the box (uses
pbcopy) - Linux: Install
xclip:sudo apt install xclip # Ubuntu/Debian sudo dnf install xclip # Fedora
Project Structure
smart-commit-generator/
├── smart_commit.py ← Main CLI script
├── setup.py ← Package config & entry point
├── requirements.txt ← Dependencies (anthropic)
└── README.md ← This file
License
MIT — free to use, modify, and distribute.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smart_commit_generator-1.0.0.tar.gz.
File metadata
- Download URL: smart_commit_generator-1.0.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01ff839f31b2ed145ed26f0ad43fdadaf3a697df5935f9ed9fc1fa9dd7bc5aaf
|
|
| MD5 |
3de4178057a90fca3c8d1f560edee032
|
|
| BLAKE2b-256 |
57aaed11d1194d13446dd129ede126dc934a4ed8aa600d0c1be8b479719c210c
|
Provenance
The following attestation bundles were made for smart_commit_generator-1.0.0.tar.gz:
Publisher:
python-publish.yml on Vijayaragavan46/smart-commit-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smart_commit_generator-1.0.0.tar.gz -
Subject digest:
01ff839f31b2ed145ed26f0ad43fdadaf3a697df5935f9ed9fc1fa9dd7bc5aaf - Sigstore transparency entry: 1270559332
- Sigstore integration time:
-
Permalink:
Vijayaragavan46/smart-commit-generator@76a9263cac3bd831fc61b952186abebe4e3861ef -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Vijayaragavan46
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@76a9263cac3bd831fc61b952186abebe4e3861ef -
Trigger Event:
release
-
Statement type:
File details
Details for the file smart_commit_generator-1.0.0-py3-none-any.whl.
File metadata
- Download URL: smart_commit_generator-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa0bb31da70bf51b58066734721320e73c7648eb4931e2089aaa2d3f0d95b621
|
|
| MD5 |
cb09249a5064ddfb2f2fe8d08687e851
|
|
| BLAKE2b-256 |
7a32f10c9348caf98421e7d1fe8f5881740c3450888319d23b2c9485fa3e6346
|
Provenance
The following attestation bundles were made for smart_commit_generator-1.0.0-py3-none-any.whl:
Publisher:
python-publish.yml on Vijayaragavan46/smart-commit-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smart_commit_generator-1.0.0-py3-none-any.whl -
Subject digest:
aa0bb31da70bf51b58066734721320e73c7648eb4931e2089aaa2d3f0d95b621 - Sigstore transparency entry: 1270559353
- Sigstore integration time:
-
Permalink:
Vijayaragavan46/smart-commit-generator@76a9263cac3bd831fc61b952186abebe4e3861ef -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Vijayaragavan46
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@76a9263cac3bd831fc61b952186abebe4e3861ef -
Trigger Event:
release
-
Statement type: