diff --git a/packages/cli/src/zed-integration/zedIntegration.ts b/packages/cli/src/zed-integration/zedIntegration.ts index c95402c7b8..cd0cb4789a 100644 --- a/packages/cli/src/zed-integration/zedIntegration.ts +++ b/packages/cli/src/zed-integration/zedIntegration.ts @@ -113,8 +113,16 @@ export class GeminiAgent { async authenticate({ methodId }: acp.AuthenticateRequest): Promise { const method = z.nativeEnum(AuthType).parse(methodId); + const selectedAuthType = this.settings.merged.security?.auth?.selectedType; - await clearCachedCredentialFile(); + // Only clear credentials when switching to a different auth method + if (selectedAuthType && selectedAuthType !== method) { + await clearCachedCredentialFile(); + } + + // Refresh auth with the requested method + // This will reuse existing credentials if they're valid, + // or perform new authentication if needed await this.config.refreshAuth(method); this.settings.setValue( SettingScope.User,