Repository navigation
Record Codex token usage in cost tracking (SECFOO-37) - #21
Merged
vsn411 merged 1 commit intoOct 1, 2026
Merged
Conversation
codex exec prints its run total as a 'tokens used' line on stderr, but extract_usage() only ever saw stdout, so Codex runs showed 0 / '-' in secfoo cost and the dashboard. - base.py: add an extract_usage_from_stderr() hook, consulted only when extract_usage() finds nothing, so claude/gemini are unaffected. - codex.py: parse the last 'tokens used' total from stderr. Codex gives a single total with no split and no cost, so it is stored as input_tokens and cost stays unknown. - Tests for the parser and for the run() fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BnvD24nuxVRZF72ZGNT6Rx
3 of 4 tasks
5 tasks done
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Codex runs showed tokens as 0 / "-" in
secfoo costand the dashboard, even thoughcodex execreports usage: it ends stderr with atokens usedline followed by the run total.extract_usage()only ever receives stdout, so this was never read.Found during SECFOO-13 E2E testing (run
423e1d8a…: Codex used 15,201 tokens; secfoo recorded 0).What
base.py: newextract_usage_from_stderr()hook onAgentAdapter. It is only consulted whenextract_usage()finds nothing, so Claude/Gemini behaviour is unchanged.codex.py: parse the lasttokens usedtotal from stderr.input_tokens;output_tokensandcost_usdstayNone, so they show as "-".Tests
run()fallback in both directions.pytest tests/test_agents: 64 passed.test_web/test_activity_routes.py/test_architecture_dashboard.pyalso fail onmain@ eeb2d17 and are unrelated.Follow-up
A dedicated
total_tokenscolumn would be more accurate than usinginput_tokensfor Codex, but it needs a schema change, so it's out of scope here.Jira: SECFOO-37