Skip to content

feat: add cost estimate to token usage output - #249

Merged
max-sixty merged 1 commit into
mainfrom
usage-cost
Apr 11, 2026
Merged

max-sixty merged 1 commit into
mainfrom
usage-cost

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Read total_cost_usd from Claude Code's session JSONL type: "result" entry and surface it in token-usage.json, the step summary table, and token-report.sh. This also switches token extraction to use the result entry's aggregated usage instead of summing individual assistant messages — single jq pass, single source of truth.

token-report.sh reads cost_usd from each run's artifact (falls back to 0 for old runs without the field). Costs are rounded to 2 decimal places and formatted as $X.XX.

Footnote notes that cost reflects API list prices, which are a large multiple of the effective rate on Claude Code subscriptions.

This was written by Claude Code on behalf of @max-sixty

Read total_cost_usd from Claude Code's session JSONL result entry
and surface it in token-usage.json, step summary, and token-report.sh.
Also switch token extraction to use the result entry's aggregated
usage instead of summing individual assistant messages.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 13f0c0f into main Apr 11, 2026
5 checks passed
@max-sixty
max-sixty deleted the usage-cost branch April 11, 2026 20:28
tend-agent added a commit that referenced this pull request Apr 13, 2026
#249 switched the token-usage jq filter to `select(.type == "result")`, an
event type that claude-code-action's session JSONL does not emit. Every
`token-usage.json` since the merge has reported zero tokens — confirmed
across all 61 runs in the past 24h on this repo.

Restore the per-assistant-event aggregation from #188 and compute cost
from token totals × Claude Opus 4 list prices, since `total_cost_usd`
isn't available in this JSONL format.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
max-sixty added a commit that referenced this pull request Apr 14, 2026
Bumps generator version to 0.0.12 and syncs lockfile.

50 commits since 0.0.11: notifications cost cut + freshness gate (#251, #254),
token-report per-run table and cost estimate (#249, #250), review-reviewers
outcome-focused Haiku analysis (#255), config workflow_extra/jobs pass-through
(#227), canonical author_association tiers across skills (#261, #263), action
token aggregation fix (#266), plus numerous review/mention/ci-runner fixes.

Co-Authored-By: Claude <[email protected]>
@max-sixty max-sixty mentioned this pull request Apr 14, 2026
max-sixty added a commit that referenced this pull request Apr 14, 2026
Bumps generator version to 0.0.12 and syncs lockfile.

50 commits since 0.0.11. Highlights:
- feat: notifications cost cut + freshness gate (#251, #254)
- feat: token-report per-run table + cost estimate (#249, #250)
- feat: review-reviewers outcome-focused Haiku analysis (#255)
- feat: config `workflow_extra` / `jobs` pass-through (#227)
- skills: canonical `author_association` tiers (#261, #263)
- fix: action token aggregation (#266), plus numerous
review/mention/ci-runner fixes

> _This was written by Claude Code on behalf of Maximilian_

Co-authored-by: Claude <[email protected]>
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.

2 participants