{"record":{"id":"1ebdb97062fb5b66","repo":"jackwener/OpenCLI","slug":"result-detail-auth-required-from-claude-probe","errorCode":null,"errorMessage":"result.detail (auth required from Claude probe)","messagePattern":"result\\.detail \\(auth required from Claude probe\\)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/claude/auth.js","lineNumber":34,"sourceCode":"    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 || '' };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('claude.ai', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/organizations`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Claude whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Claude probe: ${JSON.stringify(result)}`);\n  if (!result.user_id) throw new AuthRequiredError('claude.ai', 'Claude session incomplete — ajs_user_id cookie missing');\n  return { user_id: String(result.user_id), org_name: String(result.org_name), org_uuid: String(result.org_uuid) };\n}\n\nregisterSiteAuthCommands({\n  site: 'claude',\n  domain: 'claude.ai',\n  loginUrl: 'https://claude.ai/login',\n  columns: ['user_id', 'org_name', 'org_uuid'],\n  quickCheck: hasClaudeSessionCookie,\n  verify: verifyClaudeIdentity,\n  poll: async (page) => {\n    if (!await hasClaudeSessionCookie(page)) {\n      throw new AuthRequiredError('claude.ai', 'Waiting for Claude sessionKey cookie');\n    }","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/claude/auth.js#L16-L52","documentation":"The sessionKey cookie exists, but the in-page probe of /api/organizations returned kind 'auth', meaning Claude's server rejected the request as unauthenticated. verifyClaudeIdentity() surfaces the probe's detail via AuthRequiredError — the cookie is present but stale/invalid.","triggerScenarios":"sessionKey cookie present but revoked/expired server-side; fetch('/api/organizations') responds 401/redirect-to-login inside the page context; account logged out elsewhere invalidating the session.","commonSituations":"Password change or forced logout invalidating cookies; Claude rotating session keys; clock/profile issues leaving half-valid cookie state (sessionKey without ajs_user_id).","solutions":["Re-authenticate: log into claude.ai again in the automation profile, then retry.","Clear claude.ai cookies for the profile and log in fresh.","If it persists, verify the account wasn't logged out remotely (password change, other devices) and re-run the opencli auth flow."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify the full identity (not just the cookie) before heavy commands\ntry {\n  await opencli.claude.whoami();\n} catch {\n  await opencli.claude.login();\n  await opencli.claude.whoami();\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await opencli.claude.ask(prompt);\n} catch (e) {\n  if (e.name === 'AuthRequiredError' || /auth required from Claude probe/.test(e.message)) {\n    await opencli.claude.login();\n    return await opencli.claude.ask(prompt);\n  }\n  throw e;\n}","preventionTips":["Call whoami/probe before long automation runs to catch stale sessions early.","Re-login after password changes or remote logouts.","Treat AuthRequiredError uniformly: re-authenticate, then retry once.","Keep cookie state consistent — avoid sharing one profile across machines."],"tags":["auth","session-expired","cookies"],"backgroundTag":"session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}