Skip to content

Add token usage measurement and reporting - #188

Merged
max-sixty merged 2 commits into
mainfrom
cost
Apr 8, 2026
Merged

max-sixty merged 2 commits into
mainfrom
cost

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Every tend run now measures token consumption and writes the result to three places:

  1. token-usage.json in the session log artifact — machine-readable, included automatically in the existing artifact upload
  2. GITHUB_STEP_SUMMARY — visible as a table in the Actions UI for every run
  3. token_usage action output — available to downstream steps/workflows

A new token-report.sh script aggregates across runs: downloads artifacts, reads the pre-computed JSON, and outputs a full report (per-run details + totals) to stdout with a human-readable per-workflow summary to stderr. The review-runs skill now calls this as Step 2 of its daily analysis.

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

Every tend run now parses session JSONL logs after Claude finishes and
writes a token-usage.json (included in session log artifacts) with
input, output, cache-creation, and cache-read token counts. The totals
are also written to GITHUB_STEP_SUMMARY and exposed as an action output.

A new token-report.sh script downloads artifacts from recent runs and
produces a JSON report (per-run breakdown + totals) to stdout with a
human-readable summary to stderr. The review-runs skill now calls this
as part of its daily analysis.

Co-Authored-By: Claude <[email protected]>

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jq -s (without -c) outputs pretty-printed multi-line JSON, which breaks the GITHUB_OUTPUT format — GitHub Actions only reads the first line after =, so token_usage ends up as { instead of the full object.

Comment thread action.yaml Resolved
jq -s outputs multi-line JSON, but GITHUB_OUTPUT only reads up to the
first newline. Pipe through jq -c to compact before writing.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 87f8ece into main Apr 8, 2026
5 checks passed
@max-sixty
max-sixty deleted the cost branch April 8, 2026 22:40
max-sixty added a commit that referenced this pull request Apr 8, 2026
Bumps generator version to 0.0.8 and syncs lockfile. The tag push triggers the PyPI release workflow.

1 commit since 0.0.7: token usage measurement and reporting (#188).

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

1 commit since 0.0.7: token usage measurement and reporting (#188).

> _This was written by Claude Code on behalf of maximilian_

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