|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +CodeGPT is a CLI tool written in Go that generates git commit messages and code reviews using AI. It supports multiple AI providers (OpenAI, Azure OpenAI, Gemini, Anthropic, Ollama, Groq, OpenRouter) and integrates with git prepare-commit-msg hooks. |
| 8 | + |
| 9 | +## Build and Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build the binary |
| 13 | +make build # outputs to bin/codegpt |
| 14 | + |
| 15 | +# Install globally |
| 16 | +make install |
| 17 | + |
| 18 | +# Run all tests with coverage |
| 19 | +make test # or: go test -v -cover -coverprofile coverage.txt ./... |
| 20 | + |
| 21 | +# Run a single test |
| 22 | +go test -v -run TestName ./path/to/package |
| 23 | + |
| 24 | +# Lint (uses golangci-lint v2) |
| 25 | +golangci-lint run |
| 26 | +``` |
| 27 | + |
| 28 | +## Architecture |
| 29 | + |
| 30 | +### Package Structure |
| 31 | + |
| 32 | +- **cmd/** - CLI commands using Cobra |
| 33 | + - `cmd.go` - Root command setup and config initialization |
| 34 | + - `commit.go` - Generate commit messages (`codegpt commit`) |
| 35 | + - `review.go` - Generate code reviews (`codegpt review`) |
| 36 | + - `hook.go` - Git hook management (`codegpt hook install/uninstall`) |
| 37 | + - `config.go`, `config_set.go`, `config_list.go` - Configuration management |
| 38 | + |
| 39 | +- **core/** - Core abstractions |
| 40 | + - `openai.go` - `Generative` interface that all providers implement |
| 41 | + - `platform.go` - CI/CD platform detection |
| 42 | + |
| 43 | +- **provider/** - AI provider implementations (all implement `core.Generative`) |
| 44 | + - `openai/` - OpenAI, Azure, Groq, OpenRouter, Ollama (OpenAI-compatible) |
| 45 | + - `anthropic/` - Anthropic Claude |
| 46 | + - `gemini/` - Google Gemini (supports both Gemini API and VertexAI backends) |
| 47 | + |
| 48 | +- **git/** - Git operations |
| 49 | + - `git.go` - Diff generation, commit operations |
| 50 | + - `hook.go` - prepare-commit-msg hook installation |
| 51 | + |
| 52 | +- **prompt/** - Prompt management |
| 53 | + - Templates stored in `prompt/templates/` |
| 54 | + - Supports custom prompt folders via config |
| 55 | + |
| 56 | +- **proxy/** - Network proxy support (SOCKS and HTTP) |
| 57 | + |
| 58 | +- **util/** - Utilities including Go template rendering |
| 59 | + |
| 60 | +### Configuration |
| 61 | + |
| 62 | +Config file: `$HOME/.config/codegpt/.codegpt.yaml` |
| 63 | +Prompt folder: `$HOME/.config/codegpt/prompt/` |
| 64 | + |
| 65 | +Key config keys: `openai.provider`, `openai.api_key`, `openai.model`, `openai.base_url`, `git.diff_unified`, `output.lang` |
| 66 | + |
| 67 | +### Adding a New Provider |
| 68 | + |
| 69 | +1. Create package under `provider/` |
| 70 | +2. Implement `core.Generative` interface (`Completion` and `GetSummaryPrefix` methods) |
| 71 | +3. Add options pattern for configuration |
| 72 | +4. Wire up in `cmd/provider.go` |
0 commit comments