Skip to content

exec resume: input_tokens grow by ~18K per turn regardless of message size (system prompt re-injected every resume) #16212

Closed

Description

@SwaroopMeher

Bug Report

Summary

When resuming a session with codex exec resume --last, the input_tokens count grows by approximately 18,000 tokens on every turn — regardless of how short the actual user message is. After 3 turns with single-sentence messages, the token count has tripled.

Steps to Reproduce

# Turn 1 — start a new session
echo "the cat said meow" | codex exec --json -

# Turn 2 — resume and ask a short follow-up
echo "what did the cat say?" | codex exec resume --last --json -

# Turn 3 — another short follow-up  
echo "and what was the cat's name?" | codex exec resume --last --json -

Observed Output (from turn.completed usage field)

Turn input_tokens Message length
1 18,080 ~5 words
2 36,197 ~5 words
3 54,341 ~6 words

Each turn adds ~18,000 tokens. The user messages are 5–6 words each (~10 tokens). The delta cannot be explained by conversation history alone.

Root Cause (from session JSONL)

Looking at ~/.codex/sessions/.../rollout-*.jsonl, the session file stores the system/developer instructions as response_item entries inline in the conversation history. When exec resume loads this file, it replays all stored items (including the system instructions) and then prepends a fresh copy of the system instructions for the new turn.

The result is that each resumed turn contains one additional copy of the full system prompt (~18K tokens) compared to the previous turn:

Turn 1 input: [system_instructions, user1]
Turn 2 input: [system_instructions_fresh, system_instructions_from_history, user1, assistant1, user2]  
Turn 3 input: [system_instructions_fresh, system_instructions_from_history×2, user1, assistant1, user2, assistant2, user3]

Expected Behavior

The system prompt should appear once per API call, regardless of how many turns have been resumed. A 3-turn conversation with short messages should cost roughly:

Turn 1: ~18K tokens
Turn 2: ~18K + message_delta (~100 tokens)
Turn 3: ~18K + message_delta (~200 tokens)

Not 3× the base cost.

Impact

  • Token usage grows linearly with number of resumed turns, not with conversation content
  • The repeated system prompt also breaks prompt caching — each turn has a different prefix so cached tokens from prior turns cannot be reused
  • Long sessions become disproportionately expensive

Environment

codex-cli 0.117.0
Windows 11 / x86_64
model: gpt-5.4 (reproduced, also gpt-4o-mini)

Activity

  1. SwaroopMeher commented on Mar 30, 2026

    @SwaroopMeher
    Author

    Closing to refile with the correct CLI bug template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions