Skip to content

feat: add Daily Claude Token Usage Analyzer workflow#1605

Merged
lpcox merged 2 commits intomainfrom
feat/claude-token-usage-analyzer
Apr 2, 2026
Merged

feat: add Daily Claude Token Usage Analyzer workflow#1605
lpcox merged 2 commits intomainfrom
feat/claude-token-usage-analyzer

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented Apr 2, 2026

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-claude
  • secret-digger-claude
  • security-review, security-guard
  • Any other Claude-engine workflow with agent-artifacts

Differences from Copilot Analyzer

Feature Copilot Analyzer Claude Analyzer
Provider filter copilot anthropic
Cache write tracking Not available (OpenAI limitation) ✅ Full cache_write_tokens
Cache write rate metric N/A ✅ New metric
Pricing tiers OpenAI/Copilot rates Anthropic Sonnet/Haiku/Opus rates
Skip label token-usage-report claude-token-usage-report
Issue prefix 📊 Copilot Token Usage Report 📊 Claude Token Usage Report

Key Design Choices

  • Separate workflow (not combined) — keeps each focused and within the 15-minute timeout
  • Provider-filtered — only analyzes records with provider: "anthropic" from token-usage.jsonl
  • Cache write analysis — Anthropic uniquely exposes cache_creation_input_tokens, enabling cache write rate analysis that the Copilot analyzer cannot do
  • Anthropic pricing — uses Anthropic's published per-model rates including cache read/write discounts

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>
@lpcox lpcox requested a review from Mossaka as a code owner April 2, 2026 16:38
Copilot AI review requested due to automatic review settings April 2, 2026 16:38
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 85.86% 85.96% 📈 +0.10%
Statements 85.75% 85.84% 📈 +0.09%
Functions 86.66% 86.66% ➡️ +0.00%
Branches 78.49% 78.55% 📈 +0.06%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 86.1% → 86.5% (+0.40%) 85.6% → 86.0% (+0.39%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 downloads agent-artifacts, parses token-usage.jsonl, filters provider: "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.

Comment on lines +116 to +127
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
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Smoke Test Results — Copilot Engine

Test Result
GitHub MCP (last 2 merged PRs) #1603: fix: extract OpenAI/Copilot cached_tokens · #1593: fix: capture full session state
Playwright (github.com title) ✅ "GitHub · Change is constant…"
File write /tmp/gh-aw/agent/smoke-test-copilot-23911242767.txt created
Bash verify ✅ File read back successfully

Overall: PASS · PR by @lpcox · No assignees

📰 BREAKING: Report filed by Smoke Copilot for issue #1605

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Smoke Test Results — Run 23911242765

✅ GitHub MCP — Last 2 merged PRs: #1603 fix: extract OpenAI/Copilot cached_tokens, #1593 fix: capture full session state
✅ Playwright — github.com title contains "GitHub"
✅ File Write — /tmp/gh-aw/agent/smoke-test-claude-23911242765.txt created
✅ Bash — File contents verified

Overall: PASS

💥 [THE END] — Illustrated by Smoke Claude for issue #1605

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox
Copy link
Copy Markdown
Collaborator Author

lpcox commented Apr 2, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

@copilot apply changes based on the comments in this thread

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.

Copilot finished work on behalf of lpcox April 2, 2026 16:48
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Smoke test report (run 23911616574)
PR titles: "fix: extract OpenAI/Copilot cached_tokens from prompt_tokens_details"; "fix: capture full session state — replace blanket ~/.copilot mount, add --session-state-dir"
GitHub MCP last 2 merged PRs: ✅
safeinputs-gh pr list query: ❌ (tool unavailable)
Playwright title contains "GitHub": ❌ (Playwright MCP EACCES)
Tavily web search returned results: ❌ (tool unavailable)
File write/read test (/tmp/gh-aw/agent/smoke-test-codex-23911616574.txt): ✅
Discussion oracle comment: ❌ (discussion query tool unavailable)
Build (npm ci && npm run build): ✅
Overall status: FAIL

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Smoke Test: GitHub Actions Services Connectivity

Check Status
Redis PING (host.docker.internal:6379) ✅ PONG
PostgreSQL pg_isready (host.docker.internal:5432) ✅ accepting connections
PostgreSQL SELECT 1 (db: smoketest, user: postgres) ✅ returned 1

All 3 checks passed. (redis-cli was not installed; Redis was verified via raw TCP socket — port open, PING→PONG confirmed.)

🔌 Service connectivity validated by Smoke Services

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx All passed ✅ PASS
Node.js execa All passed ✅ PASS
Node.js p-limit All passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #1605 ·

@lpcox lpcox merged commit 5ed84e4 into main Apr 2, 2026
59 of 61 checks passed
@lpcox lpcox deleted the feat/claude-token-usage-analyzer branch April 2, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants