claude-relay-service
CLAUDE.md13k starsChanged 8 months agoMITView on GitHub
Claude Relay Service — 多平台 AI API 中转服务,作为客户端与上游 AI API 之间的中间件。 支持 Claude (官方/Console)、Gemini、OpenAI Responses、AWS Bedrock、Azure OpenAI、Droid、CCR 等账户类型。 核心能力:多账户管理、API Key 认证、统一调度、代理配置、限流、成本统计。 关键机制: - 粘性会话: 基于请求内容 hash 绑定账户,同一会话用同一账户 - 并发控制: Redis Sorted Set 实现,支持排队等待(非直接 429) - 529 处理: 自动标记过载账户,配置时长内排除 - 加密存储: 敏感数据(OAuth token、credentials)AES 加密存于 Redis - 流式响应: SSE 传输,实时捕获 usage,客户端断开时 AbortController 清理资源
- Reads credentials
- Installs packages
Trending
Quiet since September.about the whole repository
Who's talking about Wei-Shaw/claude-relay-service
- CherryHQ/cherry-studio“feat: support codex oauth signin”GitHub · Nov 7, 2025 · 2 reactions
- @github-trending-js.bsky.social“📦 Wei-Shaw / claude-relay-service ⭐ 8,738 (+96) 🗒 JavaScript CRS-自建Claude Code镜像,一站式开源中转服务,让 …”Bluesky · Mar 1, 2026 · 1 likes
- @github-trending.bsky.social“📦 Wei-Shaw / claude-relay-service ⭐ 8,471 (+56) 🗒 JavaScript CRS-自建Claude Code镜像,一站式开源中转服务,让 …”Bluesky · Feb 27, 2026 · 1 likes
- @github-trending-js.bsky.social“🚀 Skyrocketing! 🚀 (200+ new stars) 📦 Wei-Shaw / claude-relay-service ⭐ 5,030 (+209) 🗒 JavaScript …”Bluesky · Nov 4, 2025 · 1 likes
- ChatArch/claude-relay-service“feat: native scoped Codex subscription APIs”GitHub · Sep 21, 2026
The biggest 5 of 35 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 35
Talked about on GitHub and Bluesky (35 times).
On GitHub · 32
- Nov 7, 2025feat: support codex oauth signin — CherryHQ/cherry-studio2 reactions · 7 comments
- Sep 21, 2026feat: native scoped Codex subscription APIs — ChatArch/claude-relay-service0 reactions
- Sep 20, 2026Release ChatCRS 0.3.5: managed Codex subscriptions — ChatArch/ChatCRS0 reactions · 1 comment
- Sep 8, 2026feat: add API-key Responses image generation (0.1.8) — ChatArch/ChatImg0 reactions · 1 comment
- Aug 22, 2026fix(openai): mark invalid refresh tokens unauthorized — ChatArch/claude-relay-service0 reactions
27 more on GitHub
- Apr 23, 2026Gemini CLI 调用失败 — nyroway/nyro0 reactions · 1 comment
- Mar 17, 2026[2026-03-18 00:42:11] - V2EX 共 9 条热门话题 — R2DM/v2ex_mofish0 reactions
- Mar 14, 2026chore(claude-relay): bump chart to 0.1.38 (appVersion v1.1.315) — Revolution1/helm-charts0 reactions
- Jan 30, 2026chore(claude-relay): bump chart to 0.1.37 (appVersion v1.1.292) — Revolution1/helm-charts0 reactions
- Jan 23, 2026chore(claude-relay): bump chart to 0.1.36 (appVersion v1.1.267) — Revolution1/helm-charts0 reactions
- Jan 22, 2026chore(claude-relay): bump chart to 0.1.35 (appVersion v1.1.262) — Revolution1/helm-charts0 reactions
- Jan 21, 2026chore(claude-relay): bump chart to 0.1.34 (appVersion v1.1.260) — Revolution1/helm-charts0 reactions
- Jan 15, 2026chore(claude-relay): bump chart to 0.1.33 (appVersion v1.1.259) — Revolution1/helm-charts0 reactions
- Jan 14, 2026chore(claude-relay): bump chart to 0.1.32 (appVersion v1.1.257) — Revolution1/helm-charts0 reactions
- Jan 13, 2026使用 sub2api + cc-router中转gemini3 在claude code中使用经常 429 — Wei-Shaw/sub2api0 reactions · 2 comments
- Jan 9, 2026chore(claude-relay): bump chart to 0.1.31 (appVersion v1.1.256) — Revolution1/helm-charts0 reactions
- Jan 8, 2026chore(claude-relay): bump chart to 0.1.30 (appVersion v1.1.254) — Revolution1/helm-charts0 reactions
- Jan 8, 2026chore(claude-relay): bump chart to 0.1.29 (appVersion v1.1.253) — Revolution1/helm-charts0 reactions
- Jan 7, 2026chore(claude-relay): bump chart to 0.1.28 (appVersion v1.1.252) — Revolution1/helm-charts0 reactions
- Jan 1, 2026chore(claude-relay): bump chart to 0.1.27 (appVersion v1.1.251) — Revolution1/helm-charts0 reactions
- Dec 29, 2025chore(claude-relay): bump chart to 0.1.26 (appVersion v1.1.250) — Revolution1/helm-charts0 reactions
- Dec 26, 2025chore(claude-relay): bump chart to 0.1.25 (appVersion v1.1.249) — Revolution1/helm-charts0 reactions
- Dec 25, 2025chore(claude-relay): bump chart to 0.1.24 (appVersion v1.1.241) — Revolution1/helm-charts0 reactions
- Dec 24, 2025chore(claude-relay): bump chart to 0.1.23 (appVersion v1.1.239) — Revolution1/helm-charts0 reactions
- Dec 21, 2025chore(claude-relay): bump chart to 0.1.22 (appVersion v1.1.238) — Revolution1/helm-charts0 reactions
- Dec 19, 2025chore(claude-relay): bump chart to 0.1.21 (appVersion v1.1.237) — Revolution1/helm-charts0 reactions
- Dec 15, 2025chore(claude-relay): bump chart to 0.1.20 (appVersion v1.1.235) — Revolution1/helm-charts0 reactions
- Dec 12, 2025chore(claude-relay): bump chart to 0.1.19 (appVersion v1.1.233) — Revolution1/helm-charts0 reactions
- Dec 11, 2025chore(claude-relay): bump chart to 0.1.18 (appVersion v1.1.232) — Revolution1/helm-charts0 reactions
- Dec 10, 2025chore(claude-relay): bump chart to 0.1.17 (appVersion v1.1.231) — Revolution1/helm-charts0 reactions
- Oct 31, 2025Posted: Wei-Shaw / claude-relay-service — nanameru/x-post-automation0 reactions
- Aug 22, 2025【feature】建议增加gemini-cli的账号代理支持调度,可以参考项目:https://github.com/Wei-Shaw/claude-relay-service — tbphp/gpt-load0 reactions · 1 comment
On Bluesky · 3
- Mar 1, 2026📦 Wei-Shaw / claude-relay-service ⭐ 8,738 (+96) 🗒 JavaScript CRS-自建Claude Code镜像,一站式开源中转服务,让 Claude、OpenAI、Gemini、Droid… — @github-trending-js.bsky.social1 likes and repost
- Feb 27, 2026📦 Wei-Shaw / claude-relay-service ⭐ 8,471 (+56) 🗒 JavaScript CRS-自建Claude Code镜像,一站式开源中转服务,让 Claude、OpenAI、Gemini、Droid… — @github-trending.bsky.social1 likes and repost
- Nov 4, 2025🚀 Skyrocketing! 🚀 (200+ new stars) 📦 Wei-Shaw / claude-relay-service ⭐ 5,030 (+209) 🗒 JavaScript CRS-自建Claude Code镜像,一站式开源中转服务,让… — @github-trending-js.bsky.social1 likes and repost
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 185
Do what has been asked; nothing more, nothing less.
- Distinctive: line 186
NEVER create files unless they're absolutely necessary for achieving your goal.
- Distinctive: line 187
ALWAYS prefer editing an existing file to creating a new one.
- Distinctive: line 188
NEVER proactively create documentation files (\*.md) or README files.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
项目概述
Claude Relay Service — 多平台 AI API 中转服务,作为客户端与上游 AI API 之间的中间件。 支持 Claude (官方/Console)、Gemini、OpenAI Responses、AWS Bedrock、Azure OpenAI、Droid、CCR 等账户类型。 核心能力:多账户管理、API Key 认证、统一调度、代理配置、限流、成本统计。
架构原则
Clean Architecture 分层映射
| 层级 | 目录 | 职责 |
| 框架层 | src/routes/, src/middleware/ | HTTP 路由、请求验证、响应格式化 |
| 接口适配层 | src/handlers/, src/services/openaiToClaude.js | 请求/响应格式转换 |
| 用例层 | src/services/*Scheduler.js, *RelayService.js | 调度逻辑、转发编排 |
| 实体层 | src/services/*AccountService.js, src/models/ | 账户管理、数据模型 |
| 基础设施层 | src/utils/, config/ | 日志、缓存、加密、代理 |
开发原则
- 依赖方向: 外层 → 内层,内层不知道外层存在
- 新增路由: 只做参数提取和响应格式化,业务逻辑放 service
- 新增服务: 先确定属于哪一层,遵循该层职责边界
- 格式转换: 不同 API 格式的转换放 handlers 或专用转换服务
- 数据访问: 通过
src/models/redis.js统一访问
安全约束
- 敏感数据(OAuth token、refreshToken、credentials)必须 AES 加密存储(参考
claudeAccountService.js) - API Key 使用 SHA-256 哈希存储,禁止明文
- 每个请求必须经过完整认证链(API Key → 权限 → 客户端限制 → 模型黑名单)
- 客户端断开时必须通过 AbortController 清理资源和并发计数
- 日志中禁止输出完整 token,使用
tokenMask.js脱敏
项目结构
src/
├── routes/ # HTTP 路由
│ ├── api.js # Claude API 主路由
│ ├── admin/ # 管理后台路由(24个子文件)
│ ├── geminiRoutes.js, standardGeminiRoutes.js
│ ├── openaiRoutes.js, openaiClaudeRoutes.js, openaiGeminiRoutes.js
│ ├── azureOpenaiRoutes.js, droidRoutes.js
│ ├── userRoutes.js, webhook.js, unified.js, apiStats.js, web.js
├── middleware/ # auth.js(认证/权限/限流), browserFallback.js
├── handlers/ # geminiHandlers.js
├── services/ # 业务服务
│ ├── relay/ # 各平台转发服务(9个)
│ ├── account/ # 各平台账户管理(11个)
│ ├── scheduler/ # 统一调度器(4个)
│ ├── apiKeyService.js # API Key 管理
│ ├── pricingService.js # 定价和成本
│ └── ... # 其余 ~30 个业务服务
├── models/redis.js # Redis 数据模型
├── utils/ # 35+ 工具文件(logger, proxy, oauth, cache, stream...)
config/config.js # 主配置
scripts/ # 运维脚本
cli/ # CLI 工具
web/admin-spa/ # Vue SPA 管理界面
data/init.json # 管理员凭据核心请求流程
客户端(cr_前缀Key) → 路由 → auth中间件(验证/权限/限流/模型黑名单)
→ 统一调度器(选账户/粘性会话) → Token检查/刷新
→ 转发服务(通过代理发送) → 上游API
→ 流式/非流式响应 → Usage捕获 → 成本计算 → 返回客户端关键机制:
- 粘性会话: 基于请求内容 hash 绑定账户,同一会话用同一账户
- 并发控制: Redis Sorted Set 实现,支持排队等待(非直接 429)
- 529 处理: 自动标记过载账户,配置时长内排除
- 加密存储: 敏感数据(OAuth token、credentials)AES 加密存于 Redis
- 流式响应: SSE 传输,实时捕获 usage,客户端断开时 AbortController 清理资源
开发规范
代码风格
- 无分号、单引号、100字符行宽、尾逗号 none、箭头函数始终加括号
- 强制
const(no-var、prefer-const),严格相等(eqeqeq) - 下划线前缀变量
_var可豁免 unused 检查 - 必须使用 Prettier:
npx prettier --write <file> - 前端额外安装了
prettier-plugin-tailwindcss
开发工作流
- 理解现有代码 → 读相关文件,了解现有模式
- 编写代码 → 重用已有服务和工具函数
- 格式化 →
npx prettier --write <修改的文件> - 检查 →
npm run lint - 测试 →
npm test - 验证 →
npm run cli status确认服务正常
测试规范
- 测试文件在
tests/目录,命名*.test.js或*.spec.js - 使用
jest.mock()模拟依赖(logger、redis、services) beforeEach中jest.resetModules(),afterEach中jest.clearAllMocks()
前端要求
- 技术栈:Vue 3 Composition API + Pinia + Element Plus + Tailwind CSS
- 响应式设计:Tailwind CSS 响应式前缀(sm:、md:、lg:、xl:)
- 暗黑模式:所有组件必须兼容,使用
dark:前缀 - 主题切换:
web/admin-spa/src/stores/theme.js的useThemeStore() - 保持现有玻璃态设计风格
暗黑模式配色对照:
| 元素 | 明亮模式 | 暗黑模式 |
| 文本 | text-gray-700 | dark:text-gray-200 |
| 背景 | bg-white | dark:bg-gray-800 |
| 边框 | border-gray-200 | dark:border-gray-700 |
| 状态色 | text-blue-500 / text-green-600 / text-red-500 | 保持一致 |
代码修改原则
- 先检查现有模式和风格,重用已有服务和工具函数
- 敏感数据必须加密存储(参考 claudeAccountService.js)
- 遵循现有的错误处理和日志记录模式
常用命令
npm install && npm run setup # 初始化
npm run dev # 开发模式(nodemon 热重载,自动 lint)
npm start # 生产模式(先 lint 再启动)
npm run lint # ESLint 检查并自动修复
npm run lint:check # ESLint 仅检查不修复
npm run format # Prettier 格式化所有后端文件
npm run format:check # Prettier 仅检查格式
npm test # Jest 运行所有测试(tests/ 目录)
npm test -- <文件名> # 运行单个测试,如: npm test -- pricingService
npm test -- --coverage # 运行测试并生成覆盖率报告
npm run cli status # 系统状态
npm run data:export # 导出 Redis 数据
npm run data:debug # 调试 Redis 键前端命令
npm run install:web # 安装前端依赖
npm run build:web # 构建前端(生成 dist)
cd web/admin-spa && npm run dev # 前端开发模式(Vite HMR)环境变量(必须)
JWT_SECRET— JWT 密钥(32字符+)ENCRYPTION_KEY— AES 加密密钥(32字符固定)REDIS_HOST/REDIS_PORT/REDIS_PASSWORD— Redis 连接
其他可选环境变量见 .env.example。
故障排除
| 问题 | 排查方向 |
| Redis 连接失败 | 检查 REDIS_HOST/PORT/PASSWORD |
| 管理员登录失败 | 检查 data/init.json,运行 npm run setup |
| API Key 格式错误 | 确保使用 cr_ 前缀格式(可通过 API_KEY_PREFIX 配置) |
| Token 刷新失败 | 检查 refreshToken 有效性和代理配置,查看 logs/token-refresh-error.log |
| 调度器选账户失败 | 检查账户 status:'active',确认类型与路由匹配,查看粘性会话绑定 |
| 并发计数泄漏 | 系统每分钟自动清理,重启也会清理 |
| 粘性会话失效 | 检查 Redis 中 session 数据,Nginx 代理需添加 underscores_in_headers on |
| LDAP 认证失败 | 检查 LDAP_URL/BIND_DN/BIND_PASSWORD,自签名证书设 LDAP_TLS_REJECT_UNAUTHORIZED=false |
| Webhook 通知失败 | 确认 WEBHOOK_ENABLED=true,检查 WEBHOOK_URLS 格式,查看 logs/webhook-*.log |
| 成本统计不准确 | 运行 npm run init:costs,检查 pricingService 模型价格 |
日志:logs/ 目录。Web 界面 /admin-next/ 可实时查看。
important-instruction-reminders
Do what has been asked; nothing more, nothing less. NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one. NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

