-
Notifications
You must be signed in to change notification settings - Fork 103
Description
Problem
The ccusage integration in the Claude plugin causes extreme delays (60-130 seconds) on machines with significant Claude Code conversation history. The actual API usage data (Session/Weekly %) is ready in ~300ms, but users must wait over a minute because the probe blocks on ccusage completing.
Root Cause
ccusage scans all files regardless of date filters. The --since/--until flags are post-processing filters applied after every file has been read, parsed, and cost-calculated. A single-day query takes the same ~37s as a full scan.
Sequential runner fallback compounds the problem. When ccusage exceeds the 15s timeout, OpenUsage tries 4 runners sequentially (bunx → pnpm dlx → npm exec → npx), each timing out independently: 4 × ~32s = 129s total.
Timing Breakdown (from detailed plugin logging)
| Phase | Duration |
|---|---|
| Credentials (keychain) | 44ms |
| Token refresh check | skipped (not expired) |
| Usage API fetch | 296ms |
| ccusage (all 4 runners timed out) | 129,092ms |
| Total probe time | 129,433ms |
Machine Details
- Apple M2 Pro, 32 GB RAM, macOS 15.6
- 4,637 JSONL files in
~/.claude/projects/ - 572 MB total (largest single file: 469 MB - enormous but it may happen)
- Files modified today: 12 (17 MB)
- Files modified in last 7 days: ~200 (199 MB)
- Files modified in last 30 days: 3,618 (~500 MB)
Log Evidence
[plugin:claude] [probe] ====== CLAUDE PROBE START ======
[plugin:claude] [cred] loaded from KEYCHAIN, token expires in 16198s, total=44ms
[plugin:claude] [probe] token needsRefresh=false
[plugin:claude] [usage] response: status=200 in 296ms
[plugin:claude] [ccusage] starting query since=20260128
[plugin:claude] ccusage query via bunx — timed out after 15s
[plugin:claude] ccusage query via pnpm dlx — timed out after 15s
[plugin:claude] ccusage query via npm exec — timed out after 15s
[plugin:claude] ccusage query via npx — timed out after 15s
[plugin:claude] [ccusage] query returned: status=runner_failed in 129092ms
[plugin:claude] [probe] ====== CLAUDE PROBE DONE in 129433ms ======
--
Upstream Fix
I've submitted a PR to ccusage with 3-layer early date filtering (file-level mtime pre-filter + line-level substring pre-check + entry-level date skip): ryoppippi/ccusage#869
This reduces single-day queries from ~37s to <1s and full scans from ~37s to ~32s on the same machine.
Suggested OpenUsage Improvements
Even with the upstream fix, OpenUsage could improve resilience:
- Return API data immediately, ccusage data async — don't block the entire probe on ccusage
- Cache ccusage results — past days are immutable, only "today" changes
- Fail fast on runner timeout — if the first runner times out, don't try 3 more
- Remember working runner — cache which runner succeeds to avoid re-discovery
Additional Context
Related to #19 (costs for providers via ccusage).