Catalog npm
Back to packageRELEASE DETAILS

0.2.2

npm

3router

本地 Claude Code API 智能路由代理 —— 按消息内容将请求路由到不同上游/模型,支持规则引擎、多上游、系统守护进程与 Web 管理面板。

anthropicapi-proxyclaude-codellmproxyroutertypescript
Published20 Jun 2026
Direct dependencies11
Transitive dependenciesNot calculated

README

Current package documentation

3router

本地 Claude Code API 智能路由代理 —— 一套配置、按消息内容智能分流,把请求路由到最合适的上游/模型。

在本地(http://localhost:9191)启动一个兼容 Anthropic API 的代理,根据请求内容(是否含图片、文本等)匹配路由规则,将请求分发到不同上游服务和模型。在 Claude Code 中只需把 ANTHROPIC_BASE_URL 指向它即可无缝接入。

✨ 特性

  • 智能路由 — 按消息内容(has_image 含图片 / default 默认)与优先级匹配规则,将请求路由到不同上游/模型
  • 多上游支持 — 统一管理 Anthropic 官方、阿里百炼等多个上游,按场景灵活分流
  • 规则引擎 — 优先级 + 条件匹配,声明式定义路由策略
  • 系统守护进程 — start / stop / status 一键管理,支持 macOS(launchctl)与 Linux(systemd)开机自启
  • Web 管理面板 — 可视化配置上游、规则与模型(生产与后端同源 9191)
  • 流式透传 — 原生支持 SSE 流式响应(Bun.serve 原生 web stream,不阻塞 Claude Code 实时输出)
  • 图片上下文保留 — 智能缓存图片内容,避免多轮对话丢失视觉上下文
  • 零依赖二进制 — bun build --compile 产出独立可执行文件,无需 Node/Bun 运行时

安装

npm 全局安装(推荐)

npm install -g 3router

安装时按当前平台(os + cpu)自动只装一个预编译二进制(macOS / Linux / Windows × arm64/x64),底层走 @3router/<platform> 平台子包。

直接下载二进制

从 GitHub Releases 下载对应平台的 3router-<platform>.tar.gz(或 .zip),解压后放到 PATH 即可。

快速开始

3router            # 启动代理(首次运行自动生成 ~/.3router/config.json)

编辑 ~/.3router/config.json 填入上游 API 密钥,然后在 Claude Code 中设置 ANTHROPIC_BASE_URL=http://localhost:9191。

💡 可用 THREEROUTER_HOME 环境变量自定义配置目录;开机自启见 系统服务。

路由规则

  • has_image:包含图片内容块的消息
  • default:其他所有消息(纯文本、助手消息)

规则按优先级匹配(数字越小,优先级越高)。

系统服务(守护进程)

安装后可直接使用 3router 命令管理本地服务(仅 macOS / Linux):

命令说明
3router serve前台启动代理服务器(默认)
3router start注册并启动为系统服务(macOS 走 launchctl,Linux 走 systemd),开机自启
3router stop停止系统服务
3router status查看服务运行状态

💡 开机自启后,Claude Code 随时可用,无需手动保持终端运行。

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 11

Native requirements
11 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
consola
Environment
{
  "local_name": "consola",
  "alias": false,
  "peer_metadata": null
}
^3.4.2runtime
oxfmt
Environment
{
  "local_name": "oxfmt",
  "alias": false,
  "peer_metadata": null
}
^0.53.0development
oxlint
Environment
{
  "local_name": "oxlint",
  "alias": false,
  "peer_metadata": null
}
^1.68.0development
bun-types
Environment
{
  "local_name": "bun-types",
  "alias": false,
  "peer_metadata": null
}
^1.3.14development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^6.0.3development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^22.0.0development
@3router/linux-x64
Environment
{
  "local_name": "@3router/linux-x64",
  "alias": false,
  "peer_metadata": null
}
^0.2.2optional
@3router/win32-x64
Environment
{
  "local_name": "@3router/win32-x64",
  "alias": false,
  "peer_metadata": null
}
^0.2.2optional
@3router/darwin-x64
Environment
{
  "local_name": "@3router/darwin-x64",
  "alias": false,
  "peer_metadata": null
}
^0.2.2optional
@3router/linux-arm64
Environment
{
  "local_name": "@3router/linux-arm64",
  "alias": false,
  "peer_metadata": null
}
^0.2.2optional
@3router/darwin-arm64
Environment
{
  "local_name": "@3router/darwin-arm64",
  "alias": false,
  "peer_metadata": null
}
^0.2.2optional

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "9bfbee5345b54d02fda66131fc8ebcafc80cf182",
  "tarball": "https://registry.npmjs.org/3router/-/3router-0.2.2.tgz",
  "fileCount": 6,
  "integrity": "sha512-fXubFMCqqkgw6qvIPH637G9to4gyPbLoyRAep5fPyjS2dKX59WBRNKnbC32iB1dehaEJqzHMP6AN2X3wRyDhkQ==",
  "signatures": [
    {
      "sig": "MEYCIQDjb9xSdOoYsRnFHxIFvy2NcFQOYq6k9ahC6Doq0Z5aywIhAPT8FkfCy4XWfaFpmw8nmXxRLjWcqER8GkHWVHjNkpDj",
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
    }
  ],
  "unpackedSize": 8458
}

Repository

PENDING
jonny-china/3router

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:52 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:ffd47acf05db2670d4db1ca019d8ebdf308297d7c99568bef78e9f313aa69d4b

Other collected versions

0.2.522 Jun0.2.421 Jun0.2.320 Jun0.2.119 Jun0.2.018 JunView all collected versions →