jackwener/OpenCLI · error · AuthRequiredError

Claude sessionKey cookie missing

Error message

Claude sessionKey cookie missing

What it means

verifyClaudeIdentity() first checks that a non-empty sessionKey cookie exists for claude.ai. If absent, it throws AuthRequiredError because the automation has no Claude web session to act with — every subsequent page action would hit a login page.

Source

Thrown at clis/claude/auth.js:11

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';

async function hasClaudeSessionCookie(page) {
  const cookies = await page.getCookies({ url: 'https://claude.ai' });
  return cookies.some(c => c.name === 'sessionKey' && c.value);
}

async function verifyClaudeIdentity(page) {
  if (!await hasClaudeSessionCookie(page)) {
    throw new AuthRequiredError('claude.ai', 'Claude sessionKey cookie missing');
  }
  await page.goto('https://claude.ai/');
  await page.wait(2);
  const result = await page.evaluate(`(async () => {
    try {
      const res = await fetch('/api/organizations', { credentials: 'include' });
      if (res.status === 401 || res.status === 403) {
        return { kind: 'auth', detail: 'Claude /api/organizations HTTP ' + res.status };
      }
      if (!res.ok) return { kind: 'http', httpStatus: res.status };
      const d = await res.json();
      if (!Array.isArray(d) || d.length === 0) {
        return { kind: 'auth', detail: 'Claude /api/organizations empty' };
      }
      const userIdCookie = (document.cookie.split('; ').find(c => c.startsWith('ajs_user_id=')) || '').split('=')[1] || '';
      const activeOrgCookie = (document.cookie.split('; ').find(c => c.startsWith('lastActiveOrg=')) || '').split('=')[1] || '';
      const activeOrg = d.find(o => o.uuid === activeOrgCookie) || d[0];
      return { ok: true, user_id: userIdCookie, org_name: activeOrg.name || '', org_uuid: activeOrg.uuid || '' };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log into claude.ai in the automation browser profile to obtain a sessionKey cookie.
  2. Re-run the opencli auth/login flow for the claude site, then retry the command.
  3. Clear and re-create the persistent session profile if cookies are corrupted.
Defensive patterns

Strategy: validation

Validate before calling

// Check for a session cookie before invoking commands
const cookies = await page.getCookies({ url: 'https://claude.ai' });
const hasSession = cookies.some(c => c.name === 'sessionKey' && c.value);
if (!hasSession) throw new Error('Log into claude.ai first');

Try / catch

try {
  return await opencli.claude.ask(prompt);
} catch (e) {
  if (/sessionKey cookie missing/.test(e.message)) {
    await opencli.claude.login(); // interactive auth
    return await opencli.claude.ask(prompt);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling any claude command before ever logging into claude.ai in the automation browser profile, or after cookies were cleared/expired so hasClaudeSessionCookie(page) returns false.

Common situations: Fresh machine/container with no Claude login; cookie purge by browser policy; sessionKey expired after long inactivity; running headless with an empty profile.

Related errors


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