mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
05bc14e82b
The local session-log scanner dropped any assistant message that lacked a stop_reason or had output_tokens==0. Claude Code Workflow / sub-agent fan-out frequently produces messages that only wrote a message_start snapshot (output=1, stop_reason=None) without a final block, yet their input + cache_read + cache_creation tokens are already billed by Anthropic (charged once the request is accepted). Dropping them under-counted usage by ~4.1% overall, 92% concentrated in workflow/subagent transcripts. Replace the stop_reason/output gate with a billable-token check (any of input/output/cache_read/cache_creation > 0). The per-message-id dedup selection is unchanged, and request_id = "session:"+msg_id PRIMARY KEY with INSERT OR IGNORE keeps each message single-inserted, so relaxing the gate cannot double-count. Add a regression test covering a stop_reason-less message with real cache cost plus an all-zero skip. This is the parser-layer half of the Workflow under-counting fixed at the collector layer in 8d332925.