← Back to Pull requests

feat(agents): Claude Code's and OpenCode Go's usage limits (W36, D1301–D1305) #241

Open
unknown opened this pull request with 351 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 23, 2026 11:00 UTC
Author

Workstream W36 (round 4 of docs/plans/t3-roadmap.md), slice 1: Claude Code's and OpenCode Go's usage limits. Before this only Codex reported them. Decisions D1301–D1305 in docs/plans/providers.md ("Usage, accounts and the providers' rest (W36)"). The port follows T3 Code eb7b35ac: claudeUsageLimits.ts, the usage-limit classification in ClaudeAdapterV2.ts, and provider-opencode/usageLimits.ts.

What changes

  • D1301: Claude Code's status probe also reads the account's limits through the SDK's usage request, with skipBehaviors and a 4 s deadline. Rows: Session, Weekly, and "Weekly · {model}". An API key gives unsupported. A failed read gives probeFailed with the reason.

  • D1302: a turn's rate_limit_events are merged onto the last read, matched by window id. The overage-included bucket lands on the model-scoped row the read named.

  • D1303: a turn that a usage limit stopped throws UsageLimitError, using T3's rule: a 429; or a rejected window without overage, or an assistant rate_limit error, followed by a failed result. Its resetAt is the latest reset of the rejected windows. A gateway's 503 that wraps a 429 also counts. A full context window (blocking_limit with no rejection) still says the context is full.

  • D1304: agents.usage-limits reads Claude's limits again when they are a minute old, failed, or past a reset. /usage-limits now appears for Claude Code.

  • D1305: OpenCode Go's Session, Weekly and Monthly allowance, read with the Go key OpenCode signs in with (its auth file, or OPENCODE_API_KEY). Jhin keeps no copy of the key. There are none for a configured server, without a key, or on a 403.
  • The OpenCode and Claude Deferred lines are removed. What is left over (T3's mid-turn "paused until" notice, api_retry, events outside a turn, the Go credential fingerprint) goes into the new Deferred list.

    Evidence

    $ vp test run plugins/agent-claude/test/
     Test Files  10 passed (10)
          Tests  146 passed (146)
    
    $ vp test run plugins/agent-opencode/test/usage-limits.test.ts plugins/agent-opencode/test/status.test.ts
     Test Files  2 passed (2)
          Tests  18 passed (18)
    
    $ pnpm verify --affected
      ✓ check 4910ms
      ✓ typecheck 7039ms
      ✓ unit 29967ms
      ✓ knip 14456ms
      ✓ public-ids 1574ms
      ✗ e2e 697562ms
      ✓ pack 327727ms
    

    The local e2e run failed on a machine shared by ~20 threads, after 700 s. This PR has no UI change, so the e2e result is left to CI.

    The real usage request needs a signed-in Claude.ai account, which this machine does not have. It is proven against a scripted query that answers usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET and emits rate_limit_events. OpenCode Go is proven against a fake fetch.

    🤖 Generated with Claude Code

    Diff: 351 lines (+263 / -88) across 4 files Reviewer: claude[bot] Review duration: 8m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.47) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 351 lines diff across 4 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 99% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.351
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #241"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.5% (MEDIUM) · Higher = larger blast radius
    47.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.5% · Lower = rushed or shallow review
    46.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.4% · Safe to merge
    25.4%
    Repository