This file provides guidance for Claude Code (claude.ai/code) when processing this codebase.
CodeAgent is a Go-based automated code generation and collaboration system that receives various AI instructions through GitHub Webhooks, automatically handling code generation, modification, and review tasks for Issues and Pull Requests.
The system adopts a webhook-driven architecture:
GitHub Events (AI Instructions) → Webhook → CodeAgent → Branch Creation → PR Processing → AI Container → Code Generation/Modification → PR Updates
- Agent (
internal/agent/agent.go): Orchestrates the entire workflow - Webhook Handler (
internal/webhook/handler.go): Handles GitHub webhooks (Issues and PRs) - Workspace Manager (
internal/workspace/manager.go): Manages temporary Git worktrees - Code Providers (
internal/code/): Supports Claude (Docker/CLI) and Gemini (Docker/CLI) - GitHub Client (
internal/github/client.go): Handles GitHub API interactions
# Build binary file
make build
# Run locally with configuration
./scripts/start.sh # Gemini + CLI mode (default)
./scripts/start.sh -p claude -d # Claude + Docker mode
./scripts/start.sh -p gemini -d # Gemini + Docker mode
./scripts/start.sh -p claude # Claude + CLI mode
# Direct Go run
export GITHUB_TOKEN="your-token"
export GOOGLE_API_KEY="your-key" # or CLAUDE_API_KEY
export WEBHOOK_SECRET="your-secret"
go run ./cmd/server --port 8888# Run tests
make test
# Health check
curl http://localhost:8888/health
# Test webhook processing
curl -X POST http://localhost:8888/hook \
-H "Content-Type: application/json" \
-H "X-GitHub-Event: issue_comment" \
-d @test-data/issue-comment.jsonRequired environment variables:
GITHUB_TOKEN- GitHub personal access tokenWEBHOOK_SECRET- GitHub webhook secretGOOGLE_API_KEY(for Gemini) orCLAUDE_API_KEY(for Claude)
Configuration file: config.yaml
code_provider: gemini # claude or gemini
use_docker: false # true for Docker, false for CLI
server:
port: 8888cmd/server/- Main application entry pointinternal/- Core business logicagent/- Main orchestration logicwebhook/- GitHub webhook handlingworkspace/- Git worktree managementcode/- AI provider implementations (Claude/Gemini)github/- GitHub API client
pkg/models/- Shared data structuresscripts/- Utility scripts, includingstart.sh
- Local Development: Use CLI mode
./scripts/start.sh -p claude/gemini - Testing: Send test webhooks and example GitHub events
- Docker Development: Use Docker mode for containerized testing
- Workspace Management: Temporary worktrees created in
/tmp/codeagent, automatically cleaned up after 24 hours
The system supports various AI instructions triggered through GitHub comments and reviews:
Issue Instructions:
/code <description>- Generate initial code for the Issue and create a PR
PR Collaboration Instructions:
/continue <instruction>- Continue development in the PR, supporting custom instructions/fix <description>- Fix code issues in the PR
Supported Scenarios:
- Instruction handling in Issue comments
- Instruction handling in PR comments
- Instruction handling in PR Review comments
- Batch processing of PR Reviews (supports batch processing of multiple comments)
Instruction Features:
- Supports custom parameters and instruction content
- Automatically retrieves historical comment context
- Intelligent code submission and PR updates
- Complete error handling and retry mechanism
The system is designed as an extensible architecture, making it easy to add new instruction types and processing logic in the future.
- Docker Mode: Use containerized Claude/Gemini, including a complete toolkit
- CLI Mode: Use locally installed Claude CLI or Gemini CLI (faster during development)
- Docker mode requires ensuring Docker is running
- CLI mode requires checking if CLI tools are installed:
claudeorgemini - Verify GitHub webhook configuration matches local port
- Monitor logs to troubleshoot workspace cleanup issues
- When modifying code, always remember to perform type checking and formatting