____ _ _ _ _ _
/ ___|___ _ __ ___ _ __ ___ (_) |_ | | | | ___| |_ __ ___ _ __
| | / _ \| '_ ` _ \| '_ ` _ \| | __| | |_| |/ _ \ | '_ \ / _ \ '__|
| |__| (_) | | | | | | | | | | | | |_ | _ | __/ | |_) | __/ |
\____\___/|_| |_| |_|_| |_| |_|_|\__| |_| |_|\___|_| .__/ \___|_|
|_|
ch is a CLI shell tool that uses AI (OpenAI or Anthropic) to analyze git diffs and generate meaningful commit messages, then commits automatically.
| Command | Description |
|---|---|
ch -s |
Staged changes — analyze already-staged files and commit |
ch -c |
Current changes — stage all modified/untracked files, then commit |
ch show -s |
Preview staged — generate and display the commit message only, no commit |
ch show -c |
Preview current — generate and display the commit message only, no commit |
ch |
Default — display the Commit Helper banner and all commands |
ch help |
Help — alias for ch with no arguments |
- Run
git diff --cachedto get the staged diff - If nothing is staged, exit with an error:
No staged changes found. - Send the diff to the AI model
- Display the generated commit message to the user
- Prompt for confirmation:
Commit with this message? [Y/n] - On confirm: run
git commit -m "<generated message>"
- Run
git statusto detect modified, untracked, or deleted files - If no changes exist, exit with an error:
No changes found. - Run
git add .to stage all current changes - Run
git diff --cachedto get the staged diff - Send the diff to the AI model
- Display the generated commit message to the user
- Prompt for confirmation:
Commit with this message? [Y/n] - On confirm: run
git commit -m "<generated message>"
Running ch with no arguments (or ch help) prints the banner and usage, then exits. No git or AI calls are made.
Example output:
____ _ _ _ _ _
/ ___|___ _ __ ___ _ __ ___ (_) |_ | | | | ___| |_ __ ___ _ __
| | / _ \| '_ ` _ \| '_ ` _ \| | __| | |_| |/ _ \ | '_ \ / _ \ '__|
| |__| (_) | | | | | | | | | | | | |_ | _ | __/ | |_) | __/ |
\____\___/|_| |_| |_|_| |_| |_|_|\__| |_| |_|\___|_| .__/ \___|_|
|_|
AI-powered git commit message generator v1.0.0
Usage:
ch -s Commit staged changes
ch -c Stage all changes and commit
ch show -s Preview commit message for staged changes (no commit)
ch show -c Preview commit message for current changes (no commit)
ch help Show this help
Note:
Reads config from ~/.config/ch/config
Supports AI_PROVIDER=anthropic|openai
Same diff collection logic as ch -s / ch -c respectively, but instead of prompting to commit:
- Generate the commit message via AI
- Print it to the terminal in a styled box
- Offer a copy to clipboard action:
- If running in a terminal: show
Press C to copyinline prompt, copy viapbcopy(macOS),xclip/xsel(Linux), orclip(Windows) - If output is piped (non-TTY): write the raw message to stdout only, no copy prompt
- If running in a terminal: show
- Exit without touching the git index or making any commit
No git add is run for ch show -c — it reads the unstaged diff (git diff) to preview what the message would look like without staging.
Example terminal output:
┌─ Generated commit message ──────────────────────────────┐
│ feat(auth): add JWT refresh token support │
│ │
│ - Add refresh endpoint │
│ - Store refresh token in httpOnly cookie │
│ - Rotate token on each use │
└─────────────────────────────────────────────────────────┘
Press C to copy | Any other key to exit
The diff is sent to the AI with a system prompt instructing it to:
- Write a concise, imperative commit message (≤72 characters for the subject)
- Follow the Conventional Commits format:
<type>(<scope>): <subject>- Types:
feat,fix,chore,refactor,docs,test,style,perf
- Types:
- Optionally include a short body (bullet points) if the change is complex
- Return only the commit message — no explanation, no markdown fencing
Example output:
feat(auth): add JWT refresh token support
- Add refresh endpoint
- Store refresh token in httpOnly cookie
- Rotate token on each use
Configuration is read from ~/.config/ch/config (or ~/.chrc):
AI_PROVIDER=claude-cli # default — uses installed `claude` CLI (no API key needed)
# or: anthropic | openai
AI_MODEL=claude-sonnet-4-6 # only used when provider is anthropic or openai
ANTHROPIC_API_KEY=sk-ant-... # only needed when AI_PROVIDER=anthropic
OPENAI_API_KEY=sk-... # only needed when AI_PROVIDER=openaiEnvironment variables override config file values.
Uses the claude CLI that ships with Claude Code, which is already authenticated.
No API key or account setup required.
claude -p "<system prompt>\n\n<diff>"- Requires
claudeto be installed and logged in (claude auth login) - Uses whatever model Claude Code is currently configured with
- Zero configuration for existing Claude Code users
- API: Messages API (
/v1/messages) - Requires
ANTHROPIC_API_KEYwith active credits - Default model:
claude-sonnet-4-6
- API: Chat Completions (
/v1/chat/completions) - Requires
OPENAI_API_KEY - Default model:
gpt-4o
AI_PROVIDERenv var or config file value- If
claudebinary is found in PATH → default toclaude-cli - If
ANTHROPIC_API_KEYis set → fall back toanthropic - If
OPENAI_API_KEYis set → fall back toopenai - Exit with:
No AI provider configured. Install Claude Code or set an API key.
| Scenario | Behavior |
|---|---|
| Not inside a git repo | Exit with: Not a git repository. |
| No changes / nothing staged | Exit with appropriate message |
claude CLI not found (claude-cli provider) |
Exit with: `claude` CLI not found. Install Claude Code or set AI_PROVIDER=anthropic. |
| API key missing (anthropic/openai provider) | Exit with: API key not configured. Set ANTHROPIC_API_KEY or OPENAI_API_KEY. |
| API call fails | Exit with: AI request failed: <error> |
| User declines confirmation | Exit without committing: Aborted. |
The tool can be implemented as:
- Shell script (
bash/zsh) — zero dependencies, easiest to install via PATH, works well withclaude -p - Python script — cleaner API handling, easier to test
- Node.js script — good if Anthropic/OpenAI JS SDKs are preferred
Recommended: Shell script — since the default provider (claude-cli) is just a subprocess call, a shell script has zero dependencies and is trivially installable.
# Install to user-local bin (no sudo required)
mkdir -p ~/.local/bin
cp ch ~/.local/bin/ch
chmod +x ~/.local/bin/ch
# Add to PATH if not already (add to ~/.zshrc or ~/.bashrc)
export PATH="$HOME/.local/bin:$PATH"
# Configure
mkdir -p ~/.config/ch
echo "AI_PROVIDER=anthropic" >> ~/.config/ch/config
echo "ANTHROPIC_API_KEY=your-key-here" >> ~/.config/ch/config# Stage specific files manually, then let AI commit
git add src/auth.py
ch -s
# Stage everything and commit in one step
ch -c
# Preview what the commit message would be for staged changes (no commit)
ch show -s
# Preview what the commit message would be for all current changes (no commit, no staging)
ch show -c- Branch awareness or PR description generation
- Multi-repo support
- Interactive diff selection (like
git add -p) - Commit signing
- GUI or TUI interface