From be5d05b60579a41f2099a1e980494bdfc04627be Mon Sep 17 00:00:00 2001 From: thedavidweng <95214375+thedavidweng@users.noreply.github.com> Date: Tue, 9 Jun 2026 22:12:20 +0000 Subject: [PATCH 1/2] fix(deeplink): preserve custom env fields when importing Claude providers When importing Claude providers through deeplinks, custom environment variables (e.g. ANTHROPIC_CUSTOM_HEADERS, proxy settings) were silently dropped because build_claude_settings constructed env from scratch with only known keys. - Add custom_env field to DeepLinkImportRequest to carry unknown env keys - In merge_claude_config, collect non-standard env keys into custom_env - In build_claude_settings, merge custom_env into the output env object Closes #261 --- src-tauri/src/deeplink/mod.rs | 4 ++++ src-tauri/src/deeplink/provider.rs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src-tauri/src/deeplink/mod.rs b/src-tauri/src/deeplink/mod.rs index 0b8afffe..e373010a 100644 --- a/src-tauri/src/deeplink/mod.rs +++ b/src-tauri/src/deeplink/mod.rs @@ -48,6 +48,10 @@ pub struct DeepLinkImportRequest { #[serde(skip_serializing_if = "Option::is_none")] pub opus_model: Option, + /// 自定义环境变量(从 inline config 的 env 对象中保留的非标准 key) + #[serde(skip_serializing_if = "Option::is_none")] + pub custom_env: Option>, + #[serde(skip_serializing_if = "Option::is_none")] pub content: Option, #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src-tauri/src/deeplink/provider.rs b/src-tauri/src/deeplink/provider.rs index 2f53392f..96e12bb2 100644 --- a/src-tauri/src/deeplink/provider.rs +++ b/src-tauri/src/deeplink/provider.rs @@ -256,6 +256,13 @@ fn build_claude_settings(request: &DeepLinkImportRequest) -> serde_json::Value { ); } + // 合并自定义环境变量 + if let Some(custom) = &request.custom_env { + for (key, value) in custom { + env.entry(key.clone()).or_insert(value.clone()); + } + } + json!({ "env": env }) } @@ -527,6 +534,24 @@ fn merge_claude_config( .map(|s| s.to_string()); } + // 保留非标准 env key(如 ANTHROPIC_CUSTOM_HEADERS 等自定义变量) + let known_keys: &[&str] = &[ + "ANTHROPIC_AUTH_TOKEN", + "ANTHROPIC_BASE_URL", + "ANTHROPIC_MODEL", + "ANTHROPIC_DEFAULT_HAIKU_MODEL", + "ANTHROPIC_DEFAULT_SONNET_MODEL", + "ANTHROPIC_DEFAULT_OPUS_MODEL", + ]; + let custom: serde_json::Map = env + .iter() + .filter(|(k, _)| !known_keys.contains(&k.as_str())) + .map(|(k, v)| (k.clone(), v.clone())) + .collect(); + if !custom.is_empty() { + request.custom_env = Some(custom); + } + Ok(()) } From 7b5e59da3f095361a911e9329df99e74a2bc9d94 Mon Sep 17 00:00:00 2001 From: Davy <95214375+thedavidweng@users.noreply.github.com> Date: Tue, 9 Jun 2026 19:32:34 -0700 Subject: [PATCH 2/2] fix: add missing custom_env field to DeepLinkImportRequest in parser The PR added custom_env to the struct definition and provider.rs usage but missed updating the parser constructor, causing a compile error. --- src-tauri/src/deeplink/parser.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src-tauri/src/deeplink/parser.rs b/src-tauri/src/deeplink/parser.rs index 79ab6c89..d6f59e7c 100644 --- a/src-tauri/src/deeplink/parser.rs +++ b/src-tauri/src/deeplink/parser.rs @@ -138,5 +138,6 @@ fn parse_provider_deeplink( .get("usageAutoInterval") .and_then(|v| v.parse::().ok()), openclaw_config: None, + custom_env: None, }) }