openai/codex · error · CodexErr

Codex ran out of room in the model's context window. Start…

Error message

Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying.

What it means

Typed category for an API context-window overflow: the request (history plus new input) no longer fits in the model's context window, so the model API rejects it. Unlike transient stream errors, the session loop will not auto-retry, because shrinking the context is required before any retry can succeed.

Solutions

  1. Start a new thread to reset the accumulated history
  2. Clear or compact earlier history before retrying the request
  3. Reduce the size of the current input (fewer files, shorter prompts)
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at codex-rs/protocol/src/error.rs:94 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/bf9d7cb3a25351e0. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/protocol/src/error.rs:94

#[derive(Error, Debug, EnumDiscriminants)]
#[strum_discriminants(name(CodexErrKind))]
#[strum_discriminants(derive(serde::Serialize))]
#[strum_discriminants(serde(rename_all = "snake_case"))]
#[strum_discriminants(doc = "The payload-free semantic category used for analytics.")]
pub enum CodexErrorDetails {
    #[error("turn aborted. Something went wrong? Hit `/feedback` to report the issue.")]
    TurnAborted,

    #[error("shared rollout token budget exhausted")]
    SessionBudgetExceeded,

    /// Returned by ResponsesClient when the SSE stream disconnects or errors out **after** the HTTP
    /// handshake has succeeded but **before** it finished emitting `response.completed`.
    ///
    /// The Session loop treats this as a transient error and will automatically retry the turn.
    #[error("stream disconnected before completion: {0}")]
    Stream(String),
    #[error(
        "Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying."
    )]
    ContextWindowExceeded,
    #[error("no thread with id: {0}")]
    ThreadNotFound(ThreadId),
    #[error("agent thread limit reached")]
    AgentLimitReached { max_threads: usize },
    #[error("session configured event was not the first event in the stream")]
    SessionConfiguredNotFirstEvent,
    /// Returned by run_command_stream when the spawned child process timed out (10s).
    #[error("timeout waiting for child process to exit")]
    Timeout,
    #[error("request timed out")]
    RequestTimeout,
    /// Returned by run_command_stream when the child could not be spawned (its stdout/stderr pipes
    /// could not be captured). Analogous to the previous `CodexError::Spawn` variant.
    #[error("spawn failed: child stdout/stderr not captured")]
    Spawn,

View on GitHub (pinned to 339751715c)