jackwener/OpenCLI · error · CommandExecutionError

Unexpected Claude probe: ${JSON.stringify(result)}

Error message

Unexpected Claude probe: ${JSON.stringify(result)}

What it means

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.

Source

Thrown at clis/claude/auth.js:37

        return { kind: 'auth', detail: 'Claude /api/organizations HTTP ' + res.status };
      }
      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. Inspect the JSON in the message — null/undefined usually means the page navigated away or the browser context died
  2. Re-run the command; transient navigation races often resolve on a second attempt
  3. Re-run `opencli claude auth` to do a fresh login + verification on a stable page
  4. Check for a forced logout or redirect loop on claude.ai (e.g. SSO session expiry) and log in manually once
  5. Update the browser automation dependency and the library to compatible versions

Example fix

// before
// tab closed during probe -> Unexpected Claude probe: undefined
// after
opencli claude auth   // fresh login, then verify on a stable page
opencli claude whoami
Defensive patterns

Strategy: type-guard

Validate before calling

null

Type guard

function isUsableProbeResult(result) {
  return !!result && typeof result === 'object' && ['auth','http','exception'].includes(result.kind) || (result && result.ok === true);
}

Try / catch

try {
  const identity = await verifyClaudeIdentity(page);
} catch (e) {
  if (e.message.startsWith('Unexpected Claude probe:')) {
    // page likely navigated or evaluate returned null — reload and retry once
    await page.goto('https://claude.ai/');
    return verifyClaudeIdentity(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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