jackwener/OpenCLI · error · AuthRequiredError

Claude session incomplete — ajs_user_id cookie missing

Error message

Claude session incomplete — ajs_user_id cookie missing

What it means

This AuthRequiredError means the /api/organizations probe succeeded and returned org data, but the analytics cookie ajs_user_id was absent, so the library cannot report a user_id. The sessionKey cookie exists and the API accepts it, but the identity cookie Claude normally sets is missing — a partial or degraded login state.

Source

Thrown at clis/claude/auth.js:38

      }
      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 || '' };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (result?.kind === 'auth') throw new AuthRequiredError('claude.ai', result.detail);
  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/organizations`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`Claude whoami failed: ${result.detail}`);
  if (!result?.ok) throw new CommandExecutionError(`Unexpected Claude probe: ${JSON.stringify(result)}`);
  if (!result.user_id) throw new AuthRequiredError('claude.ai', 'Claude session incomplete — ajs_user_id cookie missing');
  return { user_id: String(result.user_id), org_name: String(result.org_name), org_uuid: String(result.org_uuid) };
}

registerSiteAuthCommands({
  site: 'claude',
  domain: 'claude.ai',
  loginUrl: 'https://claude.ai/login',
  columns: ['user_id', 'org_name', 'org_uuid'],
  quickCheck: hasClaudeSessionCookie,
  verify: verifyClaudeIdentity,
  poll: async (page) => {
    if (!await hasClaudeSessionCookie(page)) {
      throw new AuthRequiredError('claude.ai', 'Waiting for Claude sessionKey cookie');
    }
    return verifyClaudeIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log out of claude.ai completely and log back in so all cookies (including ajs_user_id) are set fresh
  2. Disable cookie-clearing/privacy extensions or whitelist claude.ai so analytics cookies persist
  3. Allow cookies for claude.ai in browser settings (do not block third-party/analytics cookies for the domain)
  4. If Claude removed/renamed the cookie, update the library to a version matching the current claude.ai behavior
  5. Verify with an `opencli claude auth` re-run, which re-executes the login + verification flow

Example fix

// before
// sessionKey present, ajs_user_id deleted by extension -> AuthRequiredError
// after
// browser extension: add claude.ai to cookie whitelist, then
opencli claude auth && opencli claude whoami
Defensive patterns

Strategy: validation

Validate before calling

const cookies = await page.getCookies({ url: 'https://claude.ai' });
const hasSession = cookies.some(c => c.name === 'sessionKey' && c.value);
const hasUserId = cookies.some(c => c.name === 'ajs_user_id' && c.value);
if (!hasSession || !hasUserId) throw new Error('Incomplete claude.ai cookies — re-run `opencli claude auth`');

Type guard

function hasCompleteClaudeCookies(cookies) {
  const names = new Set(cookies.filter(c => c.value).map(c => c.name));
  return names.has('sessionKey') && names.has('ajs_user_id');
}

Try / catch

try {
  const identity = await verifyClaudeIdentity(page);
} catch (e) {
  if (e.message.includes('ajs_user_id cookie missing')) {
    // partial session: full logout + fresh login restores all cookies
    return runClaudeAuthFlow();
  }
  throw e;
}

Prevention

When it happens

Trigger: verifyClaudeIdentity returns ok from /api/organizations but document.cookie contains no ajs_user_id entry — e.g. login completed only partially, cookies were partially cleared, or Claude stopped setting the ajs_user_id cookie in a frontend update; also possible when third-party/cookie settings or a cookie-clearing extension strips analytics cookies.

Common situations: User cleared cookies selectively (kept sessionKey, removed analytics cookies); browser configured to block tracking/analytics cookies; privacy extensions (uBlock, cookie auto-delete) removing ajs_* cookies; Claude changing cookie naming in a new frontend release, breaking the library's expectation.

Related errors


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