codex icon indicating copy to clipboard operation
codex copied to clipboard

o4-mini: unusually high token count (71 k) for moderate-sized prompt – guidance?

Open lucasrod opened this issue 1 year ago • 2 comments

Codex CLI revision

v0.1.2504161551

Model

o4-mini

Platform

Darwin 24.4.0 arm64 arm

What I did

  • Called:
    codex "explain this repo" --files src/**/*.py
    
  • We were trying to update a README.md file for the project, documenting:
    • Which environment manager to use (UV, Conda, Pip/venv).
    • How to activate and deactivate the environments.
    • What is Typer and how to use it for the project CLI.
  • This involved several automated apply_patch calls that attempted to modify README.md, but many failed due to "Invalid Context" errors, leading to repeated retries and possibly additional hidden token accumulation.

Observed behaviour

  • Server reports:

    Rate limit reached … Limit 200000, Used 136502, Requested 71884
    

    → CLI claims the single request will add 71 884 tokens.

  • Session was closed abruptly due to rate limit exhaustion.

My questions

  • Why is the request perceived as nearly 72k tokens?
  • Is the CLI adding hidden system prompts, patches, retry traces or duplicating context?
  • Does o4-mini use a different tokenizer?
  • Any official tips to estimate tokens more accurately before sending?
  • To optimise prompts/files to stay within rate limits?

Additional information

  • The rate-limit error kills the session (see linked bug).
  • It would be helpful to receive guidance on:
    • How Codex CLI handles token accumulation during retries, patches, and parallel commands.
    • Best practices for budgeting tokens when working with --files, patches, and active project editing.

lucasrod avatar Apr 27 '25 00:04 lucasrod

  • The entire chat (including thinking) is processed in each request, as is necessary. In the case of high thinking models like o4, this means that each failed patch and the following thinking/re-attempt can add up to, say, 5k tokens to the next prompt. It adds up pretty fast.
  • The CLI does add a system prompt, but just once.
  • I don't believe so.
  • Unofficial tip: to conserve token count, it's best to do /compact or start new chats, after completing each individual task.

christophkogler avatar May 20 '25 22:05 christophkogler

Thank you for the detailed feedback! Please try the latest version of Codex CLI, as we're actively working on improving token handling and session management. If the issue persists, we'd appreciate a report on the codex-rs/ implementation. More details on our project update can be found here.

codex-maintainers avatar Aug 07 '25 17:08 codex-maintainers