Cmc Proxy banner
cwf818 cwf818

Cmc Proxy

AI community

Description

Reverse-proxy a GOAT/commandcode AI subscription to localhost for Claude Code & Codex — OpenAI/Anthropic/Responses tri-protocol conversion, unified model routing, auto failover rotation & prefix-cache-friendly transforms. Zero-dependency single file (Node.js 18+).

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

cmc-proxy — commandcode GOAT 订阅本地反代网关

![version](https://img.shields.io/badge/version-v1.3.0-blue) ![stars](https://img.shields.io/github/stars/cwf818/cmc-proxy) ![issues](https://img.shields.io/github/issues/cwf818/cmc-proxy)

把 commandcode 的 Provider API 反代到本机 `127.0.0.1:5411`,让本地 **Claude Code** 和 **Codex** 直接接入你的 GOAT 订阅。大部分其他 Agent (Pi,zcode等)本身可以直连,无需此代理。当然加一层可以更智能些,比如图片请求可以**自动路由**,或上游失败时**自动切换**,还可以看到一些token用量、缓存命中的统计——我喜欢看 tps,快慢自知容易心里踏实。

  • 极简单文件 proxy.js,零第三方依赖,无需安装 npm 包,仅需 Node.js ≥ 18(内置 fetch/ReadableStream),node proxy.js 即可启动(都知道要反代了,想必node 早就配备了)。
  • 代码安全,不含任何后门或远程调用,所有请求仅在本机转发到 commandcode 上游;基本上是 AI 代写,使用前可以让 AI 再审查一遍。本身 AI 写一个不难,难的是如何避坑以及设计实用功能,github 找了一圈没找到合适的,所以自己让 AI 帮忙写了一个。遇到的坑包括:CC改历史、变换版本后缀、Codex只支持Responses、鬼知道什么时候配置了记忆生成导致token额外消耗等。反正这里暂时解决了。
  • 同时提供 OpenAI 兼容/v1/chat/completions)、Anthropic 兼容/v1/messages,供 Claude Code)与 Responses 兼容/v1/responses,供 Codex)三类端点;看上去 opencode-go 套餐也可以拿来改一下 EndPoint(upstreamapikey) 直接用,可能需要适应性修改,目前停了 ocgo 套餐,不去折腾了。
  • 协议转换:GOAT 订阅不含任何 Claude 模型,Claude Code 请求自动 Anthropic → OpenAI 转换;Codex 的 Responses 请求自动 Responses → Chat Completions 转换(上游只有 chat/completions);流式 + 工具调用全链路支持
  • 统一模型决策 pickModelmodelMap 显式映射 → 上游模型目录解析(resolveModel)→ 按请求类型回退默认(文本 defaultModels[0] / 带图 defaultVisionModels[0]
  • 失败轮换 switchOnFail(支持布尔或 {text, image}):失败 1 次即切换 + failTTL 冷却;文本请求按 defaultModels、带图请求按 defaultVisionModels 轮换(带图请求 400 也轮换,图片不支持的报错就是 400)
  • 多模态tool_result 内嵌图片抽出注入同轮 user 消息透传;cleanHistoryImages 可在本轮无新图时清理历史图片,让请求安全回流纯文本模型;REQ 行 img=N(新M) 标记 + 会话标签 @ 前缀
  • 前缀缓存优化:注入提醒剥离、易变计数器取整、cache_control 透传、会话缓存亲和——同会话 Claude Code / Codex 的上游前缀缓存可稳定在 95%+;RES 行内置前缀分叉探测(pfx~ 标记)可定位缓存失效来源
  • Codex 新协议全兼容custom(apply_patch freeform)/ tool_search(延迟工具发现)/ namespace 工具组 / 顶层 function_call 历史等新形态全链路支持
  • 会话级访问日志:按 x-claude-code-session-id / session-id / thread-id 稳定归因,两行日志(REQ/RES)配对 + 缓存命中率 / 生成速度 / 前缀分叉 / 累计用量统