Skip to content

Emit usage updates from Claude stream events#506

Open
Mng-dev-ai wants to merge 2 commits intoagentclientprotocol:mainfrom
Mng-dev-ai:fix/stream-event-usage-updates
Open

Emit usage updates from Claude stream events#506
Mng-dev-ai wants to merge 2 commits intoagentclientprotocol:mainfrom
Mng-dev-ai:fix/stream-event-usage-updates

Conversation

@Mng-dev-ai
Copy link
Copy Markdown

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 from ed5223a to 70a7a4c Compare April 5, 2026 02:05
@Mng-dev-ai Mng-dev-ai force-pushed the fix/stream-event-usage-updates branch from 70a7a4c to e656cc4 Compare April 5, 2026 02:10
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.

1 participant