feat: expose token usage as step outputs#83
Open
adamhenson wants to merge 3 commits intoopenai:mainfrom
Open
Conversation
… outputs Adds three new step outputs to codex-action: input-tokens, output-tokens, and cached-input-tokens. After codex exec completes, a new extract-token-outputs step reads the rollout JSONL written by the Codex CLI to $CODEX_HOME/sessions/, finds the last token_count event (cumulative totals), and surfaces the values as step outputs. Outputs are empty strings when token data is unavailable — non-breaking, existing workflows unaffected. Closes openai#65 Made-with: Cursor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Made-with: Cursor
Made-with: Cursor
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.
Closes #65
Summary
Adds three new step outputs —
input-tokens,output-tokens,cached-input-tokens— by reading the rollout JSONL thatcodex execalready writes to$CODEX_HOME/sessions/.Note on prior art: PR #62 attempted something similar by tee-ing stdout to a log file. A collaborator closed it with the suggestion:
This PR takes that approach — the Codex CLI already writes a structured JSONL rollout file to
$CODEX_HOME/sessions/YYYY/MM/DD/rollout-<timestamp>-<uuid>.jsonlas part of normal operation. The lasttoken_countline in that file contains the cumulative totals:{"type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":1234,"output_tokens":56,"cached_input_tokens":789}}}}We read that file, not stdout. No new CLI flags are needed.
What changed
src/extractTokenOutputs.ts— walks$CODEX_HOME/sessions/for the most recently modified.jsonl, scans for the lasttoken_countevent, sets the three step outputs via@actions/core. Exits silently if no file or token data is found.src/main.ts— newextract-token-outputsCLI command wired to the above.action.yml— three newoutputs:entries + a newextract_tokensstep that runs immediately afterrun_codex(sameif:condition).Outputs are empty strings when token data is unavailable (e.g.
unprivileged-userstrategy where the rollout may not be readable post-drop-sudo). Non-breaking — existing workflows are unaffected.Usage
Testing
npm run build && npm run checkpass cleanlynode dist/main.js --help | grep extract-token-outputs