Skip to content

feat: add token usage contributor hook#22485

Merged
jif-oai merged 1 commit into
mainfrom
jif/token-collab
May 13, 2026
Merged

feat: add token usage contributor hook#22485
jif-oai merged 1 commit into
mainfrom
jif/token-collab

Conversation

@jif-oai
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai commented May 13, 2026

Why

Extensions need a stable place to observe token accounting after Codex folds model-provider usage into the session's cached TokenUsageInfo. Without a contributor hook, extension-owned features that need last-turn or cumulative token usage have to duplicate session plumbing or infer state from client-facing TokenCount notifications.

What changed

  • Added TokenUsageContributor to codex-extension-api, passing session/thread ExtensionData, ThreadId, turn id, and the current TokenUsageInfo.
  • Added registry builder/storage support for token-usage contributors.
  • Invoked registered contributors from Session::record_token_usage_info after the session token cache is updated and before the client TokenCount notification is emitted.

Testing

  • Added record_token_usage_info_notifies_extension_contributors, covering cumulative token usage updates and access to both extension stores.

@jif-oai jif-oai requested a review from a team as a code owner May 13, 2026 12:21
@jif-oai jif-oai changed the title feat: token usage contributor feat: add token usage contributor hook May 13, 2026
@jif-oai jif-oai merged commit 083c196 into main May 13, 2026
27 checks passed
@jif-oai jif-oai deleted the jif/token-collab branch May 13, 2026 12:32
@github-actions github-actions Bot locked and limited conversation to collaborators May 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant