Skip to content

Forward prompt-cache token usage for every agent that records it - #104

Merged
sagnik11 merged 1 commit into
mainfrom
autter/agent-cache-tokens
Nov 13, 2026
Merged

sagnik11 merged 1 commit into
mainfrom
autter/agent-cache-tokens

Conversation

@sagnik11

@sagnik11 sagnik11 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

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:

Agent Before After
Droid Token totals live only in <session>.settings.json; never sent Snapshot of tokenUsage (input, output, cache reads, cache writes, thinking) sent with the session's events
Continue CLI Session-level usage (incl. cachedTokens, cacheWriteTokens, totalCost) dropped; only history streamed Snapshot of the session total, with Continue's own cost
Copilot in VS Code (OTel) Cache writes only in the gen_ai.usage.cache_creation.input_tokens span attribute Also sent as span.cache_creation_tokens next to cached_tokens

The snapshot is one synthetic autter_usage_snapshot event, 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.md documents the convention and what each agent records.

Per-agent audit (now in docs/agent-usage.md)

  • Raw-forwarded with cache fields intact (now pinned by tests with real-shaped events): Claude Code (incl. 5m/1h write split), Codex (cached_input_tokens, cache_write_input_tokens), Gemini CLI (tokens.cached), Pi (cacheRead, cacheWrite, cacheWrite1h, cost), Amp (camelCase Anthropic usage), Copilot CLI (session.shutdown model metrics), OpenCode (tokens.cache.read/write, cost).
  • No usage data in transcripts or hook payloads: Cursor, Windsurf, Firebender, Antigravity, Kiro.

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: clean
  • cargo test --lib streams::: 253 passed
  • Integration (droid, continue_cli, event_timestamp, stream filters, daemon mode): 98 passed

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

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>
@sagnik11
sagnik11 merged commit ce11590 into main Nov 13, 2026
8 checks passed
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