feat: add Daily Claude Token Usage Analyzer workflow#1605
Conversation
Mirrors the existing Copilot Token Usage Analyzer but focused on Claude/Anthropic-engine workflows (smoke-claude, secret-digger-claude, security-review, security-guard). Key differences from the Copilot analyzer: - Filters for provider=anthropic in token-usage.jsonl - Includes cache_write_tokens in analysis (Anthropic exposes this) - Adds cache write rate metric - Uses Anthropic pricing tiers (Sonnet/Haiku/Opus) - Separate skip-if-match label (claude-token-usage-report) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
There was a problem hiding this comment.
Pull request overview
Adds a new daily, provider-filtered token usage reporting workflow focused on Claude/Anthropic usage, mirroring the existing Copilot token usage analyzer pattern.
Changes:
- Introduces a Claude-specific token usage analyzer prompt (
.md) that downloadsagent-artifacts, parsestoken-usage.jsonl, filtersprovider: "anthropic", and instructs the agent to open a summary issue. - Adds the compiled gh-aw workflow (
.lock.yml) that runs on a daily schedule and produces the issue via safe-outputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| .github/workflows/claude-token-usage-analyzer.md | New analyzer prompt/instructions for collecting Anthropic-only token logs and producing a daily issue report. |
| .github/workflows/claude-token-usage-analyzer.lock.yml | Compiled gh-aw workflow implementing the daily scheduled run + safe-outputs issue creation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 1. **Total tokens**: `input_tokens + output_tokens + cache_read_tokens + cache_write_tokens` | ||
| 2. **Billable tokens**: `input_tokens + output_tokens + cache_write_tokens` (cache reads are discounted) | ||
| 3. **Input/output ratio**: `(input_tokens + cache_read_tokens) / output_tokens` (if `output_tokens == 0`, treat the ratio as `∞`/`N/A` and exclude that request from ratio averages to avoid division by zero) | ||
| 4. **Cache hit rate**: `cache_read_tokens / (cache_read_tokens + input_tokens) * 100` | ||
| 5. **Cache write rate**: `cache_write_tokens / (cache_read_tokens + input_tokens + cache_write_tokens) * 100` | ||
| 6. **Request count**: Number of records in the JSONL | ||
| 7. **Average latency**: Mean `duration_ms` per request | ||
| 8. **Model distribution**: Count of requests per model | ||
| 9. **Estimated cost** (use approximate rates): | ||
| - Anthropic Sonnet: input $3/M, output $15/M, cache_read $0.30/M, cache_write $3.75/M | ||
| - Anthropic Haiku: input $0.80/M, output $4/M, cache_read $0.08/M, cache_write $1/M | ||
| - Anthropic Opus: input $15/M, output $75/M, cache_read $1.50/M, cache_write $18.75/M |
There was a problem hiding this comment.
The prompt defines Billable tokens as input_tokens + output_tokens + cache_write_tokens, but later the estimated cost section assigns a non-zero rate to cache_read_tokens (discounted, not free). As written, the report will undercount billable usage for runs with cache hits. Consider either (a) including cache_read_tokens in the billable token definition (possibly with a discount factor), or (b) renaming this metric to something like “full-price tokens” and clearly separating it from discounted cache-read billing.
Smoke Test Results — Copilot Engine
Overall: PASS · PR by
|
|
Smoke Test Results — Run 23911242765 ✅ GitHub MCP — Last 2 merged PRs: #1603 fix: extract OpenAI/Copilot cached_tokens, #1593 fix: capture full session state Overall: PASS
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@copilot apply changes based on the comments in this thread |
… section Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/1ea1df07-9ddd-4b4d-a83e-db6ac24214bd Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Done in 76241ed. Renamed "Billable tokens" → "Full-price tokens" (with a note pointing to the Estimated cost section for the true billed amount), and updated the Estimated cost description to explicitly say "cache reads are discounted, not free" — so both sections are now consistent and no cache-read usage is silently dropped. |
|
Smoke test report (run 23911616574)
|
Smoke Test: GitHub Actions Services Connectivity
All 3 checks passed. (
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Summary
Adds a Claude-specific token usage analyzer workflow that mirrors the existing Copilot Token Usage Analyzer. Runs daily on a schedule, analyzes Claude/Anthropic-engine workflow runs, and creates a summary issue.
Target Workflows
smoke-claudesecret-digger-claudesecurity-review,security-guardagent-artifactsDifferences from Copilot Analyzer
copilotanthropictoken-usage-reportclaude-token-usage-reportKey Design Choices
provider: "anthropic"fromtoken-usage.jsonlcache_creation_input_tokens, enabling cache write rate analysis that the Copilot analyzer cannot do