Repository: google-gemini/gemini-cli (TypeScript)

Issue:
feat(auth): Improve GEMINI_API_KEY not found error message
**Description:**

Currently, when the `GEMINI_API_KEY` is not set, the CLI displays a generic error message that is not very helpful for new users. This subtask is to update the error message to provide clear, actionable guidance.

**Acceptance Criteria:**

- The error message for a missing `GEMINI_API_KEY` should be updated in `packages/cli/src/config/auth.ts`.
- The new message should:
  1.  Clearly state that the `GEMINI_API_KEY` was not found.
  2.  Provide a direct link to `https://aistudio.google.com/apikey` for users to find their existing key or generate a new one.
  3.  Instruct the user on the immediate next steps required to authenticate (e.g., set the environment variable or add the key to a `.env` file).

**New Error Message:**
```
GEMINI_API_KEY not found. Find your existing key or generate a new one at: https://aistudio.google.com/apikey

To continue, please set the GEMINI_API_KEY environment variable or add it to a .env file.
```


Discussion:

Patch:
diff --git a/packages/cli/src/config/auth.ts b/packages/cli/src/config/auth.ts
index 8917ba87175..4a0fd4fce0e 100644
--- a/packages/cli/src/config/auth.ts
+++ b/packages/cli/src/config/auth.ts
@@ -18,7 +18,11 @@ export function validateAuthMethod(authMethod: string): string | null {
 
   if (authMethod === AuthType.USE_GEMINI) {
     if (!process.env['GEMINI_API_KEY']) {
-      return 'GEMINI_API_KEY environment variable not found. Add that to your environment and try again (no reload needed if using .env)!';
+      return (
+        'GEMINI_API_KEY not found. Find your existing key or generate a new one at: https://aistudio.google.com/apikey\n' +
+        '\n' +
+        'To continue, please set the GEMINI_API_KEY environment variable or add it to a .env file.'
+      );
     }
     return null;
   }
diff --git a/packages/cli/src/ui/auth/AuthDialog.tsx b/packages/cli/src/ui/auth/AuthDialog.tsx
index 7eb2c8ccd6c..67d710d5a81 100644
--- a/packages/cli/src/ui/auth/AuthDialog.tsx
+++ b/packages/cli/src/ui/auth/AuthDialog.tsx
@@ -26,7 +26,7 @@ interface AuthDialogProps {
   settings: LoadedSettings;
   setAuthState: (state: AuthState) => void;
   authError: string | null;
-  onAuthError: (error: string) => void;
+  onAuthError: (error: string | null) => void;
 }
 
 export function AuthDialog({
@@ -174,6 +174,9 @@ Logging in with Google... Please restart Gemini CLI to continue.
           items={items}
           initialIndex={initialAuthIndex}
           onSelect={handleAuthSelect}
+          onHighlight={() => {
+            onAuthError(null);
+          }}
         />
       </Box>
       {authError && (
diff --git a/packages/cli/src/ui/auth/useAuth.ts b/packages/cli/src/ui/auth/useAuth.ts
index 69898f64a43..014b74a26c8 100644
--- a/packages/cli/src/ui/auth/useAuth.ts
+++ b/packages/cli/src/ui/auth/useAuth.ts
@@ -33,9 +33,11 @@ export const useAuthCommand = (settings: LoadedSettings, config: Config) => {
   const [authError, setAuthError] = useState<string | null>(null);
 
   const onAuthError = useCallback(
-    (error: string) => {
+    (error: string | null) => {
       setAuthError(error);
-      setAuthState(AuthState.Updating);
+      if (error) {
+        setAuthState(AuthState.Updating);
+      }
     },
     [setAuthError, setAuthState],
   );
diff --git a/packages/cli/src/ui/contexts/UIActionsContext.tsx b/packages/cli/src/ui/contexts/UIActionsContext.tsx
index 096128143f5..555e2235d9c 100644
--- a/packages/cli/src/ui/contexts/UIActionsContext.tsx
+++ b/packages/cli/src/ui/contexts/UIActionsContext.tsx
@@ -23,7 +23,7 @@ export interface UIActions {
     scope: SettingScope,
   ) => void;
   setAuthState: (state: AuthState) => void;
-  onAuthError: (error: string) => void;
+  onAuthError: (error: string | null) => void;
   handleEditorSelect: (
     editorType: EditorType | undefined,
     scope: SettingScope,


Test patch:
diff --git a/packages/cli/src/config/auth.test.ts b/packages/cli/src/config/auth.test.ts
index 2eacd71ed51..faae662825a 100644
--- a/packages/cli/src/config/auth.test.ts
+++ b/packages/cli/src/config/auth.test.ts
@@ -45,7 +45,9 @@ describe('validateAuthMethod', () => {
     it('should return an error message if GEMINI_API_KEY is not set', () => {
       vi.stubEnv('GEMINI_API_KEY', undefined);
       expect(validateAuthMethod(AuthType.USE_GEMINI)).toBe(
-        'GEMINI_API_KEY environment variable not found. Add that to your environment and try again (no reload needed if using .env)!',
+        'GEMINI_API_KEY not found. Find your existing key or generate a new one at: https://aistudio.google.com/apikey\n' +
+          '\n' +
+          'To continue, please set the GEMINI_API_KEY environment variable or add it to a .env file.',
       );
     });
   });
diff --git a/packages/cli/src/ui/auth/AuthDialog.test.tsx b/packages/cli/src/ui/auth/AuthDialog.test.tsx
index 25446bf8185..5a16acd47d7 100644
--- a/packages/cli/src/ui/auth/AuthDialog.test.tsx
+++ b/packages/cli/src/ui/auth/AuthDialog.test.tsx
@@ -73,7 +73,7 @@ describe('AuthDialog', () => {
     settings: LoadedSettings;
     setAuthState: (state: AuthState) => void;
     authError: string | null;
-    onAuthError: (error: string) => void;
+    onAuthError: (error: string | null) => void;
   };
   const originalEnv = { ...process.env };