From b2cabdd950eeee5ed0f9c50d42f63e963e04201e Mon Sep 17 00:00:00 2001 From: gnanam1990 Date: Tue, 7 Apr 2026 18:47:35 +0530 Subject: [PATCH] fix: preserve explicit provider intent for active profiles --- src/utils/providerProfiles.test.ts | 24 ++++++++++++++++++++++++ src/utils/providerProfiles.ts | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/utils/providerProfiles.test.ts b/src/utils/providerProfiles.test.ts index 917f8dd6..4e06a038 100644 --- a/src/utils/providerProfiles.test.ts +++ b/src/utils/providerProfiles.test.ts @@ -9,6 +9,7 @@ async function importFreshProvidersModule() { const originalEnv = { ...process.env } const RESTORED_KEYS = [ + 'CLAUDE_CODE_EXPLICIT_PROVIDER', 'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED', 'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED_ID', 'CLAUDE_CODE_USE_OPENAI', @@ -142,6 +143,29 @@ describe('applyProviderProfileToProcessEnv', () => { }) describe('applyActiveProviderProfileFromConfig', () => { + test('does not override explicit anthropic startup selection', async () => { + const { applyActiveProviderProfileFromConfig } = + await importFreshProviderProfileModules() + process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'anthropic' + + const applied = applyActiveProviderProfileFromConfig({ + providerProfiles: [ + buildProfile({ + id: 'saved_github', + baseUrl: 'https://api.githubcopilot.com', + model: 'github:copilot', + }), + ], + activeProviderProfileId: 'saved_github', + } as any) + + expect(applied).toBeUndefined() + expect(process.env.CLAUDE_CODE_EXPLICIT_PROVIDER).toBe('anthropic') + expect(process.env.CLAUDE_CODE_USE_OPENAI).toBeUndefined() + expect(process.env.CLAUDE_CODE_USE_GITHUB).toBeUndefined() + expect(process.env.OPENAI_MODEL).toBeUndefined() + }) + test('does not override explicit startup provider selection', async () => { const { applyActiveProviderProfileFromConfig } = await importFreshProviderProfileModules() diff --git a/src/utils/providerProfiles.ts b/src/utils/providerProfiles.ts index 347e11b6..e5c32982 100644 --- a/src/utils/providerProfiles.ts +++ b/src/utils/providerProfiles.ts @@ -5,6 +5,7 @@ import { type ProviderProfile, } from './config.js' import type { ModelOption } from './model/modelOptions.js' +import { EXPLICIT_PROVIDER_ENV_VAR } from './providerEnvSelection.js' export type ProviderPreset = | 'anthropic' @@ -256,6 +257,7 @@ function hasProviderSelectionFlags( processEnv: NodeJS.ProcessEnv = process.env, ): boolean { return ( + processEnv[EXPLICIT_PROVIDER_ENV_VAR] !== undefined || processEnv.CLAUDE_CODE_USE_OPENAI !== undefined || processEnv.CLAUDE_CODE_USE_GEMINI !== undefined || processEnv.CLAUDE_CODE_USE_GITHUB !== undefined ||