ai-commit is an AI-first commit assistant for Git and Jujutsu (jj).
It reads your working tree, plans cleaner atomic commits, and generates commit
messages in a Conventional Commits style.
Chinese quick guide is available in the 中文简版 section below.
ai-commit is useful when you want to:
- split a messy set of changes into cleaner commits
- stop writing commit messages by hand
- enforce repository-specific scopes, hooks, and diff limits
- use the same workflow across
gitandjj
For most users, npx is enough:
npx @effect-x/ai-commit --helpYou can also install it globally:
npm install -g @effect-x/ai-commit
ai-commit --helpPrerequisites:
- Node.js 24+
gitorjj- an OpenAI-compatible API key
A typical ai-commit commit run looks like this:
- Read the current repository changes.
- Resolve project rules such as scopes, hooks, and diff limits.
- Ask the model to plan commit groups.
- Generate a commit message for each group.
- Run configured hooks against the generated message.
- Retry or re-plan when necessary.
- Create one or more commits.
For git, the default behavior includes unstaged and untracked files in the
plan. If you only want already staged changes, use --no-stage.
Write your user-level configuration first:
ai-commit config set api_key sk-xxx
ai-commit config set model gpt-5-nano
ai-commit config set base_url https://api.openai.com/v1Verify the resolved provider config:
ai-commit config showFrom your repository root:
ai-commit initRunning init with no action flags performs the full setup flow:
- auto-detect
gitvsjj - initialize a repository if the current directory is not one yet
- generate or merge
.gitignore - generate project
scopesfrom directories and commit history - write
.ai-commit/config.json - enable the built-in
conventionalhook by default
If the current directory is not a repository, the default initialization target
is git. If you want jj explicitly:
ai-commit init --vcs jjai-commit commit --dry-runIf the plan looks correct, create the commits:
ai-commit commitIf you want to constrain the planner, provide an intent:
ai-commit commit --intent "split auth refactor from API cleanup"For normal day-to-day usage, the most reliable flow is:
- Configure your API credentials once with
ai-commit config set .... - Run
ai-commit initonce per repository. - Review the generated
.ai-commit/config.json. - Use
ai-commit commit --dry-runbefore real commits. - Run
ai-commit commitwhen the grouping looks right. - Use
ai-commit commit --amendwhen you need to rewrite the latest commit message.
This produces better results than running the tool with no repository-level configuration.
ai-commit uses three config layers:
- User config:
${XDG_CONFIG_HOME:-~/.config}/ai-commit/config.json - Project config:
<repo>/.ai-commit/config.json - Local override config:
<repo>/.ai-commit/config.local.json
Use them like this:
- user config: API key, model, base URL
- project config: shared repository rules
- local override config: machine-specific or temporary overrides
These keys belong in user scope:
api_keybase_urlmodel
Recommended commands:
ai-commit config set api_key sk-xxx
ai-commit config set base_url https://api.openai.com/v1
ai-commit config set model gpt-5-nanoExample user config:
{
"api_key": "sk-xxx",
"base_url": "https://api.openai.com/v1",
"model": "gpt-5-nano"
}If you do not want to store secrets in the config file, environment variables also work:
export OPENAI_API_KEY=sk-xxx
export OPENAI_API_BASE_URL=https://api.openai.com/v1
export OPENAI_MODEL=gpt-5-nanoProject config lives in .ai-commit/config.json and controls repository-level
behavior.
Common fields:
scopes: allowed commit scopeshook: commit message validation hooksmax_diff_lines: max diff lines sent to the model, where0means unlimitedno_commit_co_author: remove the default AI attribution trailerno_model_co_author: advanced co-author related toggle
Typical example:
{
"scopes": [
{
"name": "api",
"description": "Backend API handlers"
},
{
"name": "web",
"description": "Frontend application"
}
],
"hook": ["conventional"],
"max_diff_lines": 400
}Common follow-up commands after initialization:
ai-commit config get hook
ai-commit config set --scope project hook conventional
ai-commit config set --scope project max_diff_lines 400
ai-commit config set --scope local no_commit_co_author truescopes are usually better managed by ai-commit init --scope or by editing
.ai-commit/config.json directly, because the value is an array of objects,
not a simple string list.
Local overrides live in .ai-commit/config.local.json and take precedence over
project config.
Use it when you want to:
- disable or swap a hook only on your machine
- avoid committing personal overrides into the repository
- override the shared
max_diff_lineslocally
Examples:
ai-commit init --local --hook emptyai-commit config set --scope local hook emptyinit --local cannot run by itself. It must be combined with at least one of:
--scope, --gitignore, or --hook.
ai-commit initUse this when onboarding a repository.
ai-commit init --scopeai-commit init --gitignoreai-commit init --hook conventionalai-commit init --forceai-commit init --scope --max-commits 300This controls how much commit history is analyzed when generating scopes.
ai-commit commit --dry-runThis prints the grouped commits without creating them.
ai-commit commitai-commit commit --intent "only commit the API error handling changes"This becomes the planner's primary constraint and is useful when you want a narrower or more explicit grouping.
ai-commit commit --no-stageThis is supported for git only. If nothing is staged, the command fails.
ai-commit commit --amendai-commit commit --max-diff-lines 500ai-commit commit --no-attributionai-commit commit \
--co-author "Alice <alice@example.com>" \
--trailer "Reviewed-by: Bob <bob@example.com>"Built-in hook values currently include:
conventional: validate Conventional Commits formattingempty: do nothing
For a custom shell hook, use config set:
ai-commit config set --scope project hook ./scripts/pre-commit.shThis installs the script into .ai-commit/hooks/pre-commit and writes the hook
value into project config.
For api_key, base_url, and model, resolution is effectively:
- CLI flags:
--api-key,--base-url,--model - local Git config:
ai-commit.base-url,ai-commit.model - user config file:
~/.config/ai-commit/config.json - environment variables:
OPENAI_API_KEY,OPENAI_API_BASE_URL,OPENAI_MODEL - defaults:
https://api.openai.com/v1andgpt-5-nano
If you want repository-local model overrides in a Git repository:
git config --local ai-commit.model gpt-5-nano
git config --local ai-commit.base-url https://api.openai.com/v1Project-related settings are effectively resolved as:
.ai-commit/config.local.json.ai-commit/config.json- user-level fallback for a small subset of fields
In practice, local override config wins over shared project config.
ai-commit commitalways needs a usable API key.ai-commit initalso needs an API key when running the full setup flow,--scope, or--gitignore.--no-stageis supported forgitonly, notjj..ai-commit/config.local.jsonis meant for local overrides and usually should not be committed.
ai-commit version
ai-commit config show
ai-commit config get hook
ai-commit init
ai-commit init --scope
ai-commit init --gitignore
ai-commit commit --dry-run
ai-commit commit --intent "split auth fix"
ai-commit commit --amendai-commit 是一个给 git / jj 用的 AI 提交工具,会读取当前改动、自动规划更合理的原子提交,并生成 Conventional Commits 风格的提交信息。
推荐流程:
- 先配置全局 API。
- 每个项目先执行一次
ai-commit init。 - 日常先跑
ai-commit commit --dry-run。 - 确认结果后再跑
ai-commit commit。
npx @effect-x/ai-commit --helpai-commit config set api_key sk-xxx
ai-commit config set model gpt-5-nano
ai-commit config set base_url https://api.openai.com/v1
ai-commit config showai-commit init默认会:
- 自动识别
git/jj - 如果当前目录不是仓库则先初始化仓库
- 生成或补全
.gitignore - 生成
scopes - 写入
.ai-commit/config.json - 默认启用
conventionalhook
ai-commit commit --dry-run
ai-commit commit
ai-commit commit --intent "split auth refactor from API cleanup"
ai-commit commit --amend- 用户配置:
${XDG_CONFIG_HOME:-~/.config}/ai-commit/config.json - 项目配置:
<repo>/.ai-commit/config.json - 本地覆盖:
<repo>/.ai-commit/config.local.json
优先级通常是:本地覆盖 > 项目配置 > 用户配置回退。
If you are working on this repository itself rather than using the published CLI:
bun install
bun run checkCredit goes to the original author of the Go implementation at
GitAgentHQ/git-agent-cli.
This project is an independent TypeScript / Effect port of that work. It is
not affiliated with, maintained by, or endorsed by GitAgentHQ.
