{"record":{"id":"ef5e3f0376fc9401","repo":"jackwener/OpenCLI","slug":"claude-whoami-failed-result-detail","errorCode":null,"errorMessage":"Claude whoami failed: ${result.detail}","messagePattern":"Claude whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/claude/auth.js","lineNumber":36,"sourceCode":"      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    }\n    return verifyClaudeIdentity(page);\n  },","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/claude/auth.js#L18-L54","documentation":"This CommandExecutionError wraps any JavaScript exception thrown inside the in-page fetch probe to /api/organizations (the caught error is stringified into result.detail). It indicates the whoami verification script itself crashed in the browser context rather than receiving a normal HTTP response — e.g. a failed fetch (network/DNS error), JSON parsing failure, or a Claude page change that breaks the script.","triggerScenarios":"The page.evaluate probe's try block throws: network failure reaching /api/organizations (offline, DNS failure, proxy block), res.json() failing on a non-JSON response (login redirect HTML, Cloudflare challenge page), or an injected script/CSP change breaking evaluation.","commonSituations":"Corporate proxy or VPN blocking claude.ai API calls; Cloudflare interstitial returning HTML so JSON parsing throws; internet drop mid-probe; browser extension or CSP changes blocking in-page fetch; Claude frontend returning an unexpected payload shape after an update.","solutions":["Read result.detail in the message to see the underlying exception and address it specifically","Verify general internet connectivity and that https://claude.ai loads in the browser without a Cloudflare challenge","Disable conflicting extensions (ad-blockers/script blockers) or bypass VPN/proxy, then retry","Re-run the login flow (`opencli claude auth`) so the probe runs on a freshly loaded claude.ai page","Update the library — Claude may have changed its response format and a newer probe handles it"],"exampleFix":"// before\nconst res = await fetch('/api/organizations', { credentials: 'include' }); // TypeError: Failed to fetch (offline)\n// after\n// ensure connectivity first, then retry:\nping claude.ai && opencli claude whoami","handlingStrategy":"try-catch","validationCode":"// ensure connectivity before running browser probes\nconst res = await fetch('https://claude.ai/robots.txt').catch(() => null);\nif (!res || !res.ok) throw new Error('claude.ai unreachable — check network/VPN/proxy');","typeGuard":"function isProbeException(result) {\n  return !!result && result.kind === 'exception' && typeof result.detail === 'string';\n}","tryCatchPattern":"try {\n  const identity = await verifyClaudeIdentity(page);\n} catch (e) {\n  if (e.message.startsWith('Claude whoami failed:')) {\n    console.error('Probe crashed in page:', e.message);\n    // check network, disable interfering extensions, reload page and retry once\n  }\n  throw e;\n}","preventionTips":["Verify network/VPN/proxy access to claude.ai before automation runs","Disable ad-blocker/script-blocker extensions in the automation browser profile","Re-run the auth flow so the probe executes on a freshly loaded page","Update the library when Claude changes its response format"],"tags":["network","claude","browser","fetch"],"backgroundTag":"in-page-fetch-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}