Skip to content

fix(usage): Claude Code subscription usage missing for agents running on claude-cli - #157753

Closed
8bitsforge wants to merge 1 commit into
openclaw:mainfrom
8bitsforge:fix/claude-cli-usage-windows
Closed

8bitsforge wants to merge 1 commit into
openclaw:mainfrom
8bitsforge:fix/claude-cli-usage-windows

Conversation

@8bitsforge

@8bitsforge 8bitsforge commented Sep 25, 2026 •

Copy link
Copy Markdown

Related: #143419, #156296

What Problem This Solves

Fixes: agents that run through Claude Code (claude-cli) never show the subscription usage they actually consume. usage.status either has no Claude row or shows an error for a different Anthropic credential.

User Impact

Usage now follows the route an agent runs on. When agents run through Claude Code under the Gateway host's own login, usage.status reports a separate Claude Code row with that subscription's 5-hour and weekly windows and reset times. The row reaches the Control UI Usage page, chat /status, and Gateway clients. The Anthropic row is unchanged: an API key still shows spend and cost, a setup-token still shows its own result or error, and nothing is substituted between the two.

The row appears after the first Claude Code turn following a Gateway start. It carries when it was reported (observedAt), shown as as of 12m ago in /status and Observed 12m ago on the Control UI usage cards, so a reader can tell when it may be out of date.

Why This Change Was Made

Anthropic has two billing surfaces, and OpenClaw can use both at once:

  • Pay-per-use API (API key): spend and cost, no subscription windows.
  • Subscription through Claude Code (claude auth login): the 5-hour and weekly windows.

OpenClaw currently reports both as one "Claude" row and only asks the Anthropic credential for usage. For the Claude Code route that cannot work:

Claude Code already reports its own windows on every turn. Its stream-json output carries a rate_limit_event whose rate_limit_info.unifiedWindows has five_hour and seven_day utilization and reset times, and OpenClaw currently discards it. This change:

  • reads that record where the Claude stream is parsed;
  • keeps the latest windows in Gateway memory under a Claude Code identity;
  • reports them as their own Claude Code row whenever Claude usage is requested, beside the Anthropic row and never merged into it.

Recording is limited to the Gateway host's own Claude login. It is skipped for:

  • paired-node turns;
  • turns under an OpenClaw auth profile (pinned, set on the agent's model, or picked automatically);
  • turns with a credential, auth endpoint, or provider switch in the child environment. Any ANTHROPIC_* variable counts except model selectors, OpenClaw's Admin API usage and API-key rotation keys, and Vertex project settings (inert without CLAUDE_CODE_USE_VERTEX, which counts). Claude Code tokens and switches such as Bedrock, Vertex, Foundry, Mantle, or a gateway count too; names are matched case-insensitively;
  • turns with a --settings or --managed-settings backend argument;
  • turns with a different or skill-provided CLAUDE_CONFIG_DIR.

Each of those can be another account. A record that carries only some windows updates just those. The store clears with the model-auth status usage cache, which runs on any model-auth change.

Where the row shows.

  • /status shows the Claude Code row only for a Claude Code session on the host login, and reads it from the in-memory store without a network request. Two checks must pass. First, the runner notes on every Claude Code turn whether the recording rule admitted it, using the turn's real environment, arguments, skills, and account; the session's latest turn must have been admitted. Second, the run's own account resolver (resolveCliExecutionAuthProfileId) is asked with the session's pin, the agent's configured @profile, and the session's Claude Code binding, so a profile chosen since that turn also excludes it. Every other session keeps the usage line it had before, and the Claude Code row never stands in for its provider.
  • The Models page gives Claude Code its own usage-only card. Claude Code manages that login, so the card offers no credential actions: saving an API key there would have created a claude-cli profile that later Claude Code runs pick up.

Cache expiry. A cached usage summary no longer serves a window after that window's reset time. The usage cache refreshes at the earliest reset in the summary instead of waiting for the 60 s TTL, and stale serves drop windows that have reset. A summary cached before Claude Code first reported its windows is also refreshed on the next read, so the row does not wait out the TTL after a Gateway start. This applies to every provider's windows, since a window past its reset is stale regardless of source.

Placement. #129485 parsed the same record in core for turn-log diagnostics. It was closed because its target error was not an OpenClaw bug. This change uses the record for the documented usage surface. If maintainers prefer the Anthropic plugin to own the parser and row once #156296 moves Claude usage fetching there, both can move with it.

Known limits:

  • The Claude Code row reflects the last recorded turn. Claude use outside this Gateway, or a claude /login switch, is picked up on the next turn or when model auth changes. The row's observedAt (the oldest time among its windows) makes that visible instead of presenting the windows as current.
  • The composer popover lists providers from auth profiles (models.authStatus). Matching a session to the Claude Code row there is a UI follow-up; this PR reports the row through usage.status.
  • A separate openclaw status --usage process does not see Gateway memory.
  • A user with a working Anthropic subscription OAuth login and Claude Code on the same account sees the same windows in both rows. Each row is still correct for its own route.

No config, schema, or storage changes. One additive, optional field: ProviderUsageSnapshot.observedAt (epoch ms), set only on usage observed from runtime output rather than fetched.

Evidence

Live proof on a head-built dist and an isolated Gateway (OPENCLAW_STATE_DIR and port isolated). Config: anthropic/claude-haiku-4-5 with agentRuntime: claude-cli, Claude Code 2.1.280 with its native subscription login, no Anthropic credential in OpenClaw.

  • Before any turn: usage.status returned "providers": [].
  • One turn: a single openclaw agent turn ran (cli turn: provider=claude-cli model=claude-haiku-4-5 …).
  • After the usage cache refreshed, usage.status returned:
    { "provider": "claude-cli", "displayName": "Claude Code",
      "windows": [ { "label": "5h", "usedPercent": 56, "resetAt": 1790340000000 },
                   { "label": "Week", "usedPercent": 67, "resetAt": 1790784000000 } ] }
    The trace showed 56.00000000000001 from 0.56 * 100. The head rounds to two decimals, and a test covers it.

Control UI proof (September 26). Same isolated setup for both: a fresh state directory, the Usage page opened first, one real openclaw agent turn through Claude Code, then the Usage page again. Headless Chromium 1187, dark theme, 1280×900 at 2×. Nothing private is shown; the session is the throwaway ccusage-proof.

  • Before, upstream base 516b1f8c4a6, captured more than 60 s after the turn so the usage cache had expired: the page ends at Sessions. No provider section and no Claude Code row.
  • After, this head 127147da3e7, captured on the first page load after the turn: the Claude Code card with its 5-hour and weekly windows, reset times, and Observed just now. The page had been opened before the turn, so this load also exercises the first-observation cache refresh below.
Before (base 516b1f8c4a6) After (head 127147da3e7)
Usage page on the base commit after a Claude Code turn: no provider section Usage page on this head after a Claude Code turn: Claude Code card with windows and observed age

Claude Code usage card: 5h and Week windows, reset times, Observed just now

Models page proof (same isolated setup, one real Claude Code turn, Settings → Models). Before, the Anthropic card said "Not configured" yet showed Claude Code's windows as its own. After, Claude Code has its own usage-only card, and the Anthropic card reports its own (empty) usage with its usual actions.

Before: Anthropic card (127147da3e7) After: Anthropic card (fa180453a67)
Anthropic card marked Not configured but showing the Claude Code 5h and Week windows Anthropic card marked Not configured with no live usage data

Claude Code card with 5h and Week windows, reset times, Observed just now, and no buttons

Live /status on the same Gateway and session after the turn (sent through chat.send):

Auth: native (claude-cli)
Usage: 5h 92% left ⏱3h 19m · Week 83% left ⏱4d 4h · as of just now

Wire shape (Claude Code 2.1.280, identifiers removed), used as the parser fixture:

{"type":"rate_limit_event","rate_limit_info":{"status":"allowed","resetsAt":1790305200,"rateLimitType":"five_hour","overageStatus":"rejected","overageDisabledReason":"out_of_credits","isUsingOverage":false,"unifiedWindows":{"five_hour":{"utilization":0.03,"resetsAt":1790305200},"seven_day":{"utilization":0.48,"resetsAt":1790784000}}}}

Tests:

  • Record mapping: fraction → percent (rounded), seconds → ms, reset times that overflow to Infinity or leave the Date range are dropped, malformed sibling windows, events without unifiedWindows.
  • Stream parser: emits the windows and still observes the session id; ignored outside the Claude dialect.
  • Runner entry point (executePreparedCliRun with a Claude stream on stdout): records under the host login, not under an OpenClaw-selected profile or a configured backend credential override. The recording rule also rejects other backends, paired nodes, account and endpoint variables (including lowercase spellings), settings arguments, and a different or skill-provided CLAUDE_CONFIG_DIR. It keeps recording for model selectors, OpenClaw's own Admin and key-rotation variables, and feature switches.
  • /status (buildStatusText): a host-login Claude Code session shows Usage: 5h 80% left from the store with no usage request; a session whose latest turn the runner kept off the host login (for example, a backend credential) does not show the row; a session whose run uses a stored Claude token profile shows the Anthropic row instead; a session whose agent model pins an API-key @profile does not show the Claude Code row. The runner test also checks the per-session verdict it notes. The selection helper passes the session pin, the configured @profile, and the Claude Code binding to the run's resolver. The /status tests fail without their fixes.
  • Models page: the Claude Code card is usage-only (no buttons, status badge, or credential line), and the Anthropic card keeps its own usage. The view test fails without the fix.
  • Store: expiry at reset, partial records keep the other windows and report the oldest observedAt, no recording of windows without a reset time or with one beyond the longest quota period (8 days), clear.
  • Formatting: /status summary and the usage report label observed rows as of ….
  • Control UI usage card: an observed row shows Observed 12m ago with the exact time on hover; a fetched row shows no age line.
  • Loader:
    • no Anthropic credential gives the Claude Code row;
    • the Anthropic row is kept unchanged beside the Claude Code row for a setup-token scope refusal, a timeout, an Admin API row, and fetched subscription windows;
    • no Claude Code row when Claude usage was not requested.
  • Usage cache: a cached window stops being served at its reset time and triggers a refresh before the TTL. A usage summary cached before the first Claude Code turn refreshes on the next read once that turn records windows. A newer reading of a window already shown waits for the normal TTL. The new test fails without the fix.
  • Usage cache timing: a window that resets while its refresh is still loading expires at its reset, and a timed-out refresh reports the timeout when every retained window has reset. Both fail without the fix.
  • Observed store: its window-set version changes only when a provider gains a window: the first observation, a new label, or the first window after a reset.

Test cost (pnpm test <file> --maxWorkers=1, vitest-reported, cold transform included):

File Duration Notes
provider-usage.observed.test.ts ≈0.3 s
cli-runner/observed-usage.test.ts ≈9.6 s 78% module transform of the runner harness; the three cases take ≈40 ms
cli-output-records.test.ts ≈0.8 s
cli-output-stream.test.ts ≈0.5 s
provider-usage.load.test.ts ≈24 s 90% module transform; the new cases are ≈0.2 s together
usage.status-cache.test.ts three new cases no timers
commands-status-claude-code-usage.test.ts ≈28 s 74% module transform of /status; the four cases take ≈6 s. A new sibling file because commands-status.test.ts is at its line cap
status-usage-entry.test.ts ≈8.7 s 73% module transform; the cases take <0.1 s

No sleeps or process boots.

Rebase (September 26): rebased onto main 5be36d37cb7 as 53f2ce20d0b. The only conflict was the upstream rewrite of the provider filter in provider-usage.load.ts (#158210); the Claude Code row block is unchanged and now precedes the new filter. git range-diff shows no other content change, so the proof above (captured on 127147da3e7) applies to this head. The focused suites were re-run on the rebased head: 161 tests passed.

September 26, 2036029ad1d: rebased onto main e518bd7310c (263 commits, no conflicts; git range-diff shows the earlier commits unchanged). The last three commits address ClawSweeper Revisions 6 and 7 and two rounds of our own adversarial review (responses below). All 20 test files the PR touches, plus the session-override suites the refactor reaches, pass: 382 tests. pnpm build passed. The live proofs above were captured on fa180453a67; the only change since is the /status session check below, which a host-login turn satisfies.

Checks: node scripts/check-changed.mjs passed (format, lint, core and core-test typecheck, UI typecheck, boundaries, line-cap ratchet, dead-export scan). pnpm ui:i18n:baseline reports no raw-copy drift. The Control UI usage and model-provider page suites pass (544 jsdom tests).

Review responses (ClawSweeper, September 25)
  • [P1] Bind observed windows to the setup-token account. Resolved by design. Claude Code's windows are no longer substituted into the Anthropic row under any condition. They are reported as the Claude Code row, which is the login that produced them. The Anthropic row, including a setup-token scope error, is left exactly as the Anthropic credential reports it.
  • [P2] Expire cached observed windows at their reset time. Fixed. The usage cache refreshes at the earliest window reset, and stale serves omit windows past their reset.
Review responses (ClawSweeper, second review)
  • [P2] Validate resetsAt after the millisecond conversion. Fixed. The parser keeps a reset time only when resetsAt * 1000 is finite and within the Date range. The store also refuses a reset time more than 8 days after the observation (the longest subscription window is 7 days), so a finite but far-future value cannot pin a window either. Tests cover both.
  • Login switch on the host. The Claude Code row now carries observedAt, the time its windows were reported, and /status shows it as as of …. A claude auth login switch still shows the previous login's windows until Claude Code's next turn, but the row no longer presents them as current. Docs say so.
Review responses (ClawSweeper, third review)
  • [P2] Show the observation age on the Control UI Usage card. Fixed. The shared usage card renderer (ui/src/components/provider-usage.ts), used by the Usage page and both Models settings surfaces, now renders Observed <relative time> under the windows whenever a snapshot carries observedAt, with the exact timestamp as a tooltip. Fetched snapshots are unchanged. A new English string usage.providerUsage.observed goes through the standard locale workflow. Covered by a card test for both states.
Review responses (ClawSweeper, fourth review)
  • [P2] Refresh cached usage when the first Claude Code windows arrive. Fixed in 127147da3e7. The observed store keeps a window-set version that changes only when a provider gains a window it did not have. Each cached usage summary records the version it was loaded against, read before the load starts, and a mismatch makes it stale. The next read refreshes as with an expired entry, and the Claude Code row appears as soon as that refresh finishes instead of after the 60 s TTL. Newer readings of windows already shown keep the normal cadence, so a busy agent does not re-query every usage provider after each turn. Covered by a usage.status cache test for the sequence "empty summary → first observation → row", which fails without the fix, and by a store test for when the version changes.
  • Control UI before-and-after screenshots. Added under Evidence: base versus head on the same isolated setup after a real Claude Code turn.
  • Login switch and security-sensitive approval. These remain maintainer decisions. The row shows its observation age everywhere it is rendered, and the Docs describe the login-switch behavior.
Review responses (ClawSweeper Revision 6, plus our own review)
  • [P2] Exclude configured Claude auth overrides before recording host usage. Fixed in 3a469d30f3b. Recording now fails closed: any ANTHROPIC_* variable in the child environment disables it except model selectors, OpenClaw's Admin API usage and API-key rotation keys, and Vertex project settings. Claude Code's own tokens, auth endpoints, and provider switches (checked against the Claude Code 2.1.280 binary) disable it too, matched case-insensitively. A runner-level test covers a configured backend env that re-adds ANTHROPIC_OAUTH_TOKEN.
  • Security: configured credential mislabeled as host usage. Same fix.
  • Our own review found more, all fixed with tests that fail without the fix:
    • The Models page merged the Claude Code row into the Anthropic card, replacing Anthropic's own usage. It is now a separate usage-only card.
    • /status only loaded usage for OAuth/token auth labels, so a host-login session (native (claude-cli)) never showed the row. It judged the account by the session pin alone. It now uses the run's own resolver, including the agent's configured @profile.
    • A skill-set CLAUDE_CONFIG_DIR passed the config-directory comparison. Recording now fails closed on it.
    • The usage cache could re-query every provider on every read for a window reported past its reset, and a timed-out refresh could publish an empty entry. Both fixed: reset refresh uses the load start time, and the timeout is kept when nothing valid remains.
  • Login switch and security-sensitive approval. Still maintainer decisions. The row shows its observation age everywhere it is rendered.
Review responses (ClawSweeper Revision 7)
  • [P2] Check backend account overrides before showing host quota. Fixed. /status cannot see a session's backend environment, settings arguments, config directory, or skill environment, so it no longer guesses. The runner already evaluates the recording rule on every Claude Code turn from the turn's real environment and arguments. It now also notes that verdict per session, and /status shows the host login's windows only when the session's latest Claude Code turn was admitted and the run's account resolver still selects no profile. A session with a backend credential override is therefore never shown the host's quota. The notes are process-local, bounded, and cleared with the observed windows. /status, helper, store, and runner tests cover it; the /status and helper tests fail without the fix.
  • Security: quota attributed to the wrong Claude account. Same fix.
  • Before-and-after UI images. They are hosted as commit-pinned raw.githubusercontent.com URLs on this fork's pr-157753-proof branch and return 200 image/png; the review's media manifest could not fetch them.
  • Login switch and security-sensitive approval. Maintainer decisions, unchanged.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

This external contributor PR changes sensitive security components. A maintainer must review these changes before merging.

Current SHA: afc713c7ddc671a0b135c4e6472815e0cb6126d7

These sensitive security changes were made:

  • src/agents/auth-profiles/configured-model-profile.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/session-override.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/server-methods/models-auth-status-usage-cache.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

After reviewing the changes, post a new PR comment containing only approval commands, each on its own line:

/allow-security-sensitive-change

A later push requires a fresh approval comment.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR captures Claude Code subscription windows from local agent output and displays them separately from Anthropic credential usage.

Example: A native Claude Code turn reports five-hour utilization of 0.56 and weekly utilization of 0.67.

  • Before: usage.status has no Claude Code subscription row.
  • After: A separate Claude Code row reports 44% and 33% remaining, with reset timestamps and observation time.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful production-path evidence supports the core repair, but the rebased UI defect, remaining proof coverage, and owner decisions prevent merge readiness.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Agents using native Claude Code subscriptions cannot see the subscription quotas consumed by their turns.
Reason: The reporting repair has demonstrated user value, but the public metadata addition and documented native-login attribution tradeoff require owner direction.

Merge readiness

⛔ Blocked before merge - 6 items remain

This PR addresses missing native Claude Code quota reporting that current main still lacks, but the rebased Models card loses its observation-age label and two new cache tests violate the repository’s no-polling rule.

Priority: P2
Reviewed head: afc713c7ddc671a0b135c4e6472815e0cb6126d7
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should the public ProviderUsageSnapshot contract expose optional observedAt metadata for runtime-observed quota windows?
  • Recommendation: Approve optional observation metadata: Adopt the documented epoch-millisecond field so shared consumers can distinguish observations from freshly fetched usage.
  • Why: The field is additive and useful, but it expands a public plugin SDK contract inside a bug fix without recorded owner approval.

Before merge

  • Add real behavior proof - The isolated Gateway trace and inspected screenshots establish native-turn quota capture, account separation, and the earlier Lit presentation; they do not establish the rebased Solid Models freshness display or Telegram-visible /status behavior, so supply focused screenshots or recorded output with credentials, phone numbers, IPs, and non-public endpoints redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Render observation age in the Solid Models usage card (P2) - The new Claude Code snapshot is assigned to a Models card here, but view.tsx renders it through components/solid/provider-usage.tsx, which neither accepts nor displays observedAt. Only the Lit renderer was updated. For a snapshot observed 12 minutes ago, Models shows quota bars without the promised freshness warning, including after an external login switch. Add the age label and timestamp tooltip to the Solid renderer and cover the actual Models rendering path.
  • Await owned cache refresh work instead of polling (P3) - The added first-observation test polls usage.status with vi.waitFor, and the timeout test adds another wait at line 369. These introduce timer-based polling despite the explicit AGENTS.md prohibition and the existing settledStatus helper that drains AsyncWorkScope. Replace both polling loops with awaited refresh settlement followed by a single response assertion.
  • Resolve merge risk - Before merge, the usage owner must accept that an external native-login switch can leave the previous account’s quota visible until Claude Code emits another rate-limit event.
  • Complete next step - Complete the repository-required security-sensitive review and approval for the final revision.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P2] Render observation age in the Solid Models usage card — ui/src/pages/model-providers/data.ts:359-364
  • [P3] Await owned cache refresh work instead of polling — src/gateway/server-methods/usage.status-cache.test.ts:333-335

Tests

  • Missing end-to-end proof: Supply current Models-page proof showing the observation age after the Solid repair and Telegram Test Server /status evidence for an admitted host-login session.
Agent review details

How this fits together

Claude stream-json records enter the agent runner, which admits host-login observations into process-local memory and supplies quota snapshots to Gateway usage responses, chat status, and UI cards.

flowchart LR
A[Claude Code output] --> B[Stream parser]
B --> C[Host login check]
C --> D[Observed quota store]
D --> E[Gateway usage cache]
E --> F[Usage and Models pages]
D --> G[Chat status]
Loading

Technical review

Best possible solution:

Keep native and Anthropic usage separate, show observation age in both UI renderers, and adopt an explicit observation contract.

Do we have a high-confidence way to reproduce the issue?

Current-main source discards quota events, and the contributor’s isolated Gateway trace demonstrates the missing-to-present usage row after a native Claude Code turn; no target code was executed during this review.

Is this the best way to solve the issue?

Observing the existing CLI stream preserves native credential ownership and supplies otherwise unavailable quota facts, but the Models renderer must consume the same freshness metadata as the Usage page.

Full review comments:

  • [P2] Render observation age in the Solid Models usage card — ui/src/pages/model-providers/data.ts:359-364
    The new Claude Code snapshot is assigned to a Models card here, but view.tsx renders it through components/solid/provider-usage.tsx, which neither accepts nor displays observedAt. Only the Lit renderer was updated. For a snapshot observed 12 minutes ago, Models shows quota bars without the promised freshness warning, including after an external login switch. Add the age label and timestamp tooltip to the Solid renderer and cover the actual Models rendering path.
    Confidence: 0.99
  • [P3] Await owned cache refresh work instead of polling — src/gateway/server-methods/usage.status-cache.test.ts:333-335
    The added first-observation test polls usage.status with vi.waitFor, and the timeout test adds another wait at line 369. These introduce timer-based polling despite the explicit AGENTS.md prohibition and the existing settledStatus helper that drains AsyncWorkScope. Replace both polling loops with awaited refresh settlement followed by a single response assertion.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 481813822c01.

Merge-risk options

Maintainer options:

  1. Accept explicitly aged observations (recommended)
    Accept the documented login-switch delay once every displayed Claude Code quota row includes its observation age.
  2. Defer the native usage row
    Pause the change until the usage owner settles how native-login changes should retire previously observed quotas.

Provenance checked

  • Native Claude authentication keeps the original intent (fix: keep Claude CLI authentication native #129052: Copied single-use refresh tokens caused repeated Claude CLI logouts, so Claude Code retained exclusive native-login ownership.)
  • Configured-model auth-profile selection keeps the original intent (6323935: Automatic chats should use activated credentials while preserving explicit account pins; the PR extracts the existing configured-model selection without changing precedence.)
  • Provider usage cache changes intended behavior with a stated reason (perf(gateway): prepare provider usage runtime #125520: Prepared credential facts and bounded provider refreshes removed expensive repeated work; the PR explicitly changes expiry to retire reset windows while preserving stale-while-revalidate ownership.)
  • Models provider-card aliasing changes intended behavior with a stated reason (feat(ui): Model Providers settings page with auth, quota, and cost per provider #104061: Provider aliases originally grouped one subscription into one card; the PR explains why independently owned Claude Code and Anthropic credentials require separate usage cards.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced changes: The pinned merge-base-to-head diff introduces the parser callback, host-login admission, observation store, separate usage row, cache expiry, and UI changes. (src/agents/cli-runner/execute-process.ts:139, afc713c7ddc6)
  • Current main still lacks the observation row: Current main returns credential-fetched provider snapshots without adding native Claude Code observations; its CLI parser has no rate_limit_event handling. (src/infra/provider-usage.load.ts:181, 481813822c01)
  • Models renderer misses observation age: Models imports the Solid usage renderer, whose accepted fields and rendered output omit observedAt; the PR adds the age label only to the Lit renderer. (ui/src/components/solid/provider-usage.tsx:13, afc713c7ddc6)
  • New polling waits have an existing completion alternative: The added cache tests poll usage.status at lines 333 and 369, while settledStatus already drains the refresh through AsyncWorkScope; root AGENTS.md prohibits new test polling. (src/gateway/server-methods/usage.status-cache.test.ts:333, afc713c7ddc6)
  • Contributor runtime and visual evidence inspected: The full PR body supplies an isolated Gateway native turn, resulting usage.status JSON, and chat.send /status output. Inspected commit-pinned screenshots show the Usage row and the earlier Models account separation, including observation age. The Models captures predate the Solid migration.
  • Native authentication boundary preserved: fix: keep Claude CLI authentication native #129052 established Claude Code’s exclusive ownership of native login and refresh; this PR reads emitted quota facts without copying or refreshing native credentials. Public docs: docs/providers/anthropic.md. (docs/providers/anthropic.md:65, 750a64e7cd4a)

Likely related people:

  • Peter Steinberger: Raw commit 8127bab adds ui/src/components/solid/provider-usage.tsx:13 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8127bab9d876; files: ui/src/components/solid/provider-usage.tsx)
  • Jesse Merhi: Raw commit 95f3ed9 adds ui/src/components/provider-usage.ts:13 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 95f3ed90285b; files: ui/src/components/provider-usage.ts)

PR surface

Source +629, Tests +1207, Docs +30. Total +1866 across 33 files. Added test files: 4.

View PR surface stats
Area Files Added Removed Net
Source 19 680 51 +629
Tests 12 1207 0 +1207
Docs 2 32 2 +30
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 33 1919 53 +1866

Review metrics

Metric Value Why it matters
Public usage contract 1 optional field: observedAt in epoch milliseconds Freshness metadata reaches the public plugin SDK snapshot type; no config option or persisted format is added.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The additive public usage field requires an owner decision about the supported SDK contract.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp. Replaced prior rating: 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • add proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The PR changes Telegram-visible /status quota text; Test Server userbot evidence should show the host-login quota and age while preserving other sessions’ provider usage.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P2: Missing subscription quotas affect one agent route while agent execution remains available.
  • merge-risk: 🚨 compatibility: The additive public usage field requires an owner decision about the supported SDK contract.
  • merge-risk: 🚨 auth-provider: A native-login switch can temporarily leave quotas attributed to the previously observed account.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp. Replaced prior rating: 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The PR changes Telegram-visible /status quota text; Test Server userbot evidence should show the host-login quota and age while preserving other sessions’ provider usage.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (8 earlier review cycles)
  • reviewed 2026-09-25T00:35:41.517Z sha b5eeec574db1d4ddd3688055613daebf4ac5158b :: blocked before merge. :: [P1] Bind observed windows to the setup-token account | [P2] Expire cached observed windows at their reset time
  • reviewed 2026-09-25T11:18:03.447Z sha afa4e0843de59612d0296ec9f7bdeaac2fa5c5f6 :: blocked before merge. :: [P2] Bound Claude reset timestamps before recording windows
  • reviewed 2026-09-25T12:37:10.998Z sha 3e3b3250bc8c2133f1fac10edd41c5a397da69ef :: blocked before merge. :: [P2] Show the observation age on the Control UI Usage card
  • reviewed 2026-09-25T19:32:06.475Z sha 75d0c7cd41fd4b71e19c7a4b4be9c9444fee6b0f :: needs real behavior proof before merge. :: [P2] Refresh cached usage when the first Claude Code windows arrive
  • reviewed 2026-09-25T23:59:05.238Z sha 127147da3e738666b15aba6e3f1dfa19b9b5efbf :: blocked before merge. :: none
  • reviewed 2026-09-26T02:03:46.875Z sha 53f2ce20d0b351a68943ea1dc96b51c4778b9e24 :: blocked before merge. :: [P2] Exclude configured Claude auth overrides before recording host usage
  • reviewed 2026-09-26T11:29:39.862Z sha fa180453a670af0b3098257d9c48a27b6d375f26 :: blocked before merge. :: [P2] Check backend account overrides before showing host quota
  • reviewed 2026-09-26T13:19:39.150Z sha 2036029ad1d52cceeab0281853d1c0e237b85a8c :: blocked before merge. :: none

Reviewed October 11, 2026, 12:03 PM ET / 16:03 UTC (Revision 9).

@8bitsforge 8bitsforge changed the title fix(usage): Claude subscription usage windows missing for claude-cli setups fix(usage): Claude Code subscription usage missing for agents running on claude-cli Sep 25, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Sep 25, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling extensions: anthropic size: L app: web-ui App: web-ui labels Sep 25, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 25, 2026
@8bitsforge
8bitsforge force-pushed the fix/claude-cli-usage-windows branch from 127147d to 53f2ce2 Compare September 26, 2026 01:55
@clawsweeper clawsweeper Bot removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 26, 2026
8bitsforge added a commit to 8bitsforge/openclaw that referenced this pull request Sep 26, 2026
@8bitsforge
8bitsforge force-pushed the fix/claude-cli-usage-windows branch from fa18045 to 2036029 Compare September 26, 2026 13:11
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 26, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 11, 2026
@8bitsforge
8bitsforge force-pushed the fix/claude-cli-usage-windows branch from 2036029 to afc713c Compare October 11, 2026 15:52
@8bitsforge

Copy link
Copy Markdown
Author

Refreshed onto current main (23ad242958a) so the PR isn't stale-closed. The PR's behavior is unchanged.

  • Rebase: the 8 commits are squashed into one, afc713c7ddc, because the first commit was an earlier approach that later commits rewrote. I resolved conflicts with recent main refactors: the CLI parser's subagent-progress hook, the event-target setup in execute-process, the refreshParams usage-cache shape, withTimeout in status-text, and the Tasks runtime removal (test setup only). The Models page usage-only card is ported from the removed view.ts to the Solid view.tsx.
  • Checked: main and v2026.10.5-beta.1 still don't parse rate_limit_event or report a Claude Code row, so this is not superseded.
  • Tests: the PR's own suites pass: CLI output records/stream, observed-usage, provider-usage observed/load/format, usage.status cache, status usage entry, /status Claude Code usage, and the UI provider-usage, Models data and view tests. Neighbouring session-override, commands-status, status-text, models-auth-status, usage, and cli-runner execute suites also pass.
  • pnpm check:changed: passes with OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1. That includes core, core-test, and UI typecheck, lint, format, and the ratchets. The dead-export scan does fail, but only on files this PR doesn't touch (extensions/telegram/src/bot-native-commands.runtime.ts, subagent-registry.store.sqlite.ts).
  • Review items: none were contributor-actionable. The login-switch attribution decision and exact-head security approval are maintainer calls, and this push needs a fresh approval. The linked before/after images still load (HTTP 200). They show the Models page as it looked before the Solid migration.

@VACInc

VACInc commented Nov 28, 2026

Copy link
Copy Markdown
Member

Closing as superseded by #207543, which restores live on-demand Claude CLI quota usage (including native-only Claude CLI setups) while keeping token refresh ownership with Claude Code.

@VACInc VACInc closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation extensions: anthropic gateway Gateway runtime merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-review-required security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants