Skip to content

Allow TokenBudget reminders with native summarizing compaction #36057

Open

Description

@shaswatshah

What variant of Codex are you using?

Codex CLI and Codex App (shared codex-rs/core behavior).

What feature would you like to see?

Allow TokenBudget reminders and fallback headroom to be used with native summarizing compaction.

Today Feature::TokenBudget couples two separate concerns:

  1. Model-facing context-budget policy: guidance, remaining-token reporting, an early reminder, and a fallback interval in which normal tools remain available.
  2. Rollover implementation: automatic and manual compaction skip model/server summarization and install a fresh context window.

I would like these concerns to be independent:

  • Keep TokenBudget guidance, get_context_remaining, the reminder threshold, fallback prompt, and fallback buffer.
  • When the automatic token limit is reached, use the normal remote/local summarizing compaction path.
  • Make manual /compact use normal summarizing compaction as well.
  • Keep an explicit new_context request as a summary-free fresh-window reset.

One motivating workflow is durable, bounded state alongside native compaction:

  1. About 5K tokens before automatic compaction, TokenBudget tells the active model to update a small external capsule containing durable decisions, invariants, and recovery-critical handles.
  2. The model writes that capsule using its existing tools while the full current context is still available.
  3. At the automatic limit, Codex performs native summarizing compaction.
  4. SessionStart(source = "compact") injects the small capsule alongside the native compacted history.

This lets native compaction preserve conversational continuity while an external store preserves a narrow, stable category of durable state. It avoids rescanning the transcript or maintaining a large handoff throughout the session.

PreCompact alone cannot implement this preparation phase: it runs immediately before compaction, receives no remaining-token budget or model-visible history, and cannot schedule an intermediate model turn. TokenBudget already provides the needed earlier model-facing signal; the missing capability is using that signal without replacing native compaction.

Additional information

This behavior is based on the current open-source implementation at commit 1c5f336c:

  • Automatic compaction takes the TokenBudget reset branch before selecting remote or local summarization: session/turn.rs.
  • Manual /compact has the same early TokenBudget branch: tasks/compact.rs.
  • The TokenBudget implementation explicitly skips model/server summarization and starts a fresh context window: compact_token_budget.rs.
  • new_context explicitly promises a new window without summarizing conversation history: new_context_window.rs.

Related but distinct requests:

This request does not require Codex to own the durable store or define a handoff schema. It asks only that TokenBudget's preparation policy be usable with the native compaction implementation, leaving external tools and hooks free to provide the optional durable complement.

Activity

  1. added
    enhancementNew feature or request
    CLIIssues related to the Codex CLI
    contextIssues related to context management (including compaction)
    on Jul 30, 2026
  2. boombx403-byte commented on Aug 18, 2026

    @boombx403-byte

    Hi @shaswatshah, that rollout size is valuable stress evidence. Codex Rescue Alpha5 scans large local session histories with bounded memory and produces aggregate size, media, and compaction diagnostics without loading the whole file into RAM or dumping full payloads.

    If you still have an affected closed rollout, you can test it locally:

    pip install codex-rescue==0.1.0a5
    codex-rescue doctor <path-to-rollout.jsonl>

    No raw session upload is needed; sanitized aggregate output is sufficient.

  3. waydec commented on Sep 18, 2026

    @waydec

    Adding a user request for the Codex desktop app on Windows: please make live context-window usage directly readable by the active agent in ordinary sessions, including when native summarizing compaction is used.

    In my current app session, I asked the agent whether it could read its context usage. It reported that no context-status tool was exposed to it; account rate-limit information is available but does not answer that question.

    The desired capability is a supported, read-only tool such as get_context_remaining, or equivalent model-visible metadata, reporting:

    • Current context tokens used and effective context capacity.
    • Remaining tokens and percentage used/remaining.
    • The automatic compaction threshold or usable headroom, when available.
    • Whether the values are estimates and when they were measured.

    This would let the agent answer questions about its current context, checkpoint work before compaction, size file reads and searches, and prepare handoffs based on actual headroom. The request is for reliable context visibility without requiring a switch to summary-free context resets.

    I can obtain this kind of context visibility in my Claude Code workflow and would like the equivalent in Codex. This request is specifically about the active context window, separate from five-hour/weekly account quotas and cumulative token consumption.

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

    CLIIssues related to the Codex CLIcontextIssues related to context management (including compaction)enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions