Services Portfolio Tools Journal About
Back to Tools
📝
TypeScriptNode.jsCLI CLI Tool

gitcommitgen

AI-powered conventional commit message generator. Analyzes staged changes and generates clean commit messages.

Install
npm install -g @fanioz/gitcommitgen

Analyze your staged git changes and generate clean, meaningful conventional commit messages — powered by AI.

Setup

Set your LLM provider API key:

# OpenAI
export OPENAI_API_KEY="sk-..."

# Anthropic
export ANTHROPIC_API_KEY="sk-ant-..."

Optionally, create a config file at ~/.gitcommitgen.json for defaults:

{
  "provider": "openai",
  "model": "gpt-4o-mini",
  "commit": true,
  "edit": true,
  "dryRun": false
}

Without a config file or flags, defaults to --edit mode.

Usage

# Generate and print commit message
gitcommitgen

# Generate and auto-commit
gitcommitgen --commit

# Use a specific provider and model
gitcommitgen --provider anthropic --model claude-haiku-4-5

# Preview: show diff summary and proposed message
gitcommitgen --dry-run

# Edit the generated message before committing
gitcommitgen --commit --edit

You can also pipe directly to git:

git commit -m "$(gitcommitgen)"

How It Works

  1. Reads git diff --staged to see your changes
  2. Sends the diff to an LLM with a prompt tuned for conventional commits
  3. Returns a clean commit message (type, optional scope, description)

Supported Providers

ProviderDefault ModelEnv Var
OpenAIgpt-4o-miniOPENAI_API_KEY
Anthropicclaude-haiku-4-5ANTHROPIC_API_KEY

Features

  • Zero-config — works out of the box with just an API key
  • Supports OpenAI and Anthropic as providers
  • Config file support for team defaults (~/.gitcommitgen.json)
  • Dry-run mode to preview before committing
  • Edit mode to tweak the generated message
  • Auto-commit with --commit flag

Usage Examples

The real value of gitcommitgen shows up in the boring middle of a workday, not in a demo. A few patterns that pay off immediately:

The staged-only workflow. Stage exactly the files that belong in one logical change, then let the tool read that slice:

git add src/auth/session.ts src/auth/session.test.ts
gitcommitgen --commit
# → "fix(auth): refresh session token before expiry check"

Because the tool only sees git diff --staged, the message describes the change you actually staged — not the three unrelated files still sitting dirty in your working tree.

The pipe that never blocks. If you already live in the shell, skip the extra process management:

git commit -m "$(gitcommitgen)"

This is useful in scripts or aliases where you want the message generation to be a pure function of the index.

The review-first habit. When a change is subtle, use dry-run so the model cannot commit on your behalf:

gitcommitgen --dry-run

You get the diff summary and the proposed message, decide, and then either copy it or re-run with --commit.

Team defaults. Commit a shared config to your dotfiles and every repo picks up the same provider, model, and mode:

{ "provider": "anthropic", "model": "claude-haiku-4-5", "commit": true }

When to Use gitcommitgen

Use it when the friction is real:

  • You write “fix stuff” and “wip” messages and regret them later.
  • Your team enforces Conventional Commits and you keep guessing the right type.
  • You work on many small commits per day and typing message prose is overhead.
  • You want commit messages to be consistent across a team without a linter lecture.

Skip it when the message carries design intent that only you know. The tool reads a diff; it cannot explain why a decision was made. In those cases, write the body yourself and use the tool only for the subject line.

gitcommitgen vs. Alternatives

ToolApproachRequires API keyAuto-commitBest for
gitcommitgenLLM reads staged diffYesYes (--commit)Fast, low-friction conventional commits
commitizenInteractive prompts, templatesNoNoTeams standardizing message shape
aicommitsLLM reads staged diffYesYesSimilar scope, broader provider config
commitlintLints messages after the factNoNoEnforcing a rule, not writing the message

The practical split: gitcommitgen and aicommits generate; commitizen and commitlint enforce. Many teams run a generator plus commitlint in a commit-msg hook so the generated message is also validated.

FAQ

Does it send my code to the cloud? Yes. The staged diff is sent to the provider you configure (OpenAI or Anthropic). Do not use it on repositories whose diffs you cannot share with that provider.

Which provider should I pick? gpt-4o-mini is cheap and fast and handles conventional commit typing well. claude-haiku-4-5 is a good alternative when you already pay for Anthropic.

Does it work without an API key? No. An API key is required for the chosen provider.

Can I use it in CI? Yes, but be deliberate. Auto-committing in CI can create noisy history; most teams use it locally and keep CI for linting messages with commitlint.

What if the generated message is wrong? Run with --edit (or the default mode) and correct it before committing. The tool never commits in dry-run or plain generate mode.