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 <ali.alakbarli@users.noreply.github.com>
This commit is contained in:
@@ -259,6 +259,8 @@ describe('applyActiveProviderProfileFromConfig', () => {
|
|||||||
delete process.env.CLAUDE_CODE_USE_BEDROCK
|
delete process.env.CLAUDE_CODE_USE_BEDROCK
|
||||||
delete process.env.CLAUDE_CODE_USE_VERTEX
|
delete process.env.CLAUDE_CODE_USE_VERTEX
|
||||||
delete process.env.CLAUDE_CODE_USE_FOUNDRY
|
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_BASE_URL = 'http://localhost:11434/v1'
|
||||||
process.env.OPENAI_MODEL = 'qwen2.5:3b'
|
process.env.OPENAI_MODEL = 'qwen2.5:3b'
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ export function applyActiveProviderProfileFromConfig(
|
|||||||
processEnv[PROFILE_ENV_APPLIED_FLAG] === '1' &&
|
processEnv[PROFILE_ENV_APPLIED_FLAG] === '1' &&
|
||||||
trimOrUndefined(processEnv[PROFILE_ENV_APPLIED_ID]) === activeProfile.id
|
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
|
// Respect explicit startup provider intent. Auto-heal only when this
|
||||||
// exact active profile previously applied the current env.
|
// exact active profile previously applied the current env.
|
||||||
if (!isCurrentEnvProfileManaged) {
|
if (!isCurrentEnvProfileManaged) {
|
||||||
|
|||||||
Reference in New Issue
Block a user