From cf567ca6485cc2753ae92ec86643a966b86b5a67 Mon Sep 17 00:00:00 2001 From: Sailing Loong Date: Tue, 6 Oct 2026 09:06:09 +0800 Subject: [PATCH] fix(claude): project CLAUDE_CODE_AUTO_MODE_SERVER from provider env into settings.json (#7893) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude Code 2.1.281 added a server-side auto mode classifier that only works on official endpoints. Sessions routed through a gateway (or the built-in proxy) get a blocking notice unless CLAUDE_CODE_AUTO_MODE_SERVER is set to 0 — the officially documented compatibility option for proxies and gateways. Providers carry that key in their env row, but the live projection only writes floor (connection/auth/model) and exclusive (compat switch) keys, so it never reached settings.json and the notice kept coming back after every switch. Classify it as a provider-exclusive env key: it is written on switch-in and removed on switch-out only when the value is unchanged, so users can still set it globally on their own. The frontend preset-scan mirror (tests/config/claudeKeyFields.json) is updated in lockstep; the mirror test keeps both sides honest. Fixes #7891 --- src-tauri/src/live/floor.rs | 3 +++ src-tauri/src/live/project/claude.rs | 30 ++++++++++++++++++++++++++++ tests/config/claudeKeyFields.json | 1 + 3 files changed, 34 insertions(+) diff --git a/src-tauri/src/live/floor.rs b/src-tauri/src/live/floor.rs index cee489d4c..04baabf9b 100644 --- a/src-tauri/src/live/floor.rs +++ b/src-tauri/src/live/floor.rs @@ -98,6 +98,9 @@ pub const CLAUDE_EXCLUSIVE_ENV: &[&str] = &[ "CLAUDE_CODE_ALWAYS_ENABLE_EFFORT", "CLAUDE_CODE_EXTRA_BODY", "CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING", + // auto mode 的服务端分类器只有官方端点支持;网关场景要设 0,否则会话被 + // 阻断式提示卡住(官方文档给代理、网关的兼容选项)。 + "CLAUDE_CODE_AUTO_MODE_SERVER", // 窗口类:取值由上游模型的窗口决定。 "CLAUDE_CODE_MAX_CONTEXT_TOKENS", "CLAUDE_CODE_AUTO_COMPACT_WINDOW", diff --git a/src-tauri/src/live/project/claude.rs b/src-tauri/src/live/project/claude.rs index 3eff9f569..48e6ea6a4 100644 --- a/src-tauri/src/live/project/claude.rs +++ b/src-tauri/src/live/project/claude.rs @@ -568,6 +568,36 @@ mod tests { ); } + #[test] + fn gateway_compat_switches_reach_settings_json() { + // 回归:auto mode 的服务端分类器只有官方端点支持,网关场景的供应商行要带 + // `CLAUDE_CODE_AUTO_MODE_SERVER=0`(官方文档给代理、网关的兼容选项)。 + // 它此前不在独有字段清单里,行里写了也到不了 settings.json。 + let gateway = json!({ "env": { + "ANTHROPIC_BASE_URL": "https://gw.example", + "ANTHROPIC_AUTH_TOKEN": "sk-gw", + "CLAUDE_CODE_AUTO_MODE_SERVER": "0" + }}); + let live = json!({ "env": { + "ANTHROPIC_BASE_URL": "https://kimi.example", + "ANTHROPIC_AUTH_TOKEN": "sk-kimi" + }}); + let out = project(&live, Some(&kimi()), &gateway); + assert_eq!(out["env"]["CLAUDE_CODE_AUTO_MODE_SERVER"], json!("0")); + + // 切回不带它的官方端点:值没被改过,跟着上一家走。 + let live = json!({ "env": { + "ANTHROPIC_BASE_URL": "https://gw.example", + "ANTHROPIC_AUTH_TOKEN": "sk-gw", + "CLAUDE_CODE_AUTO_MODE_SERVER": "0" + }}); + let official = json!({ "env": { "ANTHROPIC_AUTH_TOKEN": "sk-official" } }); + assert_eq!( + project(&live, Some(&gateway), &official)["env"].get("CLAUDE_CODE_AUTO_MODE_SERVER"), + None + ); + } + #[test] fn residue_goes_but_the_targets_own_value_stays_in_place() { // 旧版给 Kimi 注入的 262144,上一家行里没有:残留清理兜住。 diff --git a/tests/config/claudeKeyFields.json b/tests/config/claudeKeyFields.json index 392240ca1..15afe94d5 100644 --- a/tests/config/claudeKeyFields.json +++ b/tests/config/claudeKeyFields.json @@ -44,6 +44,7 @@ "CLAUDE_CODE_ALWAYS_ENABLE_EFFORT", "CLAUDE_CODE_EXTRA_BODY", "CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING", + "CLAUDE_CODE_AUTO_MODE_SERVER", "CLAUDE_CODE_MAX_CONTEXT_TOKENS", "CLAUDE_CODE_AUTO_COMPACT_WINDOW", "CLAUDE_CODE_MAX_OUTPUT_TOKENS",