一个现代化的 Claude Code & Codex API 代理服务,提供智能负载均衡、用户管理和使用统计功能。 https://claude-code-hub.app/
|
|
6 zile în urmă | |
|---|---|---|
| .github | 1 săptămână în urmă | |
| .vscode | 2 luni în urmă | |
| data | 3 luni în urmă | |
| deploy | 3 săptămâni în urmă | |
| dev | 1 lună în urmă | |
| docs | 3 săptămâni în urmă | |
| docs-site | 2 luni în urmă | |
| drizzle | 1 săptămână în urmă | |
| messages | 1 săptămână în urmă | |
| public | 1 lună în urmă | |
| reports | 1 lună în urmă | |
| scripts | 1 săptămână în urmă | |
| src | 6 zile în urmă | |
| tests | 6 zile în urmă | |
| .dockerignore | 2 luni în urmă | |
| .editorconfig | 4 luni în urmă | |
| .env.example | 2 săptămâni în urmă | |
| .gitignore | 1 săptămână în urmă | |
| .mcp.json | 3 luni în urmă | |
| .prettierignore | 2 luni în urmă | |
| AGENTS.md | 1 lună în urmă | |
| CHANGELOG.md | 1 săptămână în urmă | |
| CLAUDE.md | 1 lună în urmă | |
| CONTRIBUTING.md | 1 lună în urmă | |
| Dockerfile | 1 săptămână în urmă | |
| LICENSE | 4 luni în urmă | |
| Makefile | 1 lună în urmă | |
| README.en.md | 1 săptămână în urmă | |
| README.md | 1 săptămână în urmă | |
| VERSION | 1 săptămână în urmă | |
| biome.json | 1 lună în urmă | |
| components.json | 3 luni în urmă | |
| docker-compose.dev.yaml | 1 lună în urmă | |
| docker-compose.yaml | 3 săptămâni în urmă | |
| drizzle.config.ts | 2 luni în urmă | |
| next.config.ts | 1 lună în urmă | |
| package.json | 1 săptămână în urmă | |
| postcss.config.mjs | 4 luni în urmă | |
| tsconfig.json | 1 lună în urmă | |
| vitest.codex-session-id-completer.config.ts | 1 lună în urmă | |
| vitest.config.ts | 1 lună în urmă | |
| vitest.e2e.config.ts | 1 lună în urmă | |
| vitest.include-session-id-in-errors.config.ts | 3 săptămâni în urmă | |
| vitest.integration.config.ts | 6 zile în urmă | |
| vitest.logs-sessionid-time-filter.config.ts | 3 săptămâni în urmă | |
| vitest.my-usage.config.ts | 1 lună în urmă | |
| vitest.proxy-guard-pipeline.config.ts | 1 lună în urmă | |
| vitest.quota.config.ts | 1 lună în urmă | |
| vitest.thinking-signature-rectifier.config.ts | 1 lună în urmă | |
| vitest.usage-logs-sessionid-search.config.ts | 3 săptămâni în urmă |
English | 中文
|
💎 Special Offer: Cubence is a stable and efficient AI service transit platform, providing transit services for AI tools such as Claude Code, Codex, Gemini, with good stability and cost-effectiveness. Cubence offers special discount coupons for users of CCH: when purchasing with the coupon DING113CCH, you can enjoy a 10% discount → Visit Now
|
|
💎 Special Offer: Thanks to PackyCode for sponsoring this project! PackyCode is a stable and efficient API relay service provider, offering relay services for Claude Code, Codex, Gemini and more. PackyCode offers a special discount for users of this software. Register via this link and enter code WITHCCH when recharging to enjoy 10% off → Visit Now
|
|
💎 Special Offer: YesCode is a low-profile yet highly reliable AI API relay service, dedicated to providing developers with stable access to Claude, Codex, Gemini, and other models. Built on solid technical foundations with consistently dependable service quality. Register via this link to get started → Visit Now |
/v1/chat/completions (OpenAI-compatible format), passes through tool calls and reasoning fields, enforces strict same-format routing with no cross-format conversion.The one-click deployment script automatically handles all of the following:
Linux / macOS:
# Download and run the deployment script
curl -fsSL https://raw.githubusercontent.com/ding113/claude-code-hub/main/scripts/deploy.sh -o deploy.sh
chmod +x deploy.sh
./deploy.sh
Or using wget:
wget https://raw.githubusercontent.com/ding113/claude-code-hub/main/scripts/deploy.sh
chmod +x deploy.sh
./deploy.sh
Windows (PowerShell as Administrator):
# Download and run the deployment script
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/ding113/claude-code-hub/main/scripts/deploy.ps1" -OutFile "deploy.ps1"
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
.\deploy.ps1
Deployment Directories:
/www/compose/claude-code-hub~/Applications/claude-code-hubC:\ProgramData\claude-code-hubBranch Selection:
The script will prompt you to select a deployment branch:
main (default): Stable release, recommended for productiondev: Development version with latest features, for testingImportant Notes:
Clone and configure
git clone https://github.com/ding113/claude-code-hub.git
cd claude-code-hub
cp .env.example .env
Edit configuration
Edit the .env file and update ADMIN_TOKEN (admin login token):
# MUST change this!
ADMIN_TOKEN=your-secure-token-here
# Docker Compose defaults (usually no changes needed)
DSN=postgres://postgres:postgres@postgres:5432/claude_code_hub
REDIS_URL=redis://redis:6379
Start services
docker compose up -d
Check status:
docker compose ps
docker compose logs -f app
Once started:
http://localhost:23000 (login with ADMIN_TOKEN from .env)http://localhost:23000/api/actions/scalarhttp://localhost:23000/api/actions/docs💡 Tip: To change the port, edit the
portssection indocker-compose.yml.
Clients / CLI / Integrations
│
▼
Next.js 15 App Router (v1 API routes)
│
Hono + Proxy Pipeline (Auth → Session Allocation → Rate Limiting → Provider Selection → Forwarding → Response Handling)
│
Multi-provider pool (Claude / OpenAI / Gemini / others) + PostgreSQL + Redis
src/app hosts dashboards, settings, and API actions for UI and internal APIs.src/app/v1/_lib/proxy-handler.ts chains ProxyAuthenticator, ProxySessionGuard, ProxyRateLimitGuard, ProxyProviderResolver, ProxyForwarder, and ProxyResponseHandler.src/lib contains rate limiting, session manager, circuit breaker, proxy utilities, and price-sync; src/repository encapsulates Drizzle ORM queries.src/app/api/actions/[...route]/route.ts converts Server Actions into OpenAPI endpoints automatically.ProxyAuthenticator.SessionManager fetches the five-minute cache from Redis, enforces concurrency, and records the decision chain.RateLimitService applies Lua-driven atomic counters for RPM, spend, and session caps, falling back gracefully if Redis is unavailable.ProxyProviderResolver scores vendors with weights, priorities, breaker states, and session reuse, retrying up to three times.ProxyForwarder sends requests upstream; ProxyResponseHandler processes response streams while preserving endpoint-native formats, with proxy support and model redirects.Docker Compose is the preferred deployment method — it automatically provisions the database, Redis, and application services without manual dependency installation, ideal for production quick-start.
.env (see .env.example) and point DSN/REDIS_URL to the Compose services.Start the stack:
docker compose up -d
Monitor:
docker compose logs -f app
docker compose ps
Upgrade:
docker compose pull && docker compose up -d
Stop and clean up with docker compose down when necessary.
dev/ folder: cd dev.make dev to launch PostgreSQL + Redis + bun dev in one command.make db: start only database and Redis.make logs / make logs-app: tail all services or app logs.make clean / make reset: clean or fully reset the environment.make migrate and make db-shell for schema operations.Install dependencies and build:
bun install
bun run build # Copies the VERSION file automatically
Export environment variables via your process manager (systemd, PM2, etc.) and ensure PostgreSQL/Redis endpoints are reachable.
Launch production server:
bun run start
You may keep AUTO_MIGRATE=true for the first run, then disable it and manage migrations explicitly with Drizzle CLI.
| Variable | Default | Description |
|---|---|---|
ADMIN_TOKEN |
change-me |
Admin console token — must be updated before deployment. |
DSN |
- | PostgreSQL connection string, e.g., postgres://user:pass@host:5432/db. |
AUTO_MIGRATE |
true |
Executes Drizzle migrations on startup; consider disabling in production for manual control. |
REDIS_URL |
redis://localhost:6379 |
Redis endpoint, supports rediss:// for TLS providers. |
REDIS_TLS_REJECT_UNAUTHORIZED |
true |
Validate Redis TLS certificates; set false to skip (for self-signed/shared certs). |
ENABLE_RATE_LIMIT |
true |
Toggles multi-dimensional rate limiting; Fail-Open handles Redis outages gracefully. |
SESSION_TTL |
300 |
Session cache window (seconds) that drives vendor reuse. |
ENABLE_SECURE_COOKIES |
true |
Browsers require HTTPS for Secure cookies; set to false when serving plain HTTP outside localhost. |
ENABLE_CIRCUIT_BREAKER_ON_NETWORK_ERRORS |
false |
When true, network errors also trip the circuit breaker for quicker isolation. |
APP_PORT |
23000 |
Production port (override via container or process manager). |
APP_URL |
empty | Populate to expose correct servers entries in OpenAPI docs. |
API_TEST_TIMEOUT_MS |
15000 |
Timeout (ms) for provider API connectivity tests. Accepts 5000-120000 for regional tuning. |
Boolean values should be
true/falseor1/0without quotes; otherwise Zod may coerce strings incorrectly. See.env.examplefor the full list.
Database connection failures
DSN format and credentials; use service names (e.g., postgres:5432) within Docker.docker compose ps or local PostgreSQL status, and use make db-shell for deeper checks.What if Redis goes offline?
Circuit breaker keeps opening
[CircuitBreaker] logs to see whether repeated 4xx/5xx or network errors triggered it.“No provider available” errors
Proxy configuration issues
http://, socks5://, etc.) and validate via the “Test Connection” button in the UI.proxy_fallback_to_direct is enabled, confirm via logs that the system retried without the proxy when failures occur.We welcome issues and PRs! Please read CONTRIBUTING.md for the bilingual guidelines, branch strategy, and Conventional Commits requirements before submitting changes.
This project builds on zsio/claude-code-hub, references router-for-me/CLIProxyAPI for the OpenAI-compatible layer, and prehisle/relay-pulse for provider detection functionality. Huge thanks to the original authors and community contributors!
Released under the MIT License. You’re welcome to use and extend the project as long as you comply with the license and retain the attribution.