orca icon indicating copy to clipboard operation
orca copied to clipboard

[Bug]: Orca's Claude account and usage state is wrong when Claude Code signs in with `CLAUDE_CODE_OAUTH_TOKEN`

Open siakun opened this issue 2 weeks ago • 1 comments

Where were you using Orca?

Desktop only

Operating system

Windows

Remote host operating system

No response

Orca version

v1.4.262

Details

Short summary: Orca only knows the sign-in stored in an account folder's .credentials.json. When Claude Code signs in with CLAUDE_CODE_OAUTH_TOKEN (the long-lived token from claude setup-token, documented at https://code.claude.com/docs/en/authentication#generate-a-long-lived-token), Orca shows a wrong usage state for that sign-in, and selecting a managed account silently stops deciding which account requests go to. Claude Code itself works fine in both cases; it is Orca's view of the account that is wrong.

What happened?

  1. Selecting a managed Claude account doesn't change the account requests go to while CLAUDE_CODE_OAUTH_TOKEN is set. Orca's terminal claude shell function switches CLAUDE_CONFIG_DIR but leaves the variable in place, and Claude Code ranks CLAUDE_CODE_OAUTH_TOKEN above the folder's /login credentials (https://code.claude.com/docs/en/authentication#authentication-precedence). Orca shows the selected account as active while every terminal session is billed to the token's account, with no warning.

  2. The usage panel reports a subscription sign-in as API key billing. A setup-token always belongs to a Claude subscription (Pro, Max, Team or Enterprise), yet with one in CLAUDE_CODE_OAUTH_TOKEN and no /login in ~/.claude, orca account list --json returns rateLimits.claude as status: "unavailable", error: "No subscription plan — API key billing", failureKind: "missing-credentials", with session and weekly null. The usage poll reads only .credentials.json, never the variable.

  3. The Claude usage bar appears while a session is responding and disappears a few minutes after it goes quiet. Orca does receive live usage for this sign-in: while such a session runs, claude-statusline.cmd keeps refreshing its stamp file (%TEMP%\orca-claude-statusline-last-<pane>.tmp), which it only writes after finding "rate_limits" in Claude Code's status line payload and right before posting to /statusline/claude. But resolveClaudeFetchApply keeps the live-session state only while isLiveClaudeUsageFresh holds (updated within the last 5 minutes). After that, the failing poll result from 2 replaces it and the bar drops out. For a token sign-in the poll can never succeed, so the bar flickers with session activity for as long as "Claude usage polling" is on, which is the default.

How can we reproduce it?

For 1:

  1. Set CLAUDE_CODE_OAUTH_TOKEN to a valid setup-token as a user environment variable and start Orca.
  2. Add a managed Claude account signed in to a different account and select it.
  3. Open a new Orca terminal and run claude auth status: authMethod is oauth_token, not claude.ai. Prompts run on the token's account.

I reproduced step 3 with a config folder whose .credentials.json holds a dummy access token with subscriptionType: "max". Without the variable, claude auth status in that folder reports authMethod: "claude.ai". In an Orca terminal with a valid token exported and CLAUDE_CONFIG_DIR pointing at that folder, it reports oauth_token, and a prompt gets a normal reply, which the dummy access token could not produce.

For 2 and 3:

  1. Use only CLAUDE_CODE_OAUTH_TOKEN (no /login in ~/.claude), with the System default account and "Claude usage polling" on.
  2. Start claude in an Orca terminal and send one prompt. The Claude bar appears in the status bar.
  3. Leave the session idle for more than 5 minutes. The bar disappears, and orca account list --json shows rateLimits.claude in the state described in 2.

Turning "Claude usage polling" off makes the bar stay, because claudeUsageWithoutOAuth then keeps the live values until their windows reset. That matches the setting's description ("Turn off to use live terminal readings only"), but nothing tells token users that the default setting can never work for them.

Expected:

  1. When CLAUDE_CODE_OAUTH_TOKEN is set in the environment Orca launches Claude with, the account settings say so and warn that it takes precedence over the selected account.
  2. When the poll fails with missing-credentials or missing-scope, Orca keeps the last live-session usage the way it already does with polling off, instead of replacing it after 5 minutes. A token sign-in is never labeled as API key billing.

Anything else that might help:

  • Claude Code 2.1.327, Windows 11.
  • GET https://api.anthropic.com/api/oauth/usage with a setup-token returns 403 oauth_scope_insufficient (OAuth token does not meet scope requirement user:profile). The token only has user:inference, so the poll can never serve these sign-ins; the live session data is the only usage source for them.
  • Per-model weekly limits such as Fable can't be shown for these sign-ins from any source. The status line only carries the 5-hour and 7-day (all models) windows, and Claude Code's own /usage shows only "Current week (all models)" with "Other limits and usage credits aren't shown for this sign-in." So that row should simply stay hidden for token sign-ins.
  • Making setup-token a managed account type (#12002) would remove the conflict in 1 for users who adopt it. The warning is still needed for users who keep the variable exported.
  • Related: #12002, #35497, #31905 (different cause: running sessions keep the old account after a switch).

siakun avatar Nov 18 '26 14:11 siakun

Data point from a Linux headless serve host, Orca 1.4.271, Claude Code 2.1.332.

On Linux the usage reader reads only <configDir>/.credentials.json. It does not look at CLAUDE_CODE_OAUTH_TOKEN. With only setup-tokens on the host (no /login), the file does not exist, so the usage row shows the missing-credentials state.

Reading the env token alone does not fix it. GET https://api.anthropic.com/api/oauth/usage with a claude setup-token token returns 403 oauth_scope_insufficient (required scope user:profile). The setup-token has only the inference scope.

Smallest change that works with setup-tokens: use it when the credential source is CLAUDE_CODE_OAUTH_TOKEN, or when the usage endpoint answers 403 oauth_scope_insufficient. Then fill the usage row from the last rate_limit_event of a session on that sign-in (rate_limit_info.unifiedWindows.{five_hour,seven_day}), as #35497 asks. Show "usage known after the next response" until a frame arrives. Do not report it as API key billing.

flyingbag avatar Dec 05 '26 08:12 flyingbag