Skip to content

fix(rate-limits): fall back to context_window for Claude usage on Vertex/proxy backends - #11760

Closed
YuSoeun wants to merge 1 commit into
stablyai:mainfrom
YuSoeun:fix/claude-statusline-context-window-fallback
Closed

YuSoeun wants to merge 1 commit into
stablyai:mainfrom
YuSoeun:fix/claude-statusline-context-window-fallback

Conversation

@YuSoeun

@YuSoeun YuSoeun commented Jul 31, 2026

Copy link
Copy Markdown

Summary

  • The managed Claude statusline script only forwarded the per-turn payload to Orca's agent-hook endpoint when it contained a rate_limits key, which Anthropic only includes in standard Claude.ai-subscription API responses.
  • Deployments routed through Vertex AI or an internal Anthropic-API-compatible proxy never receive rate_limits, so the live usage bar silently stopped updating even though the network itself was fine.
  • context_window is reported by every backend (computed locally from conversation length, not pulled from Claude.ai billing), so use it as a fallback session-usage source — both in the shell script's early-exit guard (POSIX case/Windows findstr) and in parseClaudeStatusLineBody — when rate_limits is absent.

Test plan

  • src/shared/claude-statusline-rate-limits.test.ts — added coverage for the context_window fallback and for rate_limits taking priority when both are present
  • src/main/claude/statusline-script.test.ts — updated the POSIX/Windows guard assertions and added a behavioral test confirming a context_window-only payload now reaches curl

…tex/proxy backends

The managed statusline script only forwarded Claude Code's per-turn payload
to Orca's agent-hook endpoint when it contained a "rate_limits" key, which
Anthropic only includes for standard Claude.ai-subscription API responses.
Deployments routed through Vertex AI or an internal Anthropic-API-compatible
proxy never receive that field, so the usage bar silently went dark even
though the network was fine.

context_window is reported by every backend (it's computed locally from the
conversation length, not pulled from Claude.ai billing), so use it as a
fallback session-usage source when rate_limits is absent.
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2d94e07a-bac0-4449-b838-632f755c940f

📥 Commits

Reviewing files that changed from the base of the PR and between d34bbd7 and 5830f67.

📒 Files selected for processing (4)
  • src/main/claude/statusline-script.test.ts
  • src/main/claude/statusline-script.ts
  • src/shared/claude-statusline-rate-limits.test.ts
  • src/shared/claude-statusline-rate-limits.ts

📝 Walkthrough

Walkthrough

The statusline scripts now recognize context_window as an alternative payload field to rate_limits on POSIX and Windows. Payloads with neither field remain inactive. The shared parser treats missing or invalid rate_limits as optional, uses context_window as a fallback five-hour window, and preserves rate_limits precedence when both fields are available. Tests cover the new forwarding and parsing behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and tests, but it omits the required Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections. Add all required template sections, including visual-change status, completed testing checks, AI review findings, security audit results, and platform-specific notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the context_window fallback for Claude rate-limit handling on Vertex and proxy backends.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes the live usage bar going dark for Claude Code sessions routed through Vertex AI or internal Anthropic-compatible proxies by widening the early-exit guard and the server-side parser to accept context_window as a fallback when rate_limits is absent.

  • Shell script guards updated (POSIX + Windows): The case/findstr pattern that previously allowed only "rate_limits" payloads through now also passes "context_window" payloads, so Vertex AI ticks reach curl and the Orca hook endpoint.
  • parseClaudeStatusLineBody extended: When rate_limits is missing or yields no usable windows, the function falls back to context_window.used_percentage and maps it into fiveHour; sevenDay remains null in this path (no 7-day billing concept on those backends).
  • Tests added: Behavioral integration tests confirm a context_window-only payload invokes curl exactly once, the old "no-rate-limits" exclusion test now also covers "no-context-window", and unit tests verify priority ordering and the empty-object guard.

Confidence Score: 5/5

Safe to merge — changes are additive, touch only the guard patterns and the parser fallback, and are covered by both unit and behavioral integration tests.

The fix is minimal and well-scoped: two OR-clauses added to shell guards (POSIX and Windows) and a small fallback branch in the TypeScript parser. The existing throttle, stamp, and curl machinery is unchanged. Tests confirm that a context_window-only payload reaches curl exactly once, that empty context_window returns null, and that rate_limits still takes priority when both keys are present. No pre-existing paths are altered in a way that could regress standard Claude.ai-subscription sessions.

Files Needing Attention: No files require special attention. The priority test in claude-statusline-rate-limits.test.ts only asserts fiveHour and leaves sevenDay unchecked when both keys are present, but the logic that drives it is correct.

Important Files Changed

Filename Overview
src/shared/claude-statusline-rate-limits.ts Core parser updated to try context_window fallback when rate_limits yields no windows; logic is sound, both empty-object and null rate_limits cases are handled correctly.
src/main/claude/statusline-script.ts POSIX case-pattern and Windows findstr guard widened to OR-include context_window; both changes are minimal and symmetric with the existing rate_limits guard idiom.
src/shared/claude-statusline-rate-limits.test.ts Good new coverage: empty context_window returns null, context_window-only populates fiveHour, rate_limits takes priority; minor gap — priority test does not assert sevenDay from rate_limits is preserved.
src/main/claude/statusline-script.test.ts Guard ordering tests updated and a new behavioral integration test confirms a context_window-only payload reaches curl exactly once; throttle behavior for context_window is implicitly covered by shared code path.

Sequence Diagram

sequenceDiagram
    participant CC as Claude Code (statusline tick)
    participant SH as statusline-script.sh / .bat
    participant ORCA as Orca agent-hook endpoint
    participant P as parseClaudeStatusLineBody

    CC->>SH: pipe JSON payload via stdin

    alt payload contains rate_limits OR context_window
        SH->>SH: pass guard (case / findstr)
        SH->>SH: check throttle stamp
        alt within min-post interval
            SH-->>CC: exit 0 (throttled)
        else interval elapsed
            SH->>ORCA: curl POST /statusline/claude
            ORCA->>P: parseClaudeStatusLineBody(body)
            alt rate_limits present and valid
                P-->>ORCA: fiveHour from rate_limits.five_hour, sevenDay from rate_limits.seven_day
            else rate_limits absent or invalid (Vertex AI / proxy)
                P-->>ORCA: fiveHour from context_window, sevenDay null
            end
            ORCA-->>SH: 200 OK
        end
    else no rate_limits or context_window
        SH-->>CC: exit 0 (skipped)
    end
Loading

Reviews (1): Last reviewed commit: "fix(rate-limits): fall back to context_w..." | Re-trigger Greptile

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Correction: the intended reference is the Claude context_window fallback. We consolidated this with #11766 and #11662 in canonical issue #17518 and will reimplement on current main. No contributor action is requested; your credit remains preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants