Skip to content

Commit 403fd74

Browse files
鲁工鲁工
authored andcommitted
feat: auto-append [1m] to models with a 1M context window, v1.19.0
Claude Code clamps third-party models to ~200k behind a custom base URL and only opens the full window when the model name ends in [1m]. Users had to retype `deepseek-flash[1m]` on every launch and after every /model switch. The suffix is a client-side marker, never an upstream id: native Claude Code strips it before calling the API, and Kimi answers `k3[1m]` with 401 "model id does not exist". So it is generated at the two Claude-Code-facing exits and stripped at the entrance: - the four model slots injected by `ccmr claude` (ANTHROPIC_MODEL plus the SONNET/OPUS/HAIKU defaults) -- fixes "200k on launch" - the ids served by GET /v1/models -- fixes "200k again after /model" - ConfigManager.resolveModelName strips [1m] before alias resolution, so both `deepseek-flash` and `deepseek-flash[1m]` route, existing configs and scripts are unaffected, and upstream always receives the bare id Threshold is context_window >= 1000000 (vendors report 1M as either 1000000 or 1048576), which covers 27 of 42 variants. Models at 256k and below stay bare on purpose: a false [1m] would make Claude Code overrun the real window, which is worse than the original bug. Verified on a scratch gateway: 27 ids suffixed, 15 bare, and a POST with a suffixed name reaches upstream as the bare model id. Also adds the diagnosis note for the related report where WebSearch/WebFetch kept hitting an exhausted Kimi plan: those tools run on the haiku slot, which `/model` cannot retarget, so they stayed on the launch default.
1 parent cc0592e commit 403fd74

22 files changed

Lines changed: 258 additions & 22 deletions

‎README.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ ccmr claude --print --output-format json "你的问题"
172172
- `CLAUDE_CONFIG_DIR=~/.claude-gateway`
173173
- `ANTHROPIC_BASE_URL=http://127.0.0.1:<gateway-port>`
174174
- `ANTHROPIC_AUTH_TOKEN=ccmr-local-gateway`
175-
- `ANTHROPIC_MODEL` 和 Claude 默认模型变量会指向当前 `default_model`
176-
- `CLAUDE_CODE_AUTO_COMPACT_WINDOW` 会按启动模型的 `context_window` 自动注入(如 Seed/Kimi 256K、DeepSeek 1M),避免 Claude Code 把第三方模型默认裁剪到 ~200k。若你已自行设置该变量,则尊重你的值不覆盖。注意它是会话级全局:运行时用 `/model` 切到不同上下文窗口的模型时,请重启或用 `ccmr claude --model <模型>` 重新启动以匹配
175+
- `ANTHROPIC_MODEL` 和 Claude 默认模型变量会指向当前 `default_model`;若该模型的 `context_window` ≥ 1M,会自动带上 `[1m]` 后缀(如 `deepseek-flash[1m]`)。Claude Code 只有在模型名带这个后缀时才会真正开启 1M 上下文,并且会在请求发出前把后缀剥掉,因此不影响上游模型 ID
176+
- `CLAUDE_CODE_AUTO_COMPACT_WINDOW` 会按启动模型的 `context_window` 自动注入(如 Seed/Kimi 256K、DeepSeek 1M),避免 Claude Code 把第三方模型默认裁剪到 ~200k。若你已自行设置该变量,则尊重你的值不覆盖。注意它是会话级全局:运行时用 `/model` 切到**不同上下文窗口**的模型时,压缩阈值不会跟着变,需要重启或用 `ccmr claude --model <模型>` 重新启动以匹配(1M 模型之间互相切换不受影响)
177177

178178
这些变量只作用于 `ccmr claude` 启动的 Claude Code 子进程,不会修改你的官方 Claude Code 配置,也不会影响直接运行 `claude` 的官方订阅模式。
179179

@@ -543,6 +543,14 @@ DeepSeek Anthropic 兼容接口会忽略 `metadata` 字段,但某些 Claude Co
543543

544544
## 更新日志
545545

546+
### v1.19.0
547+
548+
- **1M 模型自动带 `[1m]` 后缀**:Claude Code 在自定义 base_url 后面默认按 ~200k 处理第三方模型,只有模型名以 `[1m]` 结尾时才会开启百万上下文——此前需要每次手动 `/model deepseek-flash[1m]`。现在两个出口都会自动补后缀:
549+
- `ccmr claude` 注入的 `ANTHROPIC_MODEL` / `ANTHROPIC_DEFAULT_SONNET_MODEL` / `..._OPUS_MODEL` / `..._HAIKU_MODEL`(解决"刚进界面就是 200K")
550+
- `GET /v1/models` 返回的模型 id(解决"用 `/model` 切换后又变回 200K")
551+
- **判定规则**:`context_window ≥ 1000000` 才加后缀,当前 42 个模型中 27 个符合(DeepSeek、Kimi K3、Qwen3.8、GLM-5.x、MiniMax M3、MiMo 等);256K 及以下的模型(Seed、Kimi K2.x、Step)保持裸名——给小窗口模型挂 `[1m]` 会让 Claude Code 超发上下文
552+
- **后缀只对客户端有意义**:网关在解析模型名时会先剥掉 `[1m]` 再查别名,上游收到的始终是裸模型 ID(Kimi 曾因 `k3[1m]` 报 401)。因此 `deepseek-flash` 和 `deepseek-flash[1m]` 都能正常路由,老配置、老脚本不受影响
553+
546554
### v1.18.0
547555

548556
- **DeepSeek V4.1 Flash 正式版接入**(官方 2026-09-10 发布公告 / [定价页](https://api-docs.deepseek.com/quick_start/pricing)):正式模型名 `deepseek-flash`,取代 09-08 的内测 id(`deepseek-v4.1-flash-expires-on-0910`,已过期)。552B MoE、Causal-Encoder-Decoder 非对称结构(输入激活 8B / 输出激活 16B)、原生多模态视觉理解,1M 上下文、最大输出 384K。实测:文本 200(0.62s);base64 image block 真实进入上下文(8×8 纯蓝图正确答 "Blue",input_tokens 227)

‎dist/cli.js‎

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/cli.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/config.d.ts.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/config.js‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/config.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/model-suffix.d.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* The "[1m]" model-name suffix.
3+
*
4+
* Claude Code opens its 1M context window only when the model name it was
5+
* given carries this suffix, and it strips the suffix before calling the API.
6+
* The suffix is therefore a client-side marker: it never belongs in an
7+
* upstream model id (Kimi answers `k3[1m]` with 401 "model id does not
8+
* exist"), and the gateway must be able to take it back off again.
9+
*/
10+
/** Remove a trailing "[1m]" so the name can be resolved as a model or alias. */
11+
export declare function stripContextSuffix(name: string): string;
12+
/**
13+
* Add "[1m]" when the model's context window is at least 1M, so Claude Code
14+
* uses the full window instead of assuming ~200k. Already-suffixed and
15+
* smaller-window names are returned unchanged.
16+
*/
17+
export declare function withContextSuffix(name: string, contextWindow?: number): string;
18+
//# sourceMappingURL=model-suffix.d.ts.map

‎dist/model-suffix.d.ts.map‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/model-suffix.js‎

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/model-suffix.js.map‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)