Skip to content

Repository files navigation

AutoCommit

An ultra lightweight Zig CLI tool (~900KB) that analyzes Git history and generates conventional commit messages using LLM providers.

Demo

Features

  • AI-Powered Commit Messages - Automatically generates conventional commit messages from your git diffs using LLM providers (z.ai, Groq)
  • Customizable System Prompt - Edit the system prompt to customize how commit messages are generated (conventional commits, style, tone, etc.)
  • Multiple LLM Providers - Support for z.ai and Groq with easy provider switching
  • Interactive Workflow - Interactive prompts for staging files, reviewing commit messages, and pushing to remote
  • Full Automation - Optional flags for fully automated add, commit, and push workflow
  • Cross-Platform - Works on macOS and Linux

Installation

Homebrew (macOS/Linux)

brew tap jsmenzies/tap
brew install autocommit

From Source

Requires Zig 0.13.0 or later:

git clone https://github.com/jsmenzies/autocommit.git
cd autocommit
zig build

The binary will be at zig-out/bin/autocommit.

Pre-built Binaries

Download from releases page (coming soon).

Usage

Commands

autocommit                    # Generate commit message interactively
autocommit config             # Open config in default editor
autocommit config show        # Display current configuration
autocommit config path        # Show configuration file path

Options

  • --add - Auto-add all unstaged files before committing
  • --push - Auto-push after committing
  • --accept - Auto-accept generated commit message without prompting
  • --provider <name> - Override provider (zai, groq)
  • --model <name> - Override model
  • --debug - Enable debug output
  • --version - Show version information
  • --help - Show help message

Examples

# Generate commit message interactively (default)
autocommit

# Full automation: add all files, auto-accept commit, and push
autocommit --add --accept --push

# Auto-add all files and commit
autocommit --add

# Full automated workflow: add, commit, and push
autocommit --add --push

# Use specific provider
autocommit --provider groq

# Use specific provider and model
autocommit --provider groq --model llama-3.1-8b-instant

# Full automation with provider override
autocommit --add --accept --push --provider groq

# Note: All flags can be mixed and matched. Remove any you don't need:
#   autocommit --add              # Just add files
#   autocommit --add --push       # Add and push (review commit message)
#   autocommit --accept --push    # Accept and push (files already staged)

# Edit configuration in default editor
autocommit config

# Display current configuration
autocommit config show

# Show configuration file path
autocommit config path

# Show version
autocommit --version

# Show help
autocommit --help

Shell Alias (Optional)

For a fully automated workflow, add this alias to your shell configuration:

# ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish
alias ac='autocommit --add --accept --push'

With this alias, running ac will:

  1. Auto-add all unstaged/untracked files to git
  2. Generate a conventional commit message using AI
  3. Auto-accept the commit message (no prompting)
  4. Push the commit to the remote repository

This provides a quick "commit and push everything" workflow for rapid development.

Note: You can modify the flags to suit your needs:

  • Remove --accept if you want to review/edit the commit message
  • Remove --push if you don't want to push immediately
  • Add --provider <name> to use a specific provider

Configuration

Configuration is stored as TOML at ~/.config/autocommit/config.toml by default on both macOS and Linux.

If the XDG_CONFIG_HOME environment variable is set, the config will be stored at $XDG_CONFIG_HOME/autocommit/config.toml instead.

Generated Configuration

When you run autocommit config, the tool automatically creates a default configuration file with the following structure and inputs the default prompt

default_provider = "zai"

system_prompt = ""

[[providers]]
name = "zai"
api_key = "paste-key-here"
model = "glm-4.7-Flash"
endpoint = "https://api.z.ai/api/paas/v4/chat/completions"

[[providers]]
name = "groq"
api_key = "paste-key-here"
model = "llama-3.1-8b-instant"
endpoint = "https://api.groq.com/openai/v1/chat/completions"

Note: Groq offers a free tier for many models. Sign up at https://groq.com to get an API key.

System Prompt

The default system prompt instructs the LLM to generate conventional commit messages. It supports both single-line and multiline commit messages:

Single-line format (for simple changes):

<type>(<scope>): <subject>

Example:

feat(auth): add password validation to login form

Multiline format (for complex or multiple changes):

<type>(<scope>): <subject>

<body with bullet points>

Example:

feat(api): implement rate limiting middleware

- Add sliding window rate limiting with Redis backend
- Configurable limits per endpoint via env vars
- Returns 429 status with Retry-After header

The prompt instructs the LLM to:

  • Use conventional commit types: feat, fix, docs, style, refactor, test, chore
  • Keep the subject line concise and in present tense, imperative mood
  • Add a body section for complex changes or when there are multiple distinct changes
  • Use bullet points in the body to describe what and why

You can customize the system prompt in your config file to change how commit messages are generated.

Configuration Options

  • default_provider - Which LLM provider to use (zai, groq)
  • system_prompt - Custom prompt for commit message generation (see above for default behavior)
  • providers.{name}.api_key - API key for the provider
  • providers.{name}.model - Model to use
  • providers.{name}.endpoint - API endpoint URL

Build Commands

For development and testing:

zig build              # Development build
zig build test         # Run tests
zig build run          # Build and run
zig build -Doptimize=ReleaseSmall  # Optimized build

Development

Running Tests

zig build test

Cross Compilation

# macOS ARM64
zig build -Dtarget=aarch64-macos -Doptimize=ReleaseSmall

# Linux x86_64 (static)
zig build -Dtarget=x86_64-linux-musl -Doptimize=ReleaseSmall

License

MIT License - see LICENSE file for details

About

Lightweight Zig CLI tool that generates conventional commit messages using LLM providers

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages