Emit log message with token usage when Codex is interrupted

Resolved 💬 5 comments Opened Jan 6, 2026 by amir-irregular Closed Feb 23, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What feature would you like to see?

When running Codex in autonomous mode, with codex exec --json, the program shows the token usage in the turn.completed event.

This appears only then Codex completed of its own accord, not when it was stopped from outside, e.g. due to timeout, or to machine shutting down. It's useful to get the token counts in these situations too.

Can you add a handler for the TurnAborted event that emits a log with the same usage field?

Additional information

_No response_

View original on GitHub ↗

5 Comments

etraut-openai contributor · 7 months ago

Thanks for the feature request. Can you describe your use case a bit more?

amir-irregular · 7 months ago

We are working on long tasks, and want to monitor costs. At some point we want to stop if the agent doesn't halt on its own.

If there's an alternative way to monitor costs we can use that too.

etraut-openai contributor · 7 months ago

Got it, thanks for the details.

You might be able to get the information you need from our recently-added OTel (OpenTelemetry) feature. You can read about it here.

amir-irregular · 7 months ago

Thank you! We'll look into that, it looks a lot more informative than the --json logs.

etraut-openai contributor · 6 months ago

This feature request hasn't received any upvotes, so I'm going to close it.