Skip to content

fix(deeplink): custom env fields lost when importing Claude providers #261

@thedavidweng

Description

@thedavidweng

Problem

When importing Claude providers through deeplinks (ccswitch://v1/import?...), custom environment variables are silently dropped. Only the hardcoded known keys (ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL, and the four model keys) are preserved.

Root Cause

Two functions in src-tauri/src/deeplink/provider.rs cause the loss:

  1. build_claude_settings (line ~226): Constructs a brand-new empty serde_json::Map and only inserts known keys. Any user-defined env fields such as ANTHROPIC_CUSTOM_HEADERS, custom proxy variables, or other provider-specific settings are never included.

  2. merge_claude_config (line ~473): When an inline config is provided via the deeplink, this function reads the env object but only extracts the hardcoded known keys into the DeepLinkImportRequest. Custom env fields are discarded before build_claude_settings even runs.

Contrast with CLI/TUI Path

The CLI/TUI provider creation function build_claude_settings_config_from_prompt (in src/cli/commands/provider_input.rs, line ~3734) handles this correctly by cloning the existing settings as the base and only mutating known keys, so all sibling keys in env survive. Tests at lines 1355-1378 confirm that EXTRA_ENV is preserved.

Expected Behavior

The deeplink import path should preserve all existing environment fields from the source config, matching the behavior of the CLI/TUI provider creation flow. Unknown/custom env keys should be carried through untouched.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions