AI-Commit
AI-Commit is an AI-powered tool that automatically generates Conventional Commits based on your staged changes. It leverages OpenAI to produce concise, readable commit messages and now includes an experimental semantic release feature for automated versioning and releases. Inspired by insulineru/ai-commit.
Table of Contents
Key Features
-
AI-Powered Commit Messages
Generates helpful commit messages by analyzing your staged diff and prompting OpenAI.
-
Conventional Commits Compliance
Ensures messages follow Conventional Commits for a clean, interpretable commit history.
-
Interactive or Non-Interactive
Choose between a friendly TUI for confirming commits or a --force mode to skip prompts.
-
Customizable Commit Types
Specify a commit type (e.g., feat, fix, docs) or let the tool infer it automatically.
-
Custom Templates
Dynamically insert the AI-generated commit into custom templates with placeholders (e.g., branch name).
-
Semantic Release (Experimental)
Automatically suggests a new semantic version tag (MAJOR.MINOR.PATCH) based on the commit content, then optionally creates and pushes a new git tag, and invokes GoReleaser to publish release artifacts.
Prerequisites
- Git: AI-Commit operates on your local Git repository and requires Git installed.
- Go: Needed to build AI-Commit from source.
- OpenAI API Key: Sign up at https://openai.com/ to get your API key.
Installation
-
Clone the Repository
git clone https://github.com/renatogalera/ai-commit.git
cd ai-commit
-
Build the Application
go build -o ai-commit ./cmd/ai-commit
-
(Optional) Install Globally
sudo mv ai-commit /usr/local/bin/
Now ai-commit is accessible from anywhere in your terminal.
Configuration
OpenAI API Key
Set your API key either via a command-line flag or an environment variable:
Custom Templates
Use the --template flag to supply a commit message template with placeholders:
For example:
ai-commit --template "Branch: {GIT_BRANCH}\nCommit: {COMMIT_MESSAGE}"
Semantic Release
To automatically suggest a next version and optionally create & push a git tag plus run GoReleaser:
-
Install GoReleaser if you haven’t already:
brew install goreleaser/tap/goreleaser
or see official installation docs.
-
Use --semantic-release when running AI-Commit. This will:
- Parse your current version (from the latest
vX.Y.Z git tag).
- Consult OpenAI to determine if you need a MAJOR, MINOR, or PATCH bump.
- Automatically tag your repository, push the new tag, and run
goreleaser release --rm-dist.
Usage
Run ai-commit inside a Git repository with staged changes.
Command-Line Flags
--apiKey
Your OpenAI API key. If not set, the tool looks for OPENAI_API_KEY.
--commit-type
Specify a commit type (feat, fix, docs, etc.). Otherwise the tool may infer it.
--template
Custom template for your commit message.
--force
Automatically commit without interactive confirmation.
--language
Language used in AI generation (default english).
--semantic-release
Triggers AI-assisted version bumping and release tasks (see Semantic Release).
How it Works
-
Check Git
Ensures you’re in a valid Git repository and there are staged changes.
-
Retrieve Diff & Filter Lock Files
Pulls the staged diff and removes lock files (go.mod, go.sum, etc.) from analysis.
-
Generate AI Prompt
Assembles a request including your diff, commit type, and desired language.
-
OpenAI Request
Calls OpenAI’s chat completion endpoint with the prompt, retrieving a commit message.
-
Sanitize & Format
Applies Conventional Commits formatting, adds an emoji prefix if possible, and substitutes into any template you provide.
-
Interactive UI
Presents a TUI to review and optionally regenerate the commit message unless --force is used.
-
Commit & Semantic Release
Commits your changes. If --semantic-release is enabled, AI-Commit:
- Reads the current version tag.
- Generates a recommended next version (MAJOR, MINOR, or PATCH).
- Creates and pushes a new Git tag.
- Invokes GoReleaser to build and publish your release artifacts.
Examples
1. Standard Interactive Commit
ai-commit --apiKey YOUR_API_KEY
- Stage changes with
git add .
- Let AI-Commit generate a message and show you an interactive UI:
- Confirm (
y / enter)
- Regenerate (
r)
- Select Type (
t)
- Quit (
q / ctrl+c)
2. Force Commit (Non-Interactive)
ai-commit --apiKey YOUR_API_KEY --force
Bypasses the interactive UI and commits immediately.
3. Semantic Release
ai-commit --apiKey YOUR_API_KEY --semantic-release
- Generates the commit message (interactive or forced).
- After committing, it reads your latest version tag, queries OpenAI for a suggested version increment, tags your repository, and runs GoReleaser.
Tip: Use --force --semantic-release to commit and release automatically in one go.
4. Custom Template
ai-commit --template "Branch: {GIT_BRANCH}\nCommit: {COMMIT_MESSAGE}"
Inserts the current branch name and AI-generated message into the final commit log.
License
This project is released under the MIT License. Please see the LICENSE file for details.