ai-commit is a small CLI tool that writes better git commit messages for you.
It reads your staged git diff, sends a cleaned summary of those changes to an LLM, and suggests 3 concise commit messages in Conventional Commit format.
Instead of writing commits like:
fix stuffupdatechanges
You get suggestions like:
feat: add OAuth login flowfix: handle missing session tokendocs: update API auth examples
- Saves time when you do not want to think about commit wording
- Produces cleaner, more consistent commit history
- Encourages Conventional Commit style automatically
- Lets you review and choose before anything is committed
ai-commit follows this flow:
- Reads your staged git changes
- Cleans and truncates the diff
- Sends that context to OpenAI
- Generates 3 commit message suggestions
- Lets you choose one, regenerate, or quit
- Runs
git commit -m "..."for you
Clone or open this project, then install it locally:
pip install -e .After that, the ai-commit command will be available in your shell.
- Python 3.10+
- Git installed and available on your PATH
- An OpenAI API key
ai-commit needs an OpenAI API key to generate commit messages.
You have 2 simple options:
macOS / Linux:
export OPENAI_API_KEY="your_api_key"Windows PowerShell:
$env:OPENAI_API_KEY="your_api_key"You can also use:
AI_COMMIT_OPENAI_API_KEYThat is useful if you want a key that is only used for this tool.
If you do not set a key in advance, ai-commit will prompt you for it when you run the command.
Your input is hidden while typing for safety.
Stage your changes first:
git add .Then run:
ai-commitExample flow:
⚡ Analyzing staged changes...
✔ Found staged changes in 3 file(s)
⚡ Generating commit messages...
Suggested commit messages:
1. feat: add OAuth login handler
2. fix: handle missing auth token
3. refactor: simplify session validation
Select option (1-3), r to regenerate, or q to quit:
Generate commit suggestions and create a normal commit.
Generate suggestions, but do not run git commit.
Useful when you just want message ideas.
Generate a new message and amend the latest commit:
git commit --amend -m "your message"Adds emoji-style commit prefixes when appropriate.
Examples:
✨ feat: add login page🐛 fix: handle missing token♻️ refactor: simplify auth flow📝 docs: update setup guide
The generated messages are designed to be:
- Conventional Commits
- imperative in tone
- one line only
- under 72 characters
- without trailing punctuation
Examples:
feat: add GitHub login supportfix: prevent crash on empty configrefactor: simplify commit prompt builderdocs: add installation instructions
ai-commit includes a few safety protections:
- It only works on staged changes
- It strips noisy diff metadata before sending anything
- It truncates large diffs to control prompt size and cost
- It warns when it detects potentially sensitive content
- It blocks suspicious diffs in non-interactive environments
- It redacts secrets from API error messages where possible
If your staged diff appears to include secrets or sensitive files such as:
.env- private keys
- API keys
- tokens
- credentials
ai-commit will warn you before uploading that diff to OpenAI.
In non-interactive environments, it refuses to continue by default.
If you really want to override that behavior, you can set:
AI_COMMIT_ALLOW_SENSITIVE=1Use that carefully.
By default, ai-commit uses:
gpt-4.1-miniYou can override the model with:
AI_COMMIT_MODELExample:
export AI_COMMIT_MODEL="gpt-4.1"git add .
ai-commitgit add .
ai-commit --drygit add .
ai-commit --amendgit add .
ai-commit --emojiYou need to stage files first:
git add <files>Install Git and make sure it is available from your terminal.
Install project dependencies again:
pip install -e .Set OPENAI_API_KEY or AI_COMMIT_OPENAI_API_KEY, or just run the command and enter the key when prompted.
ai_commit.py
pyproject.toml
tests/
This project includes unit and integration tests.
Run them with:
python -m unittest discover -s tests -vai-commit is intentionally minimal:
- one small Python entrypoint
- easy local install
- no heavy setup
- practical defaults
It is designed for developers who want a fast, clean command they can use every day.