Skip to content

fix: emit usage updates from Claude stream events#506

Merged
benbrandt merged 4 commits intoagentclientprotocol:mainfrom
Mng-dev-ai:fix/stream-event-usage-updates
Apr 16, 2026
Merged

fix: emit usage updates from Claude stream events#506
benbrandt merged 4 commits intoagentclientprotocol:mainfrom
Mng-dev-ai:fix/stream-event-usage-updates

Conversation

@Mng-dev-ai
Copy link
Copy Markdown
Contributor

Summary

  • emit ACP usage_update notifications from top-level Claude stream_event message usage
  • keep tracking a usage snapshot across message_start and message_delta so partial deltas still produce a complete total
  • preserve the existing result-path update as the final exact/cost-bearing usage event

Why

Claude SDK stream events already carry incremental usage on message_delta, but claude-agent-acp currently ignores that path and only emits usage_update from the final result. This makes usage appear stale until the turn ends in ACP clients that expect live context usage updates.

Verification

  • built the repo with npm run build
  • ran a direct ACP stdio client against the patched local build
  • observed usage_update notifications emitted before the final result-path usage update

Patched local smoke-test output included this sequence:

  • usage_update used=20973 size=200000
  • agent_message_chunk text=TEST_OK
  • usage_update used=20989 size=200000
  • usage_update used=20989 size=1000000 cost=0.1314875

@Mng-dev-ai Mng-dev-ai force-pushed the fix/stream-event-usage-updates branch 2 times, most recently from 70a7a4c to e656cc4 Compare April 5, 2026 02:10
@Mng-dev-ai
Copy link
Copy Markdown
Contributor Author

@benbrandt sorry for bothering you but just want to know if you're accepting PRs or not

@benbrandt benbrandt force-pushed the fix/stream-event-usage-updates branch from 2da047b to fc3232a Compare April 16, 2026 16:54
@benbrandt benbrandt changed the title Emit usage updates from Claude stream events fix: emit usage updates from Claude stream events Apr 16, 2026
@benbrandt benbrandt merged commit dd67450 into agentclientprotocol:main Apr 16, 2026
1 check passed
benbrandt pushed a commit that referenced this pull request Apr 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.29.1](v0.29.0...v0.29.1)
(2026-04-17)


### Bug Fixes

* emit usage updates from Claude stream events
([#506](#506))
([dd67450](dd67450))
* Remove dot from auto mode description
([#561](#561))
([2ecfa83](2ecfa83))
* Update to claude-agent-sdk 0.2.112 to fix Auto bug with Opus 4.7
([#562](#562))
([079614a](079614a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: acp-release-bot[bot] <246668977+acp-release-bot[bot]@users.noreply.github.com>
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.

2 participants