v2 Phase 4: Session screen — today's tokens and equivalent cost
Daemon: compute_today_usage() sums today's Claude Code token usage across the local project transcripts (~/.claude/projects/**/*.jsonl), reading only files modified today so the scan stays cheap, and prices it with Anthropic list rates to show the equivalent API cost (the ccusage-style flex for subscription users). The compact fields tk (total tokens), tc (cost in cents) and tn (message count) piggyback onto the existing 60s BLE payload. Firmware: UsageData gains tokens_today (64-bit) / cost_cents_today / messages_today; parse_json reads tk/tc/tn; a new Session screen shows the cost as the hero with total tokens and message count below, refreshed from ui_update so it's current whenever opened. Wire SCREEN_SESSION to the real screen (was a stub). Verified end to end: daemon sends e.g. tk=105374109 tc=26838 tn=663. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -9,4 +9,10 @@ struct UsageData {
|
||||
char status[16]; // "allowed" or "limited"
|
||||
bool ok; // data parse succeeded
|
||||
bool valid; // false until first successful parse
|
||||
|
||||
// Today's Claude Code usage (Phase 4 — computed by the daemon from local
|
||||
// transcripts). Tokens can exceed 2^31 on a heavy day, so use 64-bit.
|
||||
long long tokens_today; // total tokens today (input+output+cache)
|
||||
int cost_cents_today; // equivalent API cost today, US cents
|
||||
int messages_today; // assistant messages today
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user