{"record":{"id":"c53ce21babbb210d","repo":"jackwener/OpenCLI","slug":"sign-in-to-grok-com-in-your-browser-then-retry-c53ce2","errorCode":null,"errorMessage":"Sign in to grok.com in your browser, then retry.","messagePattern":"Sign in to grok\\.com in your browser, then retry\\.","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/grok/send.js","lineNumber":45,"sourceCode":"    columns: ['Status', 'Prompt'],\n    func: async (page, kwargs) => {\n        const prompt = String(kwargs.prompt || '').trim();\n        if (!prompt) throw new ArgumentError('prompt', 'is required');\n        const startFresh = normalizeBooleanFlag(kwargs.new, false);\n\n        await ensureOnGrok(page);\n        if (startFresh) {\n            await startNewChat(page);\n        }\n\n        const send = await sendMessage(page, prompt);\n        if (!send?.ok) {\n            // If the composer is missing, the most likely cause is that the\n            // signed-in session expired (Grok then renders a sign-in CTA in\n            // place of the composer). Surface that as AuthRequiredError so\n            // agents can prompt for re-auth instead of treating it as a\n            // generic execution failure.\n            if (!(await isLoggedIn(page))) throw authRequired();\n            throw new CommandExecutionError(send?.reason || 'Failed to send Grok prompt');\n        }\n        return [{ Status: 'sent', Prompt: prompt }];\n    },\n});\n","sourceCodeStart":27,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/grok/send.js#L27-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Sign in to grok.com in the browser session/profile the CLI uses, then re-run the command","Persist a browser profile directory so cookies survive between runs","Re-check credentials/2FA on the grok.com account if sign-ins keep expiring","Upgrade the CLI in case session handling changed"],"exampleFix":"// before (session expired, send fails)\nawait cli.call('grok', 'send', { prompt });\n// after (detect auth error and re-auth before retrying)\ntry {\n  return await cli.call('grok', 'send', { prompt });\n} catch (e) {\n  if (e instanceof AuthRequiredError || /Sign in to grok\\.com/.test(e.message)) {\n    await grokLogin(); // interactive browser sign-in\n    return await cli.call('grok', 'send', { prompt });\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// before calling send, verify the session\nif (!(await grokIsLoggedIn())) {\n  await promptBrowserSignIn('https://grok.com');\n}","typeGuard":"function isAuthRequiredError(e) {\n  return e instanceof Error && /Sign in to grok\\.com/.test(e.message);\n}","tryCatchPattern":"try {\n  await grokSend(prompt);\n} catch (e) {\n  if (isAuthRequiredError(e)) {\n    await grokLogin();\n    return grokSend(prompt);\n  }\n  throw e;\n}","preventionTips":["Use a persistent browser profile so cookies survive restarts","Check login state before batch sends","Alert on AuthRequiredError instead of retrying blindly","Refresh sessions periodically in long-running agents"],"tags":["auth","browser-automation","session-expired"],"backgroundTag":"auth-session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}