A Ruby gem that automatically generates concise and meaningful git commit messages using a local LLM via Ollama, LM Studio, llama.cpp llama-server, or any other OpenAI-compatible API.
Install the gem using:
gem install ai-commit-messageOr add it to your Gemfile:
gem 'ai-commit-message'And then run:
bundle install- Ruby 3.0 or newer
- Git repository
- A local LLM server: Ollama, LM Studio, llama.cpp
llama-server, or any other OpenAI-compatible endpoint
Generate a commit message for your staged changes and commit with it after a confirmation:
ai-commit-message commitThis will:
- Analyze your staged changes (
git diff --cached) - Review your recent commit history for style consistency
- Consider your current branch name
- Generate an appropriate commit message
- Ask for confirmation and create the commit (answering "no" keeps the printed message so you can edit or copy it)
If you just want the suggested message without the confirmation prompt — e.g. to pipe it somewhere or review it yourself — use --message-only:
ai-commit-message commit --message-onlyAsk the model to follow the Conventional Commits format (feat:, fix:, chore:, ...):
ai-commit-message commit --conventionalConfigure the API URL and model interactively:
ai-commit-message configIf your server is reachable, the model prompt becomes a picker populated with the models available on that server.
List the models available on your server:
ai-commit-message modelsOverride configuration settings directly:
ai-commit-message commit --url=http://your-api-endpoint --model=your-model-nameAll options:
| Option | Description | Default |
|---|---|---|
--url |
Base URL of the OpenAI-compatible API | http://localhost:11434 |
--model |
Model name | qwen3:8b |
--length |
Maximum message length in characters | 72 |
--conventional |
Use Conventional Commits format | off |
--message-only |
Print the message without the commit confirmation prompt | off |
The gem:
- Collects your staged changes using
git diff --cached(capped at 12,000 characters so large diffs don't overwhelm a local model's context) - Retrieves your recent commit history for context
- Identifies your current branch name
- Sends a chat request to
{url}/v1/chat/completions— the standard OpenAI-compatible endpoint - Cleans the model output (strips code fences, quotes and reasoning blocks) and prints a single-line commit message (limited to 72 characters by default)
The URL accepts base addresses with or without a trailing /v1 and /, so http://localhost:11434 (Ollama), http://localhost:1234/v1 (LM Studio) and http://localhost:8080 (llama.cpp llama-server) all work as-is.
The gem stores your configuration in ~/.ai-commit-message.conf. You can manually edit this file if needed. Example:
url=http://localhost:11434
model=qwen3:8bThe default configuration uses Ollama with the qwen3:8b model, but you can use any model available through your API endpoint.
- qwen3:8b: Good balance of quality and speed (default). Note that it is a thinking model, so expect a few seconds of reasoning before the message appears
- qwen2.5-coder:7b: Faster, non-thinking coding model
- qwen3.5:4b: Current-generation small model for modest hardware
- gemma4:e4b: Compact general-purpose option
- llama3.1:8b: Solid general-purpose choice
- Fork the repository
- Create your feature branch:
git checkout -b my-new-feature - Install dependencies:
bundle install - Run the tests:
bundle exec rake test - Make your changes and add tests if applicable
- Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
This gem is available as open source under the terms of the MIT License.
