{"record":{"id":"6fb6805b9cca28a8","repo":"jackwener/OpenCLI","slug":"claude-sessionkey-cookie-missing","errorCode":null,"errorMessage":"Claude sessionKey cookie missing","messagePattern":"Claude sessionKey cookie missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/claude/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasClaudeSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://claude.ai' });\n  return cookies.some(c => c.name === 'sessionKey' && c.value);\n}\n\nasync function verifyClaudeIdentity(page) {\n  if (!await hasClaudeSessionCookie(page)) {\n    throw new AuthRequiredError('claude.ai', 'Claude sessionKey cookie missing');\n  }\n  await page.goto('https://claude.ai/');\n  await page.wait(2);\n  const result = await page.evaluate(`(async () => {\n    try {\n      const res = await fetch('/api/organizations', { credentials: 'include' });\n      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'Claude /api/organizations HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      if (!Array.isArray(d) || d.length === 0) {\n        return { kind: 'auth', detail: 'Claude /api/organizations empty' };\n      }\n      const userIdCookie = (document.cookie.split('; ').find(c => c.startsWith('ajs_user_id=')) || '').split('=')[1] || '';\n      const activeOrgCookie = (document.cookie.split('; ').find(c => c.startsWith('lastActiveOrg=')) || '').split('=')[1] || '';\n      const activeOrg = d.find(o => o.uuid === activeOrgCookie) || d[0];\n      return { ok: true, user_id: userIdCookie, org_name: activeOrg.name || '', org_uuid: activeOrg.uuid || '' };","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/claude/auth.js#L1-L29","documentation":"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.","triggerScenarios":"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.","commonSituations":"Fresh machine/container with no Claude login; cookie purge by browser policy; sessionKey expired after long inactivity; running headless with an empty profile.","solutions":["Log into claude.ai in the automation browser profile to obtain a sessionKey cookie.","Re-run the opencli auth/login flow for the claude site, then retry the command.","Clear and re-create the persistent session profile if cookies are corrupted."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Check for a session cookie before invoking commands\nconst cookies = await page.getCookies({ url: 'https://claude.ai' });\nconst hasSession = cookies.some(c => c.name === 'sessionKey' && c.value);\nif (!hasSession) throw new Error('Log into claude.ai first');","typeGuard":null,"tryCatchPattern":"try {\n  return await opencli.claude.ask(prompt);\n} catch (e) {\n  if (/sessionKey cookie missing/.test(e.message)) {\n    await opencli.claude.login(); // interactive auth\n    return await opencli.claude.ask(prompt);\n  }\n  throw e;\n}","preventionTips":["Run the auth/login flow once per profile before batch jobs.","Avoid clearing cookies in the persistent session profile.","Re-authenticate periodically; sessionKey does not live forever.","In CI, seed the browser profile with a valid Claude session."],"tags":["auth","session","cookies"],"backgroundTag":"missing-session-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}