anomalyco / anomalyco/opencode
V2: align Anthropic streaming usage aggregation with upstream SDKs
@rekram1-node is already working on this.
Since Aug 5, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Problem
The native Anthropic Messages parser currently normalizes usage independently on message_start and message_delta, then merges normalized Usage values. Anthropic usage is split across those events, and newer responses can include usage.iterations for compaction, message, advisor, and fallback inference.
This makes correct aggregation harder than it needs to be and risks losing or undercounting partial usage details. Vercel AI SDK instead accumulates raw Anthropic usage across stream events and normalizes once when message_stop arrives.
Follow-up scope
- Accumulate typed raw Anthropic usage in parser state across
message_startandmessage_delta. - Normalize once at
message_stoprather than merging partially normalizedUsageobjects. - Match Anthropic and AI SDK nullability for streamed usage fields.
- Define and test
usage.iterationsaccounting:- include executor
compactionandmessagework - keep
advisor_messageseparately attributable - avoid double-counting fallback responses
- handle cache-read and cache-creation counters consistently
- include executor
- Preserve the complete provider payload in
providerMetadata.anthropic. - Keep normalized
Usageinvariants intact when only partial counters are available.
Acceptance criteria
- Fixtures cover split start/delta usage, compaction, advisor, and fallback cases.
- Normalized totals match the current Anthropic/AI SDK semantics.
- No provider metadata has to be reparsed to reconstruct normalized usage.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.