一个现代化的 Claude Code & Codex API 代理服务,提供智能负载均衡、用户管理和使用统计功能。 https://claude-code-hub.app/
|
|
2 месяцев назад | |
|---|---|---|
| .github | 2 месяцев назад | |
| data | 3 месяцев назад | |
| deploy | 2 месяцев назад | |
| drizzle | 2 месяцев назад | |
| messages | 2 месяцев назад | |
| public | 2 месяцев назад | |
| scripts | 2 месяцев назад | |
| src | 2 месяцев назад | |
| tests | 2 месяцев назад | |
| .dockerignore | 3 месяцев назад | |
| .editorconfig | 4 месяцев назад | |
| .env.example | 3 месяцев назад | |
| .gitignore | 2 месяцев назад | |
| .mcp.json | 3 месяцев назад | |
| .prettierignore | 2 месяцев назад | |
| .prettierrc.json | 3 месяцев назад | |
| AGENTS.md | 2 месяцев назад | |
| CLAUDE.md | 2 месяцев назад | |
| CONTRIBUTING.md | 2 месяцев назад | |
| LICENSE | 4 месяцев назад | |
| Makefile | 3 месяцев назад | |
| README.en.md | 2 месяцев назад | |
| README.md | 2 месяцев назад | |
| VERSION | 3 месяцев назад | |
| bun.lock | 2 месяцев назад | |
| components.json | 3 месяцев назад | |
| docker-compose.yaml | 3 месяцев назад | |
| drizzle.config.ts | 3 месяцев назад | |
| eslint.config.mjs | 3 месяцев назад | |
| next.config.ts | 3 месяцев назад | |
| package.json | 2 месяцев назад | |
| postcss.config.mjs | 4 месяцев назад | |
| tsconfig.json | 2 месяцев назад |
English | 中文
/v1/chat/completions, handles format conversions, tool calls, reasoning fields, and Codex CLI instruction injection automatically.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 plus ResponseTransformer adapt Claude/OpenAI/Response formats, handle proxies, and honor 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. |
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. |
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 and references router-for-me/CLIProxyAPI for the OpenAI-compatible layer. 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.