{"record":{"id":"de7904f78f886a1f","repo":"jackwener/OpenCLI","slug":"unexpected-claude-probe-json-stringify-result","errorCode":null,"errorMessage":"Unexpected Claude probe: ${JSON.stringify(result)}","messagePattern":"Unexpected Claude probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/claude/auth.js","lineNumber":37,"sourceCode":"        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  },\n});","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/claude/auth.js#L19-L55","documentation":"This CommandExecutionError fires when verifyClaudeIdentity receives a probe result that is neither ok nor one of the recognized kinds (auth/http/exception) — e.g. result is undefined/null, came back from a page that navigated away, or the evaluate returned an unexpected shape. The full result is serialized into the message for debugging. It guards against silently accepting a bogus verification outcome.","triggerScenarios":"page.evaluate returns undefined because the page navigated or was closed mid-probe; the browser context was destroyed before the async IIFE resolved; a driver/browser-version mismatch causing evaluate to return null; a non-standard result object from an incompatible page state.","commonSituations":"Browser tab closed or page redirected during the 2-second wait; automation driver (e.g. Playwright/puppeteer-core) version mismatch returning null from evaluate; Claude page reloading due to an error or forced logout during verification.","solutions":["Inspect the JSON in the message — null/undefined usually means the page navigated away or the browser context died","Re-run the command; transient navigation races often resolve on a second attempt","Re-run `opencli claude auth` to do a fresh login + verification on a stable page","Check for a forced logout or redirect loop on claude.ai (e.g. SSO session expiry) and log in manually once","Update the browser automation dependency and the library to compatible versions"],"exampleFix":"// before\n// tab closed during probe -> Unexpected Claude probe: undefined\n// after\nopencli claude auth   // fresh login, then verify on a stable page\nopencli claude whoami","handlingStrategy":"type-guard","validationCode":"null","typeGuard":"function isUsableProbeResult(result) {\n  return !!result && typeof result === 'object' && ['auth','http','exception'].includes(result.kind) || (result && result.ok === true);\n}","tryCatchPattern":"try {\n  const identity = await verifyClaudeIdentity(page);\n} catch (e) {\n  if (e.message.startsWith('Unexpected Claude probe:')) {\n    // page likely navigated or evaluate returned null — reload and retry once\n    await page.goto('https://claude.ai/');\n    return verifyClaudeIdentity(page);\n  }\n  throw e;\n}","preventionTips":["Don't close or navigate the automated browser tab during verification","Keep browser automation driver and library versions compatible","Re-run auth if the Claude page redirects or reloads unexpectedly","Retry once on this error — navigation races are usually transient"],"tags":["claude","browser","automation","unexpected-state"],"backgroundTag":"unexpected-probe-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}