jackwener/OpenCLI · error · AuthRequiredError

Sign in to grok.com in your browser, then retry.

Error message

Sign in to grok.com in your browser, then retry.

What it means

Grok CLI's send command opens a browser session to grok.com, types the prompt, and submits it. If the send action does not succeed, the code first checks isLoggedIn(page); when the session is gone (Grok renders a sign-in CTA instead of the composer) it throws AuthRequiredError with this message so agents know to re-authenticate rather than treat it as a generic execution failure.

Source

Thrown at clis/grok/send.js:45

    columns: ['Status', 'Prompt'],
    func: async (page, kwargs) => {
        const prompt = String(kwargs.prompt || '').trim();
        if (!prompt) throw new ArgumentError('prompt', 'is required');
        const startFresh = normalizeBooleanFlag(kwargs.new, false);

        await ensureOnGrok(page);
        if (startFresh) {
            await startNewChat(page);
        }

        const send = await sendMessage(page, prompt);
        if (!send?.ok) {
            // If the composer is missing, the most likely cause is that the
            // signed-in session expired (Grok then renders a sign-in CTA in
            // place of the composer). Surface that as AuthRequiredError so
            // agents can prompt for re-auth instead of treating it as a
            // generic execution failure.
            if (!(await isLoggedIn(page))) throw authRequired();
            throw new CommandExecutionError(send?.reason || 'Failed to send Grok prompt');
        }
        return [{ Status: 'sent', Prompt: prompt }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Sign in to grok.com in the browser session/profile the CLI uses, then re-run the command
  2. Persist a browser profile directory so cookies survive between runs
  3. Re-check credentials/2FA on the grok.com account if sign-ins keep expiring
  4. Upgrade the CLI in case session handling changed

Example fix

// before (session expired, send fails)
await cli.call('grok', 'send', { prompt });
// after (detect auth error and re-auth before retrying)
try {
  return await cli.call('grok', 'send', { prompt });
} catch (e) {
  if (e instanceof AuthRequiredError || /Sign in to grok\.com/.test(e.message)) {
    await grokLogin(); // interactive browser sign-in
    return await cli.call('grok', 'send', { prompt });
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling send, verify the session
if (!(await grokIsLoggedIn())) {
  await promptBrowserSignIn('https://grok.com');
}

Type guard

function isAuthRequiredError(e) {
  return e instanceof Error && /Sign in to grok\.com/.test(e.message);
}

Try / catch

try {
  await grokSend(prompt);
} catch (e) {
  if (isAuthRequiredError(e)) {
    await grokLogin();
    return grokSend(prompt);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the grok send command while the browser session's auth cookies are expired or missing, so the composer element is not present (send.ok is false) and isLoggedIn returns false.

Common situations: Long-lived automation sessions where grok.com rotated the session token; running the CLI on a fresh browser profile that was never signed in; clearing browser cookies between runs; Grok forcing a new login after a security event or password change.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/c53ce21babbb210d. Report an issue: GitHub.