From 03e0b06e0784e4ea46945b3950840b10b6e3ca49 Mon Sep 17 00:00:00 2001 From: emsanakhchivan Date: Mon, 13 Apr 2026 16:22:50 +0400 Subject: [PATCH] fix: extend provider guard to protect anthropic profiles from cross-terminal override (#641) The provider profile activation guard in applyActiveProviderProfileFromConfig() only checked CLAUDE_CODE_USE_* environment flags, which are never set for the default anthropic provider. This allowed two terminals sharing ~/.claude.json to overwrite each other's active provider when one was using anthropic and the other a third-party provider. Now also checks the OCODE_PROVIDER_PROFILE_APPLIED flag, which is set by all profiles including anthropic, preventing cross-terminal interference. Co-authored-by: Ali Alakbarli --- src/utils/providerProfiles.test.ts | 2 ++ src/utils/providerProfiles.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/providerProfiles.test.ts b/src/utils/providerProfiles.test.ts index 917f8dd6..e1222ec7 100644 --- a/src/utils/providerProfiles.test.ts +++ b/src/utils/providerProfiles.test.ts @@ -259,6 +259,8 @@ describe('applyActiveProviderProfileFromConfig', () => { delete process.env.CLAUDE_CODE_USE_BEDROCK delete process.env.CLAUDE_CODE_USE_VERTEX delete process.env.CLAUDE_CODE_USE_FOUNDRY + delete process.env.CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED + delete process.env.CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED_ID process.env.OPENAI_BASE_URL = 'http://localhost:11434/v1' process.env.OPENAI_MODEL = 'qwen2.5:3b' diff --git a/src/utils/providerProfiles.ts b/src/utils/providerProfiles.ts index c928e620..b8ba3edf 100644 --- a/src/utils/providerProfiles.ts +++ b/src/utils/providerProfiles.ts @@ -417,7 +417,7 @@ export function applyActiveProviderProfileFromConfig( processEnv[PROFILE_ENV_APPLIED_FLAG] === '1' && trimOrUndefined(processEnv[PROFILE_ENV_APPLIED_ID]) === activeProfile.id - if (!options?.force && hasProviderSelectionFlags(processEnv)) { + if (!options?.force && (hasProviderSelectionFlags(processEnv) || processEnv[PROFILE_ENV_APPLIED_FLAG] === '1')) { // Respect explicit startup provider intent. Auto-heal only when this // exact active profile previously applied the current env. if (!isCurrentEnvProfileManaged) {