anthropics / anthropics/claude-code

Agent SDK: rate_limit_event already carries per-bucket unifiedWindows utilization at status=allowed — declare it in SDKRateLimitInfo and add a zero-token structured path (follow-up to #50518)

オープン
#91,857 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
area:agent-sdk enhancement
主要言語
Python
スター
145k
フォーク
23.1k
PR マージ指標
PR 指標を取得中

説明

## Summary

#50518 asked for per-bucket 5h/7d utilization for headless Agent SDK consumers and was auto-closed as inactive (and is now locked, so this is the follow-up it directs to). On the current CLI the data is already on the wire — but undocumented, and only reachable by spending a model turn.

## Environment

- Claude Code 2.1.259 (native install, linux-x64)
- `@anthropic-ai/claude-agent-sdk` 0.3.257 (bundled by `@agentclientprotocol/claude-agent-acp` 0.73.0)
- claude.ai subscription; utilization well below any warning threshold

## Observed

One turn into a fresh session (prompt: `Reply with the single word: done`), the `rate_limit_event`'s `rate_limit_info` — as the ACP adapter forwards it in `usage_update._meta["_claude/rateLimit"]`:

```json
{
"status": "allowed",
"resetsAt": 1788465600,
"rateLimitType": "five_hour",
"overageStatus": "allowed",
"overageResetsAt": 1790812800,
"isUsingOverage": false,
"unifiedWindows": {
"five_hour": { "utilization": 0.24, "resetsAt": 1788465600 },
"seven_day": { "utilization": 0.13, "resetsAt": 1789005600 }
}
}
```

- Top-level `utilization` is absent at `status: "allowed"`, exactly as #50518 described.
- `unifiedWindows` is present and populated at normal utilization — this looks like #50518's "Option A" per-bucket snapshot, shipped.
- `unifiedWindows` is not declared on `SDKRateLimitInfo` in `sdk.d.ts` (0.3.257), so typed consumers cannot rely on it (#26392 asked for these types to be documented).
- A session that only runs `/usage` (a local command; no API call) emits no `rate_limit_event`. A headless process that wants the numbers *without* spending a turn therefore has no structured source — `/usage` is rendered text.

## Asks

1. Declare `unifiedWindows` (with its per-bucket shape) on `SDKRateLimitInfo` and document it, so it is a contract rather than a wire observation.
2. A zero-token structured path: either a control request returning the current rate-limit snapshot (`getUsage()` is marked EXPERIMENTAL and is not exposed over ACP), or a machine-readable form of `/usage`.

## Why it matters

I run a usage-aware governor that seats sessions by 5h/7d headroom. Sessions launched over ACP (Zed) have no statusline, so today the only headless source is spawning the CLI and parsing `/usage` text hourly. It works, but it couples to UI wording; (1) plus (2) would replace it with a passive, structured source.

**Reproduction:** any ACP client — send one prompt and log `usage_update._meta["_claude/rateLimit"]`. Or via the SDK directly: log messages with `type === "rate_limit_event"` and inspect `rate_limit_info.unifiedWindows`.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start by locating SDKRateLimitInfo in sdk.d.ts and reviewing the rate_limit_event shape shown in the reproduction. Compare the existing getUsage() control request with the machine-readable /usage path, then determine how the unifiedWindows shape and zero-token source should be documented. Done means typed consumers can access per-bucket utilization and headless clients can obtain it without a model turn.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
api, cli
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。