AI-powered conventional commit message generator from staged git changes.
cwai is a command-line tool that writes git commit messages for you. It looks at your staged changes (git add), sends them to an AI model, and generates a clear, well-formatted Conventional Commits message. You can accept it, edit it, or ask for a new one. All you need is an API key from any OpenAI-compatible provider.
- Generates Conventional Commits messages from
git diff - Works with any OpenAI-compatible API (OpenAI, Anthropic, local models)
- Two modes: interactive standalone or silent
prepare-commit-msghook - Structured output support for consistent formatting
- Smart diff truncation to fit model token limits
-
Git installed and available in your terminal
-
API key from one of these providers (or any OpenAI-compatible API):
Provider Get your key OpenAI https://platform.openai.com/api-keys OpenRouter https://openrouter.ai/keys DeepSeek https://platform.deepseek.com/api_keys You can also use local models via Ollama or LM Studio — no API key needed, just point
CWAI_API_URLto your local server.
curl -fsSL https://raw.githubusercontent.com/nikmd1306/cwai/main/install.sh | bashTo install to a custom directory:
curl -fsSL https://raw.githubusercontent.com/nikmd1306/cwai/main/install.sh | bash -s -- -b ~/.local/binNote: The default install path
/usr/local/binrequiressudo. If you prefer to install withoutsudo, use~/.local/binand make sure it's in yourPATH:echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc source ~/.bashrcFor zsh, replace
~/.bashrcwith~/.zshrc.
Requires Go 1.23+.
go install github.com/nikmd1306/cwai@latestNote: Ensure
$(go env GOPATH)/binis in yourPATH:export PATH="$PATH:$(go env GOPATH)/bin"
Download the Windows zip from Releases, extract cwai.exe, and add its folder to your PATH. Or, if you have Go installed:
go install github.com/nikmd1306/cwai@latestDownload pre-built binaries from Releases.
git clone https://github.com/nikmd1306/cwai.git
cd cwai
make install-
Set up your API key (one-time):
cwai setup
The wizard will ask for your API key, provider URL, model, and language. See Prerequisites for where to get an API key.
-
Stage your changes:
git add . -
Generate a commit message:
cwai
cwai will show the staged files, generate a message, and let you accept, edit, regenerate, or cancel.
Tip: Use
cwai -yto auto-accept the generated message (useful in CI/scripts).
$ cwai
Staged files (3):
internal/ai/client.go
internal/prompt/prompt.go
cmd/root.go
Generated commit message:
feat(ai): add structured output support for commit generation
[y]es / [e]dit / [r]egenerate / [n]o:cwai hook set # Install prepare-commit-msg hook
cwai hook unset # Remove hookConfig file: ~/.cwai (INI format). Use cwai config set KEY VALUE or cwai setup.
| Key | Description | Default |
|---|---|---|
CWAI_API_KEY |
API key from your provider (required) | not set |
CWAI_API_URL |
Base URL of the AI API | https://api.openai.com/v1 |
CWAI_MODEL |
Model to use for generation | gpt-5-mini |
CWAI_LANGUAGE |
Commit message language (ISO 639-1: en, de, fr, es, ...) |
en |
| Key | Description | Default |
|---|---|---|
CWAI_MAX_TOKENS_INPUT |
Max input tokens for diff (higher = more context, more cost) | 4096 |
CWAI_MAX_TOKENS_OUTPUT |
Max output tokens for response | 500 |
CWAI_TEMPERATURE |
Sampling temperature (0.0 = deterministic, 1.0 = creative) |
not set |
CWAI_REASONING_EFFORT |
Reasoning effort for reasoning models (low, medium, high) |
not set |
CWAI_VERBOSITY |
Output verbosity level | not set |
CWAI_STRUCTURED_OUTPUT |
Enable structured JSON output (true/false) |
not set |
| Error | Cause | Solution |
|---|---|---|
CWAI_API_KEY is not set |
No API key configured | Run cwai setup or cwai config set CWAI_API_KEY <your-key> |
API error (HTTP 401) |
Invalid or expired API key | Regenerate your key at your provider's dashboard |
API error (HTTP 429) |
Rate limit exceeded | Wait a moment and try again, or upgrade your API plan |
no staged changes |
Nothing added to git staging area | Run git add <files> before running cwai |
not a git repository |
cwai was run outside a git repo | Navigate to a git repository first (cd your-project) |
cwai: command not found |
Binary not in PATH | See Installation for PATH setup instructions |
See CONTRIBUTING.md for development setup and guidelines.
