code-agent-auto-commit
v1.5.0
Published
CAC provides configurable AI auto-commit(using your git account) for OpenCode, Claude Code, Codex, and other AI code agents
Maintainers
Readme
code-agent-auto-commit
code-agent-auto-commit (cac) provides configurable code-agent-end auto-commit(using your git account) for:
- OpenCode
- Claude Code
- OpenAI Codex CLI
Features
- Auto-commit when a chat/agent turn ends
- Commit strategies:
single: all changed files in one commitper-file: one file per commit
- AI-generated commit messages with multi-provider model configuration
- OpenAI-compatible mode (
openai-completions) - Anthropic-compatible mode (
anthropic-messages)
- OpenAI-compatible mode (
- Optional auto-push to GitHub, GitLab, or generic remotes
- Tool installers for OpenCode, Codex, and Claude Code
Installation
pnpm add -g code-agent-auto-commit@latestTo update to the latest version:
pnpm update -g code-agent-auto-commit
OR:
pnpm add -g code-agent-auto-commit@latestThen use the short command:
cac --helpQuick Start
# 1. Initialize config
cac init
# 2. Configure AI API key (pick one method):
# Global (recommended — works across all projects):
cac ai set-key <provider|ENV_VAR> <api-key>
# Or project-level (edit .cac/.env):
echo 'MINIMAX_API_KEY=sk-xxx' >> .cac/.env
# 3. Install hooks
cac install --tool all --scope project
# 4. Verify
cac status --scope project
cac ai "hello"
# 5. Agentic coding
opencode / claude / codexImportant: After
cac init, you must configure an AI provider API key. Without a valid key, AI commit messages will not work andcacfalls back to genericchore(auto): ...prefixed messages.Model tip: Choose a fast, lightweight model (e.g.
gpt-4.1-mini,MiniMax-M2.5-highspeed). Commit messages are short — speed matters more than intelligence here.
Commands
cac init [--worktree <path>] [--config <path>]
cac install [--tool all|opencode|codex|claude] [--scope project|global] [--worktree <path>] [--config <path>]
cac uninstall [--tool all|opencode|codex|claude] [--scope project|global] [--worktree <path>]
cac status [--scope project|global] [--worktree <path>] [--config <path>]
cac run [--tool opencode|codex|claude|manual] [--worktree <path>] [--config <path>] [--event-json <json>] [--event-stdin]
cac set-worktree <path> [--config <path>]
cac ai <message> [--config <path>]
cac ai set-key <provider|ENV_VAR> <api-key> [--config <path>]
cac ai get-key <provider|ENV_VAR> [--config <path>]Command Details
cac init: creates.cac/.code-agent-auto-commit.jsonunder the worktree (unless--configis provided), and also writes.cac/.env.exampleand.cac/.envwith default provider API key env vars.cac install: installs adapters/hooks for selected tools (opencode,codex,claude) inprojectorglobalscope. If no config exists at the resolved path, it creates one first.cac uninstall: removes previously installed adapters/hooks for selected tools and scope.cac status: prints resolved config path, worktree, commit mode, AI/push toggles, and install status of each adapter.cac run: executes one auto-commit pass (manual or hook-triggered). It reads config, filters changed files, stages/commits by configured mode, and optionally pushes. Hook-triggered runs also write logs to.cac/run-<timestamp>.log.cac set-worktree: updates only theworktreefield in the resolved config file.cac ai: tests AI request (cac ai "hi") or manages global keys (set-key/get-key).
Config File
Default project config file:
.cac/.code-agent-auto-commit.json
Generated env templates:
.cac/.env.example.cac/.env
You can copy from:
.code-agent-auto-commit.example.json
Full schema and options:
doc/CONFIG.mddoc/zh-CN.md
AI Key Resolution
cac resolves API keys automatically in this order (first match wins):
process.env— environment variable already set in the current shell~/.config/code-agent-auto-commit/keys.env— global keys file (written bycac ai set-key).cac/.env— project-level env file (created bycac init)ai.providers.<name>.apiKey— key stored directly in config (not recommended)
This means hooks work out of the box — no need to manually source .cac/.env before running.
If AI request fails (missing key, invalid provider/model, or non-2xx response), cac falls back to commit.fallbackPrefix-style messages.
AI Models (Multi-Provider)
Model format follows provider/model (OpenClaw-style). Example:
{
"ai": {
"enabled": true,
"model": "openai/gpt-4.1-mini",
"defaultProvider": "openai",
"providers": {
"openai": {
"api": "openai-completions",
"baseUrl": "https://api.openai.com/v1",
"apiKeyEnv": "OPENAI_API_KEY"
},
"anthropic": {
"api": "anthropic-messages",
"baseUrl": "https://api.anthropic.com/v1",
"apiKeyEnv": "ANTHROPIC_API_KEY"
},
"moonshot": {
"api": "openai-completions",
"baseUrl": "https://api.moonshot.ai/v1",
"apiKeyEnv": "MOONSHOT_API_KEY"
}
}
}
}Integration Notes
- OpenCode: installs plugin under
.opencode/plugins/or~/.config/opencode/plugins/ - Codex CLI: writes managed
notifyblock in.codex/config.tomlor~/.codex/config.toml - Claude Code: installs
Stophook in.claude/settings.jsonor~/.claude/settings.json
If Codex config already has a custom notify = ..., installer stops and asks for manual merge.
Development
pnpm install
pnpm run typecheck
pnpm run build
pnpm testOpen Source
- Contribution guide:
CONTRIBUTING.md - Security policy:
SECURITY.md - Code of conduct:
CODE_OF_CONDUCT.md
License
MIT
