jackwener/OpenCLI · error · AuthRequiredError

Claude requires a logged-in browser session.

Error message

Claude requires a logged-in browser session.

What it means

This AuthRequiredError is thrown by ensureClaudeLogin when getPageState reports isLoggedIn === false for claude.ai — i.e. the automated browser has no valid logged-in session. All claude detail/history/read/send commands call it before scraping or interacting, so any page operation requires an authenticated session first. A caller-supplied message overrides the default text.

Source

Thrown at clis/claude/utils.js:56

}

export async function getPageState(page) {
    return page.evaluate(`(() => {
        var composer = document.querySelector('${COMPOSER_SELECTOR}');
        var userMenu = document.querySelector('[data-testid="user-menu-button"]');
        return {
            url: window.location.href,
            title: document.title,
            hasComposer: !!composer,
            isLoggedIn: !!userMenu,
        };
    })()`);
}

export async function ensureClaudeLogin(page, message = 'Claude requires a logged-in browser session.') {
    const state = await getPageState(page);
    if (!state.isLoggedIn) {
        throw new AuthRequiredError(CLAUDE_DOMAIN, message);
    }
    return state;
}

export async function ensureClaudeComposer(page, message = 'Claude composer is not available on the current page.') {
    const state = await ensureClaudeLogin(page, message);
    if (!state.hasComposer) {
        throw new CommandExecutionError(message);
    }
    return state;
}

export function requireNonEmptyPrompt(prompt, commandName) {
    const text = String(prompt ?? '').trim();
    if (!text) {
        throw new ArgumentError(
            `${commandName} prompt cannot be empty`,
            `Example: opencli ${commandName} "hello"`,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run `opencli claude auth` (or `opencli claude whoami`) to launch the login flow and establish a fresh session before running detail/history/read/send
  2. Log in manually in the automated browser window if the flow is running, completing any 2FA/SSO/email-code steps
  3. Check that privacy extensions or browser settings are not stripping claude.ai cookies between commands
  4. If you were logged in but it broke recently, verify claude.ai in a normal browser — a forced logout (password change) requires re-login
  5. Update the library if login detection broke due to a Claude UI change

Example fix

// before
opencli claude read   // no session -> AuthRequiredError
// after
opencli claude auth    # complete login in the automated browser
opencli claude read
Defensive patterns

Strategy: validation

Validate before calling

// verify a session exists before running any claude command
const cookies = await page.getCookies({ url: 'https://claude.ai' });
if (!cookies.some(c => c.name === 'sessionKey' && c.value)) {
  throw new Error('Not logged in — run `opencli claude auth` first');
}

Type guard

function isClaudeLoggedIn(state) {
  return !!state && state.isLoggedIn === true;
}

Try / catch

try {
  await ensureClaudeLogin(page);
} catch (e) {
  if (e instanceof AuthRequiredError || /logged-in browser session/.test(e.message)) {
    await runClaudeAuthFlow();               // fresh login, then proceed
    return ensureClaudeLogin(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: Any claude command (detail, history, read, send) runs while the browser lacks a claude.ai login: cookies expired or were cleared, the user never completed `opencli claude auth`, Claude force-logged-out the session, or getPageState's login detection fails to recognize the logged-in UI after a Claude frontend change.

Common situations: sessionKey cookie expired (Claude sessions age out); cookies cleared by privacy tools or browser restart; user ran a claude command before ever running the auth flow; Claude invalidated the session server-side (password change, SSO expiry); library's login-detection selector broken by a Claude UI update.

Related errors


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