CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

Bug: Provider config overridden by environment variable when switching profiles

Open Artenx opened this issue 6 months ago • 0 comments

Bug Description

When using the /profile command to switch configuration profiles, even if the profile correctly configures provider = "openrouter" (or any non-deepseek provider), the provider displayed after switching remains deepseek instead of the provider configured in the profile.

Steps to Reproduce

  1. Configure a profile in config.toml:
[profiles.google]
provider = "openrouter"
default_text_model = "deepseek-v4-pro"
  1. Start codewhale (default uses deepseek provider)
  2. Use /profile google command to switch to google profile
  3. Observe the system message shows: Provider: deepseek, it should be openrouter

Root Cause Analysis

In crates/cli/src/lib.rs line 1432, when starting up, the CLI sets the DEEPSEEK_PROVIDER environment variable. When switching profiles, the apply_env_overrides function reads this environment variable and overrides the provider configured in the profile.

fn apply_env_overrides(config: &mut Config) {
    if let Ok(value) = std::env::var("DEEPSEEK_PROVIDER") {
        config.provider = Some(value);  // This overrides the profile configuration!
    }
}

Expected Behavior

After switching profiles, the provider configured in the profile should be displayed, not overridden by the environment variable set at startup.

Artenx avatar May 25 '26 08:05 Artenx