Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(tui): run gcloud ADC login from the Vertex row's l key

Jack Rudenko94f5f3358002
diff --git a/packages/cli/src/auth/credentials/vertex-credential.ts b/packages/cli/src/auth/credentials/vertex-credential.ts
index 9441d8b2..462bfeef 100644
--- a/packages/cli/src/auth/credentials/vertex-credential.ts
+++ b/packages/cli/src/auth/credentials/vertex-credential.ts
@@ -12,6 +12,8 @@
import {
getVertexAuthManager,
+ resetVertexAuthManager,
+ resetVertexProjectDiscovery,
resolveVertexConfig,
selectVertexAuthMode,
validateVertexOAuthConfig,
@@ -26,6 +28,11 @@ export class VertexCredentialProvider implements CredentialProvider {
return selectVertexAuthMode({ project: config?.projectId }) !== null;
}
+ invalidate(): void {
+ resetVertexAuthManager();
+ resetVertexProjectDiscovery();
+ }
+
async getRequestAuth(_ctx: RequestAuthContext): Promise<RequestAuth> {
const config = await resolveVertexConfig();
if (selectVertexAuthMode({ project: config?.projectId }) === "project") {
diff --git a/packages/cli/src/auth/vertex-access-denied.test.ts b/packages/cli/src/auth/vertex-access-denied.test.ts
index e0f12d74..64cba939 100644
--- a/packages/cli/src/auth/vertex-access-denied.test.ts
+++ b/packages/cli/src/auth/vertex-access-denied.test.ts
@@ -1,5 +1,6 @@
// REGRESSION: Vertex config TUI showed oauth but offered only "set key" and an unexplained 403 — Fixed in /dev:fix session dev-fix-20261020-235500-vtx01
-import { describe, expect, test } from "bun:test";
+import { afterEach, describe, expect, test } from "bun:test";
+import { credentials } from "./credentials/authority.js";
import * as vertexAuth from "./vertex-auth.js";
const projectId = "vertex-test-project";
@@ -54,3 +55,31 @@ describe("Vertex access-denied explanation", () => {
}
}
});
+
+describe.serial("Vertex authentication cache reset", () => {
+ afterEach(() => {
+ vertexAuth.resetVertexAuthManager?.();
+ vertexAuth.resetVertexProjectDiscovery();
+ });
+
+ test("resetVertexAuthManager replaces the shared authentication manager", () => {
+ const previous = vertexAuth.getVertexAuthManager();
+ expect(vertexAuth.getVertexAuthManager()).toBe(previous);
+
+ vertexAuth.resetVertexAuthManager();
+
+ const current = vertexAuth.getVertexAuthManager();
+ expect(current).not.toBe(previous);
+ expect(vertexAuth.getVertexAuthManager()).toBe(current);
+ });
+
+ test('credentials.invalidate("vertex") replaces the shared authentication manager', () => {
+ const previous = vertexAuth.getVertexAuthManager();
+
+ credentials.invalidate("vertex");
+
+ const current = vertexAuth.getVertexAuthManager();
+ expect(current).not.toBe(previous);
+ expect(vertexAuth.getVertexAuthManager()).toBe(current);
+ });
+});
diff --git a/packages/cli/src/auth/vertex-auth.ts b/packages/cli/src/auth/vertex-auth.ts
index fa28e847..53e7a1e7 100644
--- a/packages/cli/src/auth/vertex-auth.ts
+++ b/packages/cli/src/auth/vertex-auth.ts
@@ -249,7 +249,7 @@ let discoveredProjectSettled: VertexProjectOrigin | null | undefined;
let syncAdcOrigin: VertexProjectOrigin | null | undefined;
/**
- * Reset the discovery memos. Test seam — production resolves once per process.
+ * Reset the discovery memos, including when credentials.invalidate("vertex") runs after ADC login.
*/
export function resetVertexProjectDiscovery(): void {
discoveredProjectPromise = null;
@@ -642,6 +642,11 @@ export function buildVertexOAuthEndpoint(
// Singleton instance
let authManagerInstance: VertexAuthManager | null = null;
+/** Drop the cached token after the ADC login changes. */
+export function resetVertexAuthManager(): void {
+ authManagerInstance = null;
+}
+
/**
* Get the shared VertexAuthManager instance
*/
diff --git a/packages/cli/src/tui/App.tsx b/packages/cli/src/tui/App.tsx
index 5ac84a2a..14073fd2 100644
--- a/packages/cli/src/tui/App.tsx
+++ b/packages/cli/src/tui/App.tsx
@@ -136,6 +136,7 @@ import {
import {
type AuthSource,
type ProviderDef,
+ type ProviderLoginAction,
getProviderDefs,
maskKey,
providerAuthCapabilities,
@@ -143,6 +144,7 @@ import {
providerCredentialNote,
providerIsReady,
providerIsReadyForDisplay,
+ providerLoginAction,
} from "./providers.js";
import { A, C } from "./theme.js";
import type {
@@ -160,15 +162,12 @@ import type {
interface AppProps {
/**
* Called from the Providers tab `l` handler. The wrapper in
- * tui/index.tsx records the requested slug, then after the renderer
- * is destroyed it spawns `claudish login {slug}` as a child process
- * and re-enters startConfigTui when the child exits. App.tsx just
- * signals intent; lifecycle is the wrapper's responsibility.
+ * tui/index.tsx records the requested action, then after the renderer
+ * is destroyed it spawns the login command as a child process and
+ * re-enters startConfigTui when the child exits. App.tsx just signals
+ * intent; lifecycle is the wrapper's responsibility.
*/
- // Derived, not restated: this union had drifted the same way `ProviderDef.
- // oauthSlug` had, still naming the removed `gemini` provider. Both now follow
- // the catalog's `oauthLoginSlug`.
- requestLogin?: (slug: NonNullable<ProviderDef["oauthSlug"]>) => void;
+ requestLogin?: (action: ProviderLoginAction) => void;
}
/**
@@ -2326,9 +2325,9 @@ export function App({ requestLogin }: AppProps = {}) {
: "No stored config to remove.")
);
} else if (key.name === "l") {
- // OAuth login for the selected provider. Signal the wrapper
- // (tui/index.tsx) which slug to log into, then destroy the
- // renderer. The wrapper spawns `claudish login {slug}` as a
+ // Login for the selected provider. Signal the wrapper
+ // (tui/index.tsx) which action to run, then destroy the
+ // renderer. The wrapper spawns the login command as a
// child process so the OAuth callback server and inquirer
// prompts run in a clean stdio environment. When the child
// exits, the wrapper re-enters startConfigTui and we're back
@@ -2337,20 +2336,26 @@ export function App({ requestLogin }: AppProps = {}) {
// Child-process isolation avoids the ERR_CONNECTION_REFUSED
// issue that an earlier in-process attempt hit — the child
// gets a fresh Node runtime with no OpenTUI residue.
- const slug = selectedProvider.oauthSlug;
- if (!slug) {
+ const action = providerLoginAction(selectedProvider);
+ const command =
+ action?.kind === "gcloud-adc"
+ ? "gcloud auth application-default login"
+ : action
+ ? `claudish login ${action.slug}`
+ : "";
+ if (!action) {
setStatusMsg(
`${selectedProvider.displayName} doesn't support OAuth login. Press s to set an API key.`
);
} else if (!requestLogin) {
// Fallback: wrapper didn't provide the login bridge. Tell the
// user the command to run manually.
- setStatusMsg(`Run: claudish login ${slug}`);
+ setStatusMsg(`Run: ${command}`);
} else {
- setStatusMsg(`Launching: claudish login ${slug}…`);
+ setStatusMsg(`Launching: ${command}…`);
// Defer destroy so React commits the status message first.
setTimeout(() => {
- requestLogin(slug);
+ requestLogin(action);
renderer.destroy();
}, 50);
}
@@ -2845,7 +2850,7 @@ export function App({ requestLogin }: AppProps = {}) {
activeTab === "providers" && selectedProvider
? {
apiKey: !!selectedProvider.apiKeyEnvVar,
- oauth: !!selectedProvider.oauthSlug,
+ oauth: Boolean(providerLoginAction(selectedProvider)),
endpoint: !!selectedProvider.endpointEnvVar,
local: selectedProviderIsLocal,
localEnabled: selectedLocalEnabled,
diff --git a/packages/cli/src/tui/components/Footer.tsx b/packages/cli/src/tui/components/Footer.tsx
index 39af965e..e92959a1 100644
--- a/packages/cli/src/tui/components/Footer.tsx
+++ b/packages/cli/src/tui/components/Footer.tsx
@@ -22,6 +22,44 @@ interface FooterProps {
};
}
+export function providerFooterKeys(
+ providerCaps: FooterProps["providerCaps"]
+): Array<[string, string, string]> {
+ // Hotkey row is computed per-cursor-row: chips that don't apply to the
+ // selected provider are hidden. e.g. Gemini Code Assist has no API-key
+ // path so `s set key` and `e endpoint` are omitted; bare Gemini has no
+ // OAuth path so `l login` is omitted.
+ //
+ // When providerCaps is omitted (e.g. legacy callers, empty list), all
+ // chips are shown — back-compat.
+ const showKey = providerCaps ? providerCaps.apiKey : true;
+ const showEndpoint = providerCaps ? providerCaps.endpoint || providerCaps.local : true;
+ const showLogin = providerCaps ? providerCaps.oauth : true;
+ const showRemove = providerCaps
+ ? !providerCaps.local && (providerCaps.apiKey || providerCaps.endpoint)
+ : true;
+ // `u` is shown whenever the provider has an editable endpoint URL.
+ // For local providers it's the ONLY way to change the URL because `e`
+ // is taken by the enable/disable toggle. For remote providers it's a
+ // shortcut equivalent to `e endpoint`.
+ const showUrl = providerCaps ? providerCaps.endpoint : true;
+ const keys: Array<[string, string, string]> = [[C.blue, "↑↓", "navigate"]];
+ if (showKey) keys.push([C.green, "s", "set key"]);
+ if (showEndpoint)
+ keys.push([
+ C.green,
+ "e",
+ providerCaps?.local ? (providerCaps.localEnabled ? "disable" : "enable") : "endpoint",
+ ]);
+ if (showUrl) keys.push([C.green, "u", "url"]);
+ if (showLogin) keys.push([C.green, "l", "login"]);
+ keys.push([C.cyan, "t", "test"]);
+ keys.push([C.cyan, "T", "test all"]);
+ if (showRemove) keys.push([C.red, "x", "remove"]);
+ keys.push([C.dim, "q", "quit"]);
+ return keys;
+}
+
export function Footer({ activeTab, mode, probeMode, providerCaps }: FooterProps) {
// Recompute isProfileEditMode from the `mode` prop — pure on `mode`, kept
// self-contained so the parent doesn't have to pass a derived bool.
@@ -53,38 +91,7 @@ export function Footer({ activeTab, mode, probeMode, providerCaps }: FooterProps
[C.dim, "q", "quit"],
];
} else if (activeTab === "providers") {
- // Hotkey row is computed per-cursor-row: chips that don't apply to the
- // selected provider are hidden. e.g. Gemini Code Assist has no API-key
- // path so `s set key` and `e endpoint` are omitted; bare Gemini has no
- // OAuth path so `l login` is omitted.
- //
- // When providerCaps is omitted (e.g. legacy callers, empty list), all
- // chips are shown — back-compat.
- const showKey = providerCaps ? providerCaps.apiKey : true;
- const showEndpoint = providerCaps ? providerCaps.endpoint || providerCaps.local : true;
- const showLogin = providerCaps ? providerCaps.oauth : true;
- const showRemove = providerCaps
- ? !providerCaps.local && (providerCaps.apiKey || providerCaps.endpoint)
- : true;
- // `u` is shown whenever the provider has an editable endpoint URL.
- // For local providers it's the ONLY way to change the URL because `e`
- // is taken by the enable/disable toggle. For remote providers it's a
- // shortcut equivalent to `e endpoint`.
- const showUrl = providerCaps ? providerCaps.endpoint : true;
- keys = [[C.blue, "↑↓", "navigate"]];
- if (showKey) keys.push([C.green, "s", "set key"]);
- if (showEndpoint)
- keys.push([
- C.green,
- "e",
- providerCaps?.local ? (providerCaps.localEnabled ? "disable" : "enable") : "endpoint",
- ]);
- if (showUrl) keys.push([C.green, "u", "url"]);
- if (showLogin) keys.push([C.green, "l", "login"]);
- keys.push([C.cyan, "t", "test"]);
- keys.push([C.cyan, "T", "test all"]);
- if (showRemove) keys.push([C.red, "x", "remove"]);
- keys.push([C.dim, "q", "quit"]);
+ keys = providerFooterKeys(providerCaps);
} else if (activeTab === "profiles" && isProfileEditMode) {
// The bordered "New Profile" wizard modal owns its own inline hint line
// for every step (scope, name, model fields, provider picker). Showing
diff --git a/packages/cli/src/tui/components/footer-keys.test.ts b/packages/cli/src/tui/components/footer-keys.test.ts
new file mode 100644
index 00000000..3867401a
--- /dev/null
+++ b/packages/cli/src/tui/components/footer-keys.test.ts
@@ -0,0 +1,32 @@
+// REGRESSION: Vertex config TUI showed oauth but offered only "set key" and an unexplained 403 — Fixed in /dev:fix session dev-fix-20261020-235500-vtx01
+import { describe, expect, test } from "bun:test";
+import * as footer from "./Footer.js";
+
+const baseCaps = {
+ apiKey: true,
+ oauth: false,
+ endpoint: false,
+ local: false,
+ localEnabled: false,
+};
+
+function keyLabels(caps: Parameters<typeof footer.providerFooterKeys>[0]): string[][] {
+ return footer.providerFooterKeys(caps).map(([, key, label]) => [key, label]);
+}
+
+describe("Providers-tab footer keys", () => {
+ test("OAuth login support shows l login", () => {
+ expect(keyLabels({ ...baseCaps, oauth: true })).toContainEqual(["l", "login"]);
+ });
+
+ test("no OAuth login support omits the l chip", () => {
+ expect(keyLabels({ ...baseCaps, oauth: false }).some(([key]) => key === "l")).toBe(false);
+ });
+
+ test("undefined capabilities keep the default set-key and login chips", () => {
+ const keys = keyLabels(undefined);
+
+ expect(keys).toContainEqual(["s", "set key"]);
+ expect(keys).toContainEqual(["l", "login"]);
+ });
+});
diff --git a/packages/cli/src/tui/index.tsx b/packages/cli/src/tui/index.tsx
index 5b1b528a..8744ef14 100644
--- a/packages/cli/src/tui/index.tsx
+++ b/packages/cli/src/tui/index.tsx
@@ -7,20 +7,19 @@ import { getCodexOAuth } from "../auth/codex-oauth.js";
import { credentials } from "../auth/credentials/authority.js";
import { decideTuiRole, setCredentialPromptRole } from "../auth/credentials/prompt-role.js";
import { getKimiOAuth } from "../auth/kimi-oauth.js";
+import { resetVertexProjectDiscovery } from "../auth/vertex-auth.js";
import { setStderrQuiet } from "../logger.js";
-import { applyRendererThemeMode } from "../theme/renderer-theme.js";
-import type { ProviderDef } from "./providers.js";
-
-/** The `claudish login <slug>` argument, derived from the provider catalog. */
-type LoginSlug = NonNullable<ProviderDef["oauthSlug"]>;
import { ensureEndpointsRegistered } from "../providers/endpoint-registration.js";
import { resetMuseCredentialState } from "../providers/meta-muse/muse-credentials.js";
+import { _clearVertexDiscoveryCache } from "../providers/transport/vertex-discovery.js";
+import { applyRendererThemeMode } from "../theme/renderer-theme.js";
import { App } from "./App.js";
import { invalidateProbeProxyHandlers, shutdownProbeProxy } from "./probe-proxy.js";
+import type { ProviderLoginAction } from "./providers.js";
/**
- * Start the config TUI. Re-entrant: if App requests an OAuth login,
- * we tear down the renderer, spawn `claudish login {slug}` as a CHILD
+ * Start the config TUI. Re-entrant: if App requests a login,
+ * we tear down the renderer, spawn the login command as a CHILD
* process (clean stdio so the OAuth callback server doesn't fight with
* OpenTUI's lifecycle), wait for it to exit, then start a fresh TUI.
*
@@ -51,15 +50,12 @@ export async function startConfigTui(): Promise<void> {
// screen (the renderer can't invalidate cells it didn't draw).
setStderrQuiet(true);
- // Derived from the catalog's `oauthLoginSlug` — see the note on
- // `ProviderDef.oauthSlug`. These were hand-written unions that had drifted to
- // name a removed provider (`gemini`) while missing newer slugs.
- const loginRequest: { slug: LoginSlug | null } = {
- slug: null,
+ const loginRequest: { action: ProviderLoginAction | null } = {
+ action: null,
};
- const requestLogin = (slug: LoginSlug): void => {
- loginRequest.slug = slug;
+ const requestLogin = (action: ProviderLoginAction): void => {
+ loginRequest.action = action;
};
const renderer = await createCliRenderer({
@@ -88,20 +84,39 @@ export async function startConfigTui(): Promise<void> {
// messages on quit). Re-suppressed at the top of the next recursive call.
setStderrQuiet(false);
- if (loginRequest.slug !== null) {
- const slug = loginRequest.slug;
- console.log(`\nLaunching: claudish login ${slug}\n`);
- // Spawn the same runtime + script with `login {slug}`. stdio: "inherit"
- // gives the child our terminal so inquirer prompts and the OAuth
- // callback server work normally.
- const result = spawnSync(process.argv[0], [process.argv[1], "login", slug], {
- stdio: "inherit",
- });
+ if (loginRequest.action !== null) {
+ const action = loginRequest.action;
+ const command =
+ action.kind === "gcloud-adc"
+ ? "gcloud auth application-default login"
+ : `claudish login ${action.slug}`;
+ console.log(`\nLaunching: ${command}\n`);
+ // stdio: "inherit" gives the child our terminal so inquirer prompts
+ // and the OAuth callback server work normally.
+ const result =
+ action.kind === "gcloud-adc"
+ ? spawnSync("gcloud", ["auth", "application-default", "login"], { stdio: "inherit" })
+ : spawnSync(process.argv[0], [process.argv[1], "login", action.slug], { stdio: "inherit" });
if (result.error) {
- console.error(`\n❌ Failed to spawn login: ${result.error.message}\n`);
+ if (
+ action.kind === "gcloud-adc" &&
+ (result.error as NodeJS.ErrnoException).code === "ENOENT"
+ ) {
+ console.error(
+ "\ngcloud not found — install the Google Cloud CLI (https://cloud.google.com/sdk/docs/install)\n"
+ );
+ } else {
+ console.error(`\n❌ Failed to spawn login: ${result.error.message}\n`);
+ }
} else if (result.status !== 0) {
console.error(`\n❌ Login exited with status ${result.status}\n`);
+ } else if (action.kind === "gcloud-adc") {
+ resetVertexProjectDiscovery();
+ credentials.invalidate("vertex");
+ _clearVertexDiscoveryCache();
+ invalidateProbeProxyHandlers("vertex");
} else {
+ const slug = action.slug;
// Login succeeded IN A CHILD PROCESS, which wrote a fresh token file this
// long-lived parent never re-reads (the OAuth singletons load once at
// startup). Reload the relevant singleton from disk so the re-entered TUI's
diff --git a/packages/cli/src/tui/providers.ts b/packages/cli/src/tui/providers.ts
index 57f2240c..bdb8f548 100644
--- a/packages/cli/src/tui/providers.ts
+++ b/packages/cli/src/tui/providers.ts
@@ -49,6 +49,17 @@ export interface ProviderDef {
oauthSlug?: ProviderDefinition["oauthLoginSlug"];
}
+export type ProviderLoginAction =
+ | { kind: "claudish"; slug: NonNullable<ProviderDef["oauthSlug"]> }
+ | { kind: "gcloud-adc" };
+
+/** The login offered by both the Providers-tab footer and its `l` handler. */
+export function providerLoginAction(p: ProviderDef): ProviderLoginAction | undefined {
+ if (p.oauthSlug) return { kind: "claudish", slug: p.oauthSlug };
+ if (p.catalogName === "vertex") return { kind: "gcloud-adc" };
+ return undefined;
+}
+
// Skip virtual providers that have no API key and no TUI presence
const SKIP = new Set(["qwen", "native-anthropic"]);
@@ -252,7 +263,7 @@ export function providerCredentialNote(p: ProviderDef): string | undefined {
// sentence mentions an API key, because there is none to find.
return hasVertexAdcCredentials()
? `ADC present, no project — ${VERTEX_SET_PROJECT_REMEDY}`
- : `No credential — run \`gcloud auth application-default login\`, then ${VERTEX_SET_PROJECT_REMEDY}`;
+ : `No credential — run \`gcloud auth application-default login\` (press l), then ${VERTEX_SET_PROJECT_REMEDY}`;
}
return `Project ${origin.projectId} from ${describeVertexProjectSource(origin)}`;
}
diff --git a/packages/cli/src/tui/providers.vertex.test.ts b/packages/cli/src/tui/providers.vertex.test.ts
new file mode 100644
index 00000000..a45ebc87
--- /dev/null
+++ b/packages/cli/src/tui/providers.vertex.test.ts
@@ -0,0 +1,53 @@
+// REGRESSION: Vertex config TUI showed oauth but offered only "set key" and an unexplained 403 — Fixed in /dev:fix session dev-fix-20261020-235500-vtx01
+import { afterEach, beforeEach, describe, expect, test } from "bun:test";
+import { resetVertexProjectDiscovery } from "../auth/vertex-auth.js";
+import * as providers from "./providers.js";
+
+const originalProject = process.env.VERTEX_PROJECT;
+
+function providerDef(catalogName: string): providers.ProviderDef {
+ return (
+ providers.getProviderDefs().find((p) => p.catalogName === catalogName) ??
+ ({ catalogName } as providers.ProviderDef)
+ );
+}
+
+describe.serial("Vertex Providers-tab actions and guidance", () => {
+ beforeEach(() => {
+ process.env.VERTEX_PROJECT = "vertex-test-project";
+ resetVertexProjectDiscovery();
+ });
+
+ afterEach(() => {
+ if (originalProject === undefined) delete process.env.VERTEX_PROJECT;
+ else process.env.VERTEX_PROJECT = originalProject;
+ resetVertexProjectDiscovery();
+ });
+
+ test("Vertex without a claudish OAuth slug offers gcloud ADC login", () => {
+ const vertex = providerDef("vertex");
+ expect(vertex.oauthSlug).toBeUndefined();
+
+ expect(providers.providerLoginAction(vertex)).toEqual({ kind: "gcloud-adc" });
+ });
+
+ test("a declared kimi OAuth slug keeps the claudish login action", () => {
+ const kimi = { ...providerDef("kimi"), oauthSlug: "kimi" as const };
+
+ expect(providers.providerLoginAction(kimi)).toEqual({ kind: "claudish", slug: "kimi" });
+ });
+
+ test("Devin without a claudish OAuth slug offers no login action", () => {
+ const devin = providerDef("devin");
+ expect(devin.oauthSlug).toBeUndefined();
+
+ expect(providers.providerLoginAction(devin)).toBeUndefined();
+ });
+
+ test("the resolved-project credential note states only the project and its source", () => {
+ const note = providers.providerCredentialNote(providerDef("vertex"));
+
+ expect(note).toBe("Project vertex-test-project from $VERTEX_PROJECT");
+ expect(note).not.toContain("who signs");
+ });
+});