Skip to content

fix(claude-usage-report): price cache-writes at their actual TTL#8

Open
goneflyin wants to merge 3 commits into
mainfrom
fix/usage-report-cache-ttl
Open

fix(claude-usage-report): price cache-writes at their actual TTL#8
goneflyin wants to merge 3 commits into
mainfrom
fix/usage-report-cache-ttl

Conversation

@goneflyin

Copy link
Copy Markdown
Contributor

What

The claude-usage-report parser costed every cache-write token at the 5-minute TTL rate (1.25× input), ignoring the 5m/1h split that each transcript records in its cache_creation object. Most Claude Code cache-writes actually use the 1-hour TTL (2× input), so reports materially under-counted cache-write spend.

Impact on a real 16-day sample: the report read ~$509 when the TTL-correct figure was ~$599 — an $89 undercount, entirely Opus 1-hour cache writes.

Changes

  • usage_report.py — read ephemeral_5m_input_tokens / ephemeral_1h_input_tokens per message and cost each at cw / cw_1h. Falls back to the combined cache_creation_input_tokens (as 5m) for legacy transcripts, and to 2× input when a price record omits cw_1h. Also fixes a token double-count in the per-session total that the new fields introduced. RATES output now prints both cache-write columns.
  • prices.json — add explicit cw_1h (= 2× input) to the models that lacked it; document the field in the header comment.
  • SKILL.md — add the 1h column to the reference table and replace the stale "assumes 5-minute TTL" caveat.

Notes

Branched off fix/marketplace-source-format (PR #7), so until that merges this PR's diff also contains the marketplace-source fix.

🤖 Generated with Claude Code

goneflyin and others added 3 commits July 16, 2026 19:33
A plugin entry that combined a bare relative-string source
("./skills/claude-usage-report") with a skills array ([".") tripped
Claude Code's plugin resolver into its default: throw, surfaced as a
misleading "update Claude Code" error. Switch to the git-subdir object
form used by other skill-bearing marketplaces.

After merge, re-pull with `/plugin marketplace update 7factor` (the
local marketplaces copy is a cache).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…yout

The git-subdir source from the prior attempt made the plugin resolver
throw its generic "source type your Claude Code version does not support"
error, even on the latest Claude Code (2.1.212). That message is a
misleading catch-all the resolver emits when it can't process an entry.

Two coupled problems were feeding the throw:
1. the `git-subdir` object source, and
2. `skills: ["."]`, which trips the "Path escapes plugin directory"
   loader bug (same issue nicobailon/visual-explainer hit).

`skills: ["."]` existed because SKILL.md sat at the plugin root, so the
default `skills/` scan found nothing. Fix both by matching the
conventional layout:

- move the skill (SKILL.md + usage_report.py + update_pricing.py +
  prices.json) into skills/claude-usage-report/skills/claude-usage-report/
  so the default scan finds it; drop the `skills` field entirely.
- set the plugin source to the plain relative path
  "./skills/claude-usage-report" (the original, universally-supported
  form; resolves against the cloned marketplace repo).

record_account.sh/.py, hooks/hooks.json, and .claude-plugin/plugin.json
stay at the plugin root, so ${CLAUDE_PLUGIN_ROOT}/record_account.sh and
the existing settings.json hook path keep working.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The parser costed every cache-write token at the 5-minute TTL rate
(1.25x input), ignoring the 5m/1h split that each transcript records in
its `cache_creation` object. In practice most Claude Code cache-writes
use the 1-hour TTL (2x input), so reports under-counted materially — a
16-day sample came out ~$509 when the TTL-correct figure was ~$599.

- usage_report.py: read `ephemeral_5m_input_tokens` /
  `ephemeral_1h_input_tokens` per message and cost each at `cw` / `cw_1h`;
  fall back to the combined field (as 5m) for legacy transcripts, and to
  2x input when a price record omits `cw_1h`. Fix a token double-count in
  the per-session total introduced by the new fields. RATES output now
  shows both cache-write columns.
- prices.json: add explicit `cw_1h` (= 2x input) to the models that
  lacked it; document the field in the header comment.
- SKILL.md: add the 1h column to the reference table and replace the
  stale "assumes 5-minute TTL" caveat.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@goneflyin
goneflyin force-pushed the fix/usage-report-cache-ttl branch from 127f4bb to 955f4f6 Compare July 17, 2026 02:12
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