This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
git-smartmsg is a Go CLI tool that uses OpenAI's API to generate improved commit messages for Git repositories. It operates in two phases:
- Plan phase: Analyzes commit history and generates AI-suggested commit messages, saving them to
plan.json - Apply phase: Creates a new branch with rewritten commit history using the improved messages
- Single-file Go application (
main.go) with clear separation of concerns - OpenAI Integration: Uses OpenAI SDK v2 with configurable API base and model
- Git Operations: Direct
gitcommand execution viaexec.Command - Plan Storage: JSON-based plan file format for staging commit message improvements
Key components:
AIClientinterface withOpenAIClientimplementationPlanandPlanItemstructs for managing commit rewriting plans- Git helper functions for repository operations
- Commit metadata extraction and diff generation
Required:
OPENAI_API_KEY: OpenAI API authentication key
Optional:
OPENAI_API_BASE: Custom API endpoint (for OpenAI-compatible services)OPENAI_MODEL: Model to use (defaults to "gpt-5-nano")
# Build the application
go build -o git-smartmsg main.go
# Run directly
go run main.go plan --limit 10
go run main.go apply --branch rewrite/improved-messages# Generate AI commit messages for last 20 commits
./git-smartmsg plan --limit 20 --model gpt-4o
# Generate commit messages with emoji prefixes
./git-smartmsg plan --emoji --limit 10
# Apply with custom range
./git-smartmsg plan --range HEAD~10..HEAD
# Apply the plan to a new branch
./git-smartmsg apply --branch improved-history --in plan.json
# Include merge commits (not recommended)
./git-smartmsg plan --allow-merges
./git-smartmsg apply --allow-merges --branch with-merges- Uses Conventional Commits style when appropriate (normal mode)
- Emoji mode: Uses present tense, imperative mood with contextual emoji prefixes
- Sanitizes messages to remove markdown formatting artifacts
- Limits first line to ~72 characters
- Preserves original author information and timestamps
When --emoji flag is used, commit messages start with contextual emojis:
- 🎨
:art:when improving code structure/format - 🐛
:bug:when fixing bugs - 📝
:memo:when writing docs - ✅
:white_check_mark:when adding tests - 🔒
:lock:when dealing with security - ⬆️
:arrow_up:when upgrading dependencies - And more based on the change context
- Requires clean worktree before applying changes
- Creates new branches for rewritten history (never modifies current branch)
- Skips merge commits by default (linear history preference)
- Uses cherry-pick with
--no-verifyto avoid hooks during rewriting
- All git commands use
exec.Commandwith proper error handling - Preserves author name, email, and date during commit rewriting
- Uses
--force-with-leaserecommendation for safe force-pushing
main.go: Complete application logicplan.json: Generated plan file (git-ignored, working file)go.mod/go.sum: Go module dependencies (OpenAI SDK v2)