fix: let saved provider profiles win on restart (#513)
Treat profile-managed env as restart state rather than explicit user intent so saved OpenAI-compatible profiles can replace stale Ollama values on startup and persist correctly across restarts. Co-authored-by: Claude Opus 4.6 <noreply@openclaude.dev>
This commit is contained in:
committed by
GitHub
parent
07621a6f8d
commit
cb8f8b7ac2
@@ -667,22 +667,39 @@ export async function buildStartupEnvFromProfile(options?: {
|
||||
readGeminiAccessToken?: () => string | undefined
|
||||
}): Promise<NodeJS.ProcessEnv> {
|
||||
const processEnv = options?.processEnv ?? process.env
|
||||
if (hasExplicitProviderSelection(processEnv)) {
|
||||
const persisted = options?.persisted ?? loadProfileFile()
|
||||
|
||||
// Saved /provider profiles should still win over provider-manager env that was
|
||||
// auto-applied during startup. Only explicit shell/flag provider selection
|
||||
// should bypass the persisted startup profile.
|
||||
const profileManagedEnv = processEnv.CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED === '1'
|
||||
if (hasExplicitProviderSelection(processEnv) && !profileManagedEnv) {
|
||||
return processEnv
|
||||
}
|
||||
|
||||
const persisted = options?.persisted ?? loadProfileFile()
|
||||
if (!persisted) {
|
||||
return processEnv
|
||||
}
|
||||
|
||||
const launchProcessEnv = profileManagedEnv
|
||||
? (() => {
|
||||
const cleanedEnv = { ...processEnv }
|
||||
for (const key of PROFILE_ENV_KEYS) {
|
||||
delete cleanedEnv[key]
|
||||
}
|
||||
delete cleanedEnv.CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED
|
||||
delete cleanedEnv.CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED_ID
|
||||
return cleanedEnv
|
||||
})()
|
||||
: processEnv
|
||||
|
||||
return buildLaunchEnv({
|
||||
profile: persisted.profile,
|
||||
persisted,
|
||||
goal:
|
||||
options?.goal ??
|
||||
normalizeRecommendationGoal(processEnv.OPENCLAUDE_PROFILE_GOAL),
|
||||
processEnv,
|
||||
processEnv: launchProcessEnv,
|
||||
getOllamaChatBaseUrl:
|
||||
options?.getOllamaChatBaseUrl ?? getOllamaChatBaseUrl,
|
||||
resolveOllamaDefaultModel: options?.resolveOllamaDefaultModel,
|
||||
|
||||
Reference in New Issue
Block a user