Repository navigation
Description
Hi Command Code team! 👋
We are working on first-class Command Code (cmd) usage analytics and rate-limit recovery integration for T3 Code (related to CommandCodeAI/command-code#1161 and pingdotgg/t3code#29353).
After auditing command-code@1.93.2 (cmd acp and ~/.commandcode/projects/*/*.jsonl) against T3 Code's UsageService, UsageLimitRecoveryWorker, and provider-acp adapter, we found three concrete integration points that would make Command Code work seamlessly with T3 Code (and other ACP hosts):
1. cmd acp PromptResponse.usage vs _meta.usage (Per-Turn vs Cumulative Session Usage)
In command-code@1.93.2 (promptResult(e, n) in dist/cli.mjs), session/prompt currently returns:
- Top-level
result.usage: cumulativesessionUsageacross all turns in the session ({ totalTokens, inputTokens, outputTokens, cachedReadTokens, cachedWriteTokens }). result._meta.usage: the actual per-turnturnUsage({ inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens }).
In T3 Code (acpPerTurnPromptUsage in packages/provider-acp/src/server/adapter.ts), the ACP adapter reads PromptResponse.usage expecting per-turn token counts (whereas session/update with sessionUpdate: "usage_update" carries cumulative session context/token usage). Because result.usage in cmd acp is cumulative across turns, multi-turn ACP sessions double-count earlier turns when result.usage is summed per turn.
Proposal:
- Either return per-turn usage in
PromptResponse.usage(with standard ACP keysinputTokens,outputTokens,cachedReadTokens,cachedWriteTokens,totalTokens) and emit cumulative session usage viasession/update(sessionUpdate: "usage_update"), or documentresult._meta.usage(cacheReadTokens/cacheWriteTokens) as the stable per-turn usage contract for ACP clients.
2. Local Session Transcript Contract (~/.commandcode/projects/<slug>/<sessionId>.jsonl)
T3 Code's UsageService (apps/server/src/usage/UsageService.ts) scans local provider transcript files incrementally by mtime + byte size to power the 30-day Settings → Usage dashboard (daily cost, model breakdown, cache hit ratio, latency).
Command Code's JSONL transcripts (type: "assistant" entries with messageId, sessionId, timestamp, model, provider, costUsd, durationMs, and usage) are already very close to what T3 Code needs. To rely on them without drift, could you confirm whether the following invariants in 1.93.2 are considered stable?
usage.inputTokensalready includesusage.cacheReadTokens + usage.cacheWriteTokens(consistent withtoSessionUsageincli.mjs), so uncached input ismax(0, inputTokens - cacheReadTokens - cacheWriteTokens).usage.cacheWriteTokens1his a subset ofusage.cacheWriteTokens(1-hour TTL cache creation vs 5-minute default), so total cache creation tokens isusage.cacheWriteTokens.costUsdon eachtype: "assistant"event is the authoritative per-turn USD cost computed byestimateCatalogCostUsd.
3. Live Rate-Limit Quotas (#1161) & Structured ACP Rate-Limit Reset Metadata
T3 Code has two features that depend on quota windows (5-hour rolling, weekly, monthly, and extra credits):
- Live Usage Limits UI (
ServerProviderUsageLimitsin Settings → Usage). - Automatic Rate-Limit Recovery (
UsageLimitRecoveryWorker), which automatically pauses a thread when a turn hits a usage limit and schedules an automatic resume atresetsAt.
Currently, external tools have to read ~/.commandcode/auth.json and call undocumented internal endpoints (/alpha/whoami?limits=1, /alpha/billing/credits, /alpha/billing/subscriptions, /alpha/usage/summary) or run a local CLIProxyAPI shim.
Proposal:
- Local quota snapshot (
#1161) or CLI subcommand: As proposed in #1161, writing the latest 5-hour / weekly / monthly window percentages andresetAttimestamps to~/.commandcode/usage.jsonafter each turn (or exposingcmd usage --json) would let T3 Code display live quota bars with zero extra API calls and without touching~/.commandcode/auth.json. - Structured ACP rate-limit error on
session/prompt: When a turn fails due to a 5-hour, weekly, or monthly limit incmd acp, including a machine-readableresetsAt(ISO-8601) and window identifier in the JSON-RPC errordata(e.g.,error.data = { kind: "usage_limit", window: "five_hour", resetsAt: "2026-..." }) would allow T3 Code to automatically pause and resume the agent turn as soon as the window resets.
Happy to test any changes or submit the corresponding adapter/usage PR on the T3 Code side!
Activity
ahmadbilaldev commentedon Nov 23, 2026
Taking a look