中文 | English
A Claude Code proxy server rewritten in Go, providing a complete frontend and backend interface that supports converting Claude API requests to OpenAI API calls.
/v1/messages endpoint# Ensure Go 1.21+ is installed
go version
# Download dependencies
go mod tidy
# Copy configuration file (optional)
cp .env.example .env
# Edit .env file to set data storage directory and security keys
# All API and service configurations are managed through the web interface
Using published images:
# Using Docker Hub image with data persistence
docker run -d -p 8082:8082 \
-v ccany_data:/app/data \
-v ccany_logs:/app/logs \
-e OPENAI_API_KEY=your_openai_api_key \
czyt/ccany:latest
# Or using GitHub Container Registry image with data persistence
docker run -d -p 8082:8082 \
-v ccany_data:/app/data \
-v ccany_logs:/app/logs \
-e OPENAI_API_KEY=your_openai_api_key \
ghcr.io/ca-x/ccany:latest
Using Docker Compose (Production):
# Copy environment configuration
cp .env.example .env
# Edit .env file to set required API keys
# Use production compose (with published images)
docker-compose -f docker-compose.production.yml up -d
# Or use full compose (includes monitoring services)
docker-compose up -d
# Start server
go run cmd/server/main.go
# After starting the server, initial setup is required for first access
# Visit http://localhost:8082/setup to create admin account and configure API keys
# Or use the deployment script for automated deployment:
chmod +x scripts/deploy.sh
./scripts/deploy.sh start
# After logging into the web interface, configure in the management panel:
# - OpenAI API key and base URL
# - Claude API key and base URL
# - Model configuration
# - Performance parameters
ANTHROPIC_BASE_URL=http://localhost:8082 ANTHROPIC_AUTH_TOKEN="some-api-key" claude
Open your browser and visit http://localhost:8082 to view the management panel.
System Configuration:
CLAUDE_PROXY_DATA_PATH - Data storage directory (default: ./data)CLAUDE_PROXY_MASTER_KEY - Master key for encrypting sensitive configurations (recommended for production)JWT_SECRET - JWT key for user authentication (recommended for production)API Configuration:
Model Configuration:
gpt-4o)gpt-4o-mini)Server Settings:
0.0.0.0)8082)info)Performance Configuration:
4096)100)90)2)0.7)true)💡 Note: All API and service configurations are now managed through the web management interface, no longer requiring environment variables. Visit the
/setuppage for initial setup on first run.
The proxy maps Claude model requests to your configured models:
| Claude Request | Mapped To | Environment Variable |
|---|---|---|
| Models containing "haiku" | SMALL_MODEL | Default: gpt-4o-mini |
| Models containing "sonnet" or "opus" | BIG_MODEL | Default: gpt-4o |
Configure through web interface:
sk-your-openai-keyhttps://api.openai.com/v1gpt-4ogpt-4o-miniConfigure through web interface:
your-azure-keyhttps://your-resource.openai.azure.com/openai/deployments/your-deployment2024-02-01gpt-4gpt-35-turboConfigure through web interface:
dummy-key (required but can be dummy)http://localhost:11434/v1llama3.1:70bllama3.1:8bConfigure through web interface:
sk-ant-your-claude-keyhttps://api.anthropic.comAccess http://localhost:8082 to use the web management interface, which includes:
The interface features Apple-style design with responsive layout and frosted glass effects. A complete authentication system ensures the security of the management interface.
ccany/ ├── cmd/ │ └── server/ │ └── main.go # Main program entry ├── internal/ │ ├── app/ # Application configuration management │ ├── auth/ # Authentication service │ ├── cache/ # Cache service │ ├── claudecode/ # Claude Code compatibility services │ ├── client/ # OpenAI client │ ├── config/ # Configuration management │ ├── converter/ # Request/response converter │ ├── crypto/ # Encryption service │ ├── database/ # Database management │ ├── handlers/ # HTTP handlers │ ├── logging/ # Request logging │ ├── middleware/ # Middleware │ ├── models/ # Data models │ └── monitoring/ # System monitoring ├── ent/ │ ├── schema/ # Database schema definitions │ └── ... # Generated ORM code ├── tests/ │ └── basic_test.go # Basic test file ├── scripts/ │ └── deploy.sh # Deployment script ├── web/ │ ├── index.html # Main page │ ├── setup.html # Setup page │ └── static/ │ ├── css/ # Style files │ └── js/ # JavaScript files ├── .env.example # Configuration template ├── go.mod # Go module file ├── Makefile # Build script └── README.md # This file
POST /v1/messages - Create messagePOST /v1/messages/count_tokens - Count tokensGET / - Web management interfaceGET /health - Health checkGET /ready - Readiness checkGET /setup - Initialization setup interfacePOST /setup - Submit initialization setupPOST /admin/auth/login - Admin loginPOST /admin/auth/logout - Admin logoutGET /admin/auth/profile - Get user informationGET /admin/users - Get user listPOST /admin/users - Create userPUT /admin/users/:id - Update userDELETE /admin/users/:id - Delete userGET /admin/config - Get configuration informationPUT /admin/config - Update configurationGET /admin/request-logs - Get request logsGET /admin/request-logs/stats - Get request statisticsDELETE /admin/request-logs - Clear request logsGET /admin/monitoring/health - System health checkGET /admin/monitoring/metrics - System metricsGET /admin/monitoring/system - System information# Build executable
go build -o ccany cmd/server/main.go
# Cross-compile
GOOS=linux GOARCH=amd64 go build -o ccany-linux cmd/server/main.go
GOOS=windows GOARCH=amd64 go build -o ccany.exe cmd/server/main.go
# Run all tests
go test ./...
# Run tests for specific package
go test ./internal/converter
# Run integration tests (requires server to be running)
go test -v ./tests/
# Run benchmark tests
go test -bench=. ./tests/
# Generate test coverage report
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# Format code
go fmt ./...
# Check code
go vet ./...
This proxy is designed to work seamlessly with Claude Code CLI. The enhanced version includes complete Claude Code compatibility support:
# Start the enhanced proxy using deployment script
./scripts/deploy.sh start
# Use Claude Code with the proxy
ANTHROPIC_BASE_URL=http://localhost:8082 claude
# Or set permanently
export ANTHROPIC_BASE_URL=http://localhost:8082
claude
message_start, content_block_start, ping, content_block_delta, content_block_stop, message_delta, message_stop events~/.claude.json configuration filethinking field and intelligent model routingcache_read_input_tokens usage reporting# Basic deployment
./scripts/deploy.sh start
# Deployment with monitoring
./scripts/deploy.sh monitoring
# Deployment with Nginx
./scripts/deploy.sh nginx
# Test Claude Code compatibility
./scripts/deploy.sh test
# Show help
./scripts/deploy.sh help
# Copy environment configuration
cp .env.example .env
# Edit .env file to configure API keys
# Basic deployment
docker-compose up -d
# Deployment with monitoring
docker-compose --profile monitoring up -d
# Deployment with Nginx
docker-compose --profile nginx up -d
# Test Claude Code compatibility
docker-compose --profile test up --build test-claude-code
# Automated deployment (recommended)
./scripts/deploy.sh start
# Deployment with monitoring stack
./scripts/deploy.sh monitoring
# Check service status
./scripts/deploy.sh status
# View logs
./scripts/deploy.sh logs
For detailed deployment guide, please refer to: Deployment Documentation
MIT License
Issues and Pull Requests are welcome!