#14483: fix(cli-runner): map Anthropic cache_creation_input_tokens
agents
stale
size: XS
Cluster:
Memory Management Enhancements
## Summary
- map `usage.cache_creation_input_tokens` to `cacheWrite` in `toUsage()`
- keep existing aliases (`cache_write_input_tokens`, `cacheWrite`) intact
- add a unit test for usage normalization to prevent regression
## Why
Anthropic reports cache creation usage under `cache_creation_input_tokens`. Without this mapping we under-report cache write tokens.
Closes #14366
## Validation
- [x] `npx pnpm build`
- [x] `npx pnpm check`
- [x] `npx pnpm exec vitest run src/agents/cli-runner/helpers.test.ts`
## AI assistance
- [x] AI-assisted
- Testing: locally validated with targeted and repo checks above
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the CLI runner’s usage normalization so that Anthropic’s `usage.cache_creation_input_tokens` is counted as `cacheWrite` (in addition to the existing aliases), and adds a small Vitest unit test to prevent regressions in the JSON parsing path.
The change is localized to `src/agents/cli-runner/helpers.ts`’s `toUsage()` normalization logic, which feeds `parseCliJson()` and therefore impacts how token usage is reported across CLI backends.
<h3>Confidence Score: 4/5</h3>
- This PR is low-risk and likely safe to merge after tightening the new test fixture to avoid type-unsafe configuration casting.
- The production change is a straightforward additional alias mapping in `toUsage()` and is covered by a targeted unit test. The main concern is the new test using an empty object cast to `CliBackendConfig`, which can hide future breaking changes to required config fields and reduce the test’s value.
- src/agents/cli-runner/helpers.test.ts
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#13895: fix(usage): exclude cache tokens from context-window accounting
by zerone0x · 2026-02-11
80.3%
#14488: Fix Telegram default account listing and CLI cache-write usage mapping
by abdulbb · 2026-02-12
79.6%
#22701: fix(reply): make usage footer reflect full turn usage and avoid tra...
by artwalker · 2026-02-21
74.4%
#13831: fix(agents): include Anthropic in tool call ID sanitization
by lailoo · 2026-02-11
73.3%
#17253: fix: propagate lastTurnTotal through usage accumulator for accurate...
by robbyczgw-cla · 2026-02-15
73.1%
#22387: fix: session_status context tracking undercount for cached providers
by 1ucian · 2026-02-21
73.0%
#19251: CLI: emit diagnostics for embedded Slack-context runs
by gg2uah · 2026-02-17
72.9%
#17560: fix: Anthropic Prompt Caching Not Working - Missing cache_control H...
by MisterGuy420 · 2026-02-15
72.5%
#13215: fix: pass agentId to loadCostUsageSummary in /usage cost command
by veast · 2026-02-10
72.5%
#4137: [AI-assisted] test(cli): add missing test cases for parseDurationMs
by sind00 · 2026-01-29
72.5%