Repository navigation
Forward prompt-cache token usage for every agent that records it - #104
Merged
Merged
Conversation
Droid keeps its running token totals (with cache reads and writes) only in the <session>.settings.json next to its transcript, and Continue CLI keeps them at the top level of the session file, outside the history autter streams. Both readers now append one `autter_usage_snapshot` event (disjoint counts, running session totals, the agent's own cost when it has one) to the batch that reaches the end of the file; it does not move the watermark. Copilot Chat's OTel traces database keeps cache writes only in the `gen_ai.usage.cache_creation.input_tokens` span attribute; the span JSON now carries them as `cache_creation_tokens` next to `cached_tokens`. The other agents already carry their cache counts in the raw events autter forwards; tests now pin that for Codex, Gemini CLI, Pi, Amp, Copilot CLI and OpenCode with real-shaped events. docs/agent-usage.md lists what each agent records and the snapshot convention. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
AI spend has to include prompt caching for every agent. autter forwards most agents' session events verbatim, so their cache counts already reach the backend. Three agents' cache data did not:
<session>.settings.json; never senttokenUsage(input, output, cache reads, cache writes, thinking) sent with the session's eventsusage(incl.cachedTokens,cacheWriteTokens,totalCost) dropped; onlyhistorystreamedgen_ai.usage.cache_creation.input_tokensspan attributespan.cache_creation_tokensnext tocached_tokensThe snapshot is one synthetic
autter_usage_snapshotevent, appended to the batch that reaches the end of the file. It does not move the watermark. Its counts are disjoint (input excludes cache reads and writes,input_includes_cache: false) and are running session totals, so consumers diff them and never sum them.docs/agent-usage.mddocuments the convention and what each agent records.Per-agent audit (now in docs/agent-usage.md)
cached_input_tokens,cache_write_input_tokens), Gemini CLI (tokens.cached), Pi (cacheRead,cacheWrite,cacheWrite1h, cost), Amp (camelCase Anthropic usage), Copilot CLI (session.shutdownmodel metrics), OpenCode (tokens.cache.read/write, cost).Backend
The platform-side pricing and normalization is in Autter-dev/autter-monorepo#706. It reads the new fields and is backward compatible with older CLIs.
Tests
cargo clippy --all-targets -- -D warnings: cleancargo test --lib streams::: 253 passeddroid,continue_cli,event_timestamp,streamfilters, daemon mode): 98 passed🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.