@@ -1,3 +1,4 @@
1+import { isLoggedIn } from "../oauth/auth-storage.ts";
12 import {
23 listModelCapabilities,
34 listModelInfoState,
@@ -111,9 +112,16 @@ function hasAnyEnvKey(
111112 export function getRemoteProvidersFromEnv(
112113 env: Record<string, string | undefined>,
113114 ): string[] {
114- return REMOTE_PROVIDER_ENV_KEYS.filter((entry) =>
115+ const providers = REMOTE_PROVIDER_ENV_KEYS.filter((entry) =>
115116 hasAnyEnvKey(env, entry.envKeys),
116117 ).map((entry) => entry.provider);
118+
119+ // Include providers with OAuth login even without env keys
120+ if (!providers.includes("anthropic") && isLoggedIn("anthropic")) {
121+ providers.push("anthropic");
122+ }
123+
124+ return providers;
117125 }
118126
119127 export function getProvidersToRefreshFromEnv(
@@ -260,10 +268,30 @@ export function supportsThinking(modelString: string): boolean {
260268 return resolveModelInfo(modelString)?.reasoning ?? false;
261269 }
262270
271+function hasCachedModelsForAllVisibleProviders(): boolean {
272+ const visible = getVisibleProvidersForSnapshotFromEnv(process.env);
273+ for (const provider of visible) {
274+ let found = false;
275+ for (const row of runtimeCache.providerModelsByKey.values()) {
276+ if (row.provider === provider) {
277+ found = true;
278+ break;
279+ }
280+ }
281+ if (!found) return false;
282+ }
283+ return true;
284+}
285+
263286 export async function fetchAvailableModelsSnapshot(): Promise<AvailableModelsSnapshot> {
264287 ensureLoaded();
265288 if (isModelInfoStale() && !isModelInfoRefreshing()) {
266- if (runtimeCache.providerModelsByKey.size === 0) {
289+ // Block when the cache is empty or a visible provider has no cached models
290+ // (e.g. user just logged in via OAuth). Otherwise refresh in background.
291+ if (
292+ runtimeCache.providerModelsByKey.size === 0 ||
293+ !hasCachedModelsForAllVisibleProviders()
294+ ) {
267295 await refreshModelInfoInBackground({ force: true });
268296 } else {
269297 void refreshModelInfoInBackground();