Codex subagent token statistics are missing and too low - CC Switch Fix
Quick fix
Upgrade to the latest code, where the parser derives a unique request ID from payload.id instead of session_id, so subagent usage lands in the database.
Symptom
Section titled “Symptom”CC Switch 能发现并解析子代理 JSONL 文件,但大部分子代理使用量没有成功写入数据库。因此,统计页面主要显示父线程的使用量,导致 Codex Token 和费用统计偏低。CC Switch can find and parse the subagent JSONL files, but most subagent usage is not written into the database successfully. So the statistics page mainly shows the usage of the parent thread, making the Codex token and cost statistics too low.
The subagent logs of newer Codex carry both payload.id (the unique identifier of the current thread) and payload.session_id (the parent thread ID) in the session_meta event. The existing sync logic wrongly prefers session_id when composing the request ID (in the format codex_session:{session_id}:{event_index}). Because event_index starts at 1 in every JSONL file, the main thread and every subagent under one parent thread generate exactly the same request ID.
The database insert uses INSERT OR IGNORE, which silently discards later records on a duplicate ID. Worse, the sync cursor still advances normally, so those discarded historical records cannot be recovered by resyncing. Separately, some startup events replay the total_token_usage accumulated by the parent thread, which double-counts unless the baseline snapshot is filtered correctly.
Update cc-switch to the main branch with the fix merged, or a later release, to enable the unique ID generation based on payload.id.
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 2 real issues
- How was this resolved?
- It is a defect in the parsing logic underneath, fixed by updating the cc-switch code. Update the tool to a version containing the fix and the statistics work again.
- Why is the earlier statistics gap not filled in automatically after upgrading?
- Because the sync cursor already advanced past the ID collisions, so the system considers those records processed. You have to trigger a targeted rebuild sync against the old JSONL files by hand to recover the lost data.
Related problems
Section titled “Related problems”This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.