AIFeed

Show HN:Subagents-MCP – 在 claude.ai 中使用 Gemini 和 Codex 订阅($0 API)

Translation(model translation, not the source's own text)

subagents-mcp

题图
题图

将你现有的 Google(Gemini)、ChatGPT(Codex)和 Claude 订阅作为可选代理,在 Claude Code 和 claude.ai 中使用——API 账单为 $0,且无需任何 API 代理。

当你已经为每月 AI 订阅付费时,按 token 计费的 API 代理很快就会变得昂贵。subagents-mcp 出自 deepclaude(★2,200+)的作者之手,它通过标准 Model Context Protocol(MCP)暴露你本地已登录的订阅 CLI(agy、codex、claude),让你可以并排选择和向 Gemini、Codex、Claude 发消息,并支持多轮会话恢复。

deepclaude 与 subagents-mcp 对比

deepclaudesubagents-mcp
计费按 token 计费的 API 密钥(DeepSeek / OpenRouter)$0 API 账单——使用你现有的 Google、ChatGPT 和 Claude 订阅
模型兼容 Anthropic 的 API 后端Gemini( agy )、Codex( codex )和 Claude( claude )并排使用
可在 claude.ai 网页版和移动端使用?否(CLI 代理)是——内置单所有者 OAuth 2.1 MCP 自定义连接器
可在 Claude Code 中使用?是( ANTHROPIC_BASE_URL )是——stdio MCP + /agents 预设 + 本地 CLI --proxy
API 密钥泄露防护需要 API 密钥在启动前硬性剥离每个 *_API_KEY 和 GOOGLE_APPLICATION_CREDENTIALS

工作原理


        Claude Code / Cursor / Antigravity / claude.ai (MCP client)
        │  MCP (stdio or Streamable HTTP)
        ▼
  subagents-mcp  (list_agents / send_to_agent / get_reply)
        │  strips EVERY *_API_KEY & GOOGLE_APPLICATION_CREDENTIALS
        │  runs inside an isolated empty 0700 directory
        ├──► agy    (Google AI subscription — Gemini models, all tool actions denied)
        ├──► codex  (ChatGPT subscription — read-only sandbox)
        └──► claude (Claude subscription — read-only plan mode)
      

硬性安全与成本保证

  • 从构造上保证 $0 API 账单:在启动任何 CLI 之前,每个 *_API_KEY 环境变量(GEMINI_API_KEY、GOOGLE_API_KEY、OPENAI_API_KEY、ANTHROPIC_API_KEY、OPENROUTER_API_KEY 等)和 GOOGLE_APPLICATION_CREDENTIALS 都会被剥离。如果你未登录订阅,CLI 会报告这一点,而不是静默地按 API 密钥计费。
  • 不修改工作区:所有运行器都在一个隔离的空 0700 目录(~/.local/state/subagents-mcp/sandbox-cwd)中执行,如果该目录非空,启动时会大声报错。
  • 硬性工具锁定:agy 以仅会话级 --settings 运行,将 toolPermission 固定为 "request-review",并拒绝全部 7 个通配符权限类别(command()、write_file()、read_file()、mcp()、execute_url()、download_url()、read_url(*))。codex 以 --sandbox read-only 运行(恢复时使用 -c sandbox_mode="read-only")。claude 以 --permission-mode plan 运行。
  • agy 以仅会话级 --settings 运行,将 toolPermission 固定为 "request-review",并拒绝全部 7 个通配符权限类别(command()、write_file()、read_file()、mcp()、execute_url()、download_url()、read_url(*))。
  • codex 以 --sandbox read-only 运行(恢复时使用 -c sandbox_mode="read-only")。
  • claude 以 --permission-mode plan 运行。
  • 多轮上下文:将 conversation_id 传回 send_to_agent 会恢复底层 CLI 会话(--conversation、codex exec resume、--resume)。

前置条件

安装并登录(通过订阅登录,无需 API 密钥)你想要使用的 CLI——任何缺失的 CLI 都会在启动时被干净地跳过:

  • Gemini(Google AI 订阅):Antigravity CLI(agy)——运行一次 agy 登录,用 agy models 验证。
  • Codex(ChatGPT 订阅):OpenAI Codex CLI(codex)——运行 codex login。
  • Claude(Claude 订阅):Claude Code CLI(claude)——运行 claude auth login。

快速开始


        git clone https://github.com/aattaran/subagents-mcp.git
cd subagents-mcp
npm install

# Check which subscription agents are detected on this machine
node src/cli.js --list
      

文章标题:Show HN: Subagents-MCP – 在 claude.ai 中使用 Gemini 和 Codex 订阅($0 API)

正文:

1. 在 Claude Code 中使用(stdio MCP + /agents)

注册一次 MCP 服务器:


        claude mcp add subagents -- node /absolute/path/to/subagents-mcp/src/cli.js
      

可选——复制捆绑的 subagent 预设,使 gemini 和 codex 直接出现在 Claude Code 的 /agents 选择器中:


        mkdir -p ~/.claude/agents
cp claude-agents/*.md ~/.claude/agents/
      

2. 直接连接 claude.ai(Web、桌面端和移动端——内置 OAuth 2.1)

claude.ai Custom Connectors 需要基于 HTTPS 的 OAuth 2.1。subagents-mcp 内置了单所有者 OAuth 2.1 服务器(Dynamic Client Registration、PKCE、scrypt 所有者口令同意、refresh token 轮换以及暴力破解锁定)。

第 1 步——一次性设置你的所有者口令:


        node src/cli.js --set-passphrase
      

第 2 步——通过 HTTPS 暴露 localhost(例如 Cloudflare Tunnel):


        cloudflared tunnel --url http://127.0.0.1:3456
# Copy the https://<your-tunnel-url> printed by cloudflared
      

(如需永久主机名,请使用指向 http://127.0.0.1:3456 的命名 Cloudflare Tunnel。)

第 3 步——以 OAuth 2.1 模式启动 subagents-mcp:


        node src/cli.js --http --port 3456 --public-url https://<your-tunnel-url>
      

第 4 步——在 claude.ai 中添加 Custom Connector:

  • 在 claude.ai 中,前往 Settings → Connectors → Add custom connector。
  • 输入你的 MCP URL:https://<your-tunnel-url>/mcp。
  • 点击 Connect → 在同意页面输入你的所有者口令 → 点击 Allow。
  • 在任何 claude.ai 聊天中(web、桌面端或移动端),启用该连接器并说“List my agents”或“Ask gemini-4-neon-high to ...”。

3. 本地 Claude Code CLI 槽位代理(--proxy)

想把本地 Claude Code CLI(/model 或 --model)中未使用的旧槽位(Opus 5、Sonnet 5、Haiku 4.5)路由到由订阅支持的 Gemini 4 Neon、Gemini 4 Carbon 或 Codex,API 计费为 $0,同时让 Opus 5.5 / Sonnet 5.5 / Haiku 5.5 继续使用 Anthropic?

第 1 步——启动本地订阅 CLI 代理:


        npm run proxy
# Listening on http://127.0.0.1:3457:
#   Opus 5 / Opus 4.7 -> gemini:gemini-4-neon-high (Gemini 4 Neon)
#   Sonnet 5          -> gemini:gemini-4-carbon-high (Gemini 4 Carbon)
#   Haiku 4.5         -> codex:codex (Codex)
#   All other models  -> https://api.anthropic.com (pass-through)
      

第 2 步——启动指向该代理的本地 Claude Code:


        ANTHROPIC_BASE_URL=http://127.0.0.1:3457 claude --model claude-opus-5
      
在 claude.ai/code(claude remote-control)上测得的限制:只要 ANTHROPIC_BASE_URL 不指向 api.anthropic.com,Claude Code 2.1.331+ 就会明确拒绝 claude remote-control(“Remote Control is only available when using Claude via api.anthropic.com”)。因此 --proxy 路径适用于本地 Claude Code CLI / 终端会话,而 claude.ai web/移动端应使用第 2 节(内置 OAuth 2.1 MCP Custom Connector)。注意:映射的槽位会实时流式传输来自 agy / codex 的文本/推理回复(只读/工具锁定,$0 API 成本);当你需要原生 Claude Code 文件/shell 工具执行时,请切回 Opus 5.5 / Sonnet 5.5。随附一个可选的配套用户脚本(browser/claude-ai-relabel.user.js)供参考。

在 claude.ai/code(claude remote-control)上测得的限制:只要 ANTHROPIC_BASE_URL 不指向 api.anthropic.com,Claude Code 2.1.331+ 就会明确拒绝 claude remote-control(“Remote Control is only available when using Claude via api.anthropic.com”)。因此 --proxy 路径适用于本地 Claude Code CLI / 终端会话,而 claude.ai web/移动端应使用第 2 节(内置 OAuth 2.1 MCP Custom Connector)。

注意:映射的槽位会实时流式传输来自 agy / codex 的文本/推理回复(只读/工具锁定,$0 API 成本);当你需要原生 Claude Code 文件/shell 工具执行时,请切回 Opus 5.5 / Sonnet 5.5。随附一个可选的配套用户脚本(browser/claude-ai-relabel.user.js)供参考。

4. 静态 Bearer Token HTTP 模式(非 OAuth MCP 客户端)


        export SUBAGENTS_TOKEN="$(openssl rand -hex 32)"
node src/cli.js --http --port 3456
      

文章标题:Show HN: Subagents-MCP – Gemini 和 Codex 订阅在 claude.ai 中使用($0 API)

正文: 默认绑定到 127.0.0.1:3456,并要求在 /mcp 上携带 Authorization: Bearer <token>(恒定时间校验)。

MCP 工具

工具描述
list_agents列出每一个已发现的订阅 agent( id , provider , label , busy )。
send_to_agent启动或继续一段对话( agent , message ,可选的 conversation_id )。立即返回 conversation_id,因此长回合永远不会让 MCP 调用超时。
get_reply长轮询(每次调用最多 25 秒)获取比 after 更新的回复,并返回 { status, replies } 。

开发与测试


        # 快速宿主测试套件(伪造 CLI,无网络)
npm test

# 完整的隔离 Docker 测试运行(--network=none,非 root 用户,实时 proxy/OAuth CLI 冒烟测试)
npm run test:isolated
      

运行 Node 内置测试运行器(node --test),覆盖环境净化、子进程运行器(验证环境变量剥离、argv 锁定、多字节 UTF-8 分片流式传输、被拒工具以及多轮恢复)、单所有者 OAuth 2.1 + PKCE、本地 /v1/messages 代理流式传输 + 透传,以及端到端 stdio + Streamable HTTP MCP 流程。

订阅条款说明:在通过自定义设置或 UI 驱动任何订阅 CLI 之前,请核实你的使用方式符合提供商当前的订阅服务条款。切勿将付费 API 密钥放入此工具的环境中。

许可证

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗