Skip to main content

Module codex_usage

Module codex_usage 

Source
Expand description

The calls a Codex thread made, read from its session file for the per-task token ledger (docs/specs/SPEC_TOKEN_ANALYSIS_PER_KANBAN_TASK_2026_11_22.md section 4.2). codex exec --json reports only the thread’s running totals, so the ledger reads the calls from Codex’s own file (the one codex_context.rs finds), once each turn has exited.

The file is append-only, so a byte offset names a line for good: a call’s id is its thread and the offset its line starts at, and the offset read up to is kept per thread, so a turn reads only what it added. The ledger keeps each counted id, so reading a line twice (after a restart, which loses the offset) adds nothing; only lines made at or after the turn’s start count when there is no offset, so a restart does not count a thread’s history again.

One token_count event with a non-null info is one call, from its last_token_usage. Codex repeats an event when nothing ran between two of them: an event whose total_token_usage equals the last one’s is not a call. The model is the last turn_context before the event. Nothing but counts, a model name, a time and an offset is kept.