This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
GitComm is a CLI tool that uses LLMs to automatically generate meaningful Git commit messages by analyzing staged changes. The tool uses OpenRouter to access multiple LLM models with automatic fallback support.
- Build:
go build ./... - Run:
go run . - Install CLI:
go install ./... - Tidy dependencies:
go mod tidy
- Lint:
golangci-lint run(install withgo install github.com/golangci/golangci-lint/cmd/golangci-lint@latest) - Format:
go fmt ./... - Vet:
go vet ./...
- All tests:
go test ./... - Package tests:
go test ./internal/analyzer -v - Single test:
go test ./internal/analyzer -run TestName -v
- main.go - Entry point handling CLI flags and orchestration
- internal/analyzer - Orchestrates LLM analysis of git diffs
- internal/llm - LLM client abstraction supporting multiple providers
- internal/config - Configuration management for API keys
- internal/git - Git operations wrapper
- Main parses CLI flags (
-setup,-auto,-ap,-sa,-debug) - Git operations get staged changes or stage all files
- Analyzer sends diff to LLM with structured prompt
- LLM response is parsed to extract commit message
- Optionally commits and/or pushes changes
API keys are loaded in this order (environment variables override file):
~/.gitcomm/config.jsonfile- Environment variables:
GEMINI_API_KEY,GROQ_API_KEY,OPENAI_API_KEY
- Primary: Gemini (gemini-1.5-flash)
- Fallback: Groq (llama-3.1-70b-versatile) or OpenAI (gpt-4o-mini)
- Settings: Max tokens: 400, Temperature: 0.7 (optimized for proper Git commit format)
- Go version: 1.23.x with modules enabled
- Imports: Standard library, then external, then internal packages
- Formatting: Use
go fmt, keep files under 250 lines when practical - Error handling: Return
(T, error), wrap with context usingfmt.Errorf("...: %w", err) - Logging: Use
log/slogfor structured logging ininternal/llm, simplefmt.Printlnfor CLI output
- CLI flags: Maintain backwards compatibility with existing flags
- Git operations: Shell out to git commands, avoid interactive prompts in library code
- API keys: Never log secrets, use environment variables or config file
- Prompt engineering: Structure LLM prompts for single-line commit message extraction
- Fallback logic: Gemini is always available as fallback when other providers fail
Use -debug flag to enable verbose logging that shows:
- Flag parsing and startup sequence
- Git command execution and output sizes
- LLM client initialization and API calls
- Response processing and extraction
The project focuses on integration testing with real APIs due to the nature of LLM interactions. When adding new LLM providers or prompt formats, test with actual API calls rather than mocks.