Skip to content

incorrect context window % left in /status in oss mode #10858

Open

Description

@dkhokhlov

What version of Codex CLI is running?

codex-cli 0.98.0

What subscription do you have?

Team

Which model were you using?

gpt-oss:20b

What platform is your computer?

Ubuntu 22

What terminal emulator and version are you using (if applicable)?

No response

What issue are you seeing?

Incorrect ctx window "XX% left" in /status: "Context window: 89% left (14.9K used / 38K) ".

╭─────────────────────────────────────────────────────────────────────────────────╮
│  >_ OpenAI Codex (v0.98.0)                                                      │
│                                                                                 │
│ Visit https://chatgpt.com/codex/settings/usage for up-to-date                   │
│ information on rate limits and credits                                          │
│                                                                                 │
│  Model:                gpt-oss:20b (reasoning high, summaries off)              │
│  Model provider:       gpt-oss - http://x.x.x.x:11434/v1                        │
│  Directory:            /lib                                                     │
│  Approval:             never                                                    │
│  Sandbox:              danger-full-access                                       │
│  Agents.md:            ../AGENTS.md                                             │
│  Account:             xxxxxxx@xxxxxx (Team)                                     │
│  Collaboration mode:   Default                                                  │
│  Session:              019c3193-7aaf-70d0-a0b7-f13340366d63                     │
│                                                                                 │
│  Context window:       89% left (14.9K used / 38K)                              │
╰─────────────────────────────────────────────────────────────────────────────────╯

What steps can reproduce the bug?

  • ollama
    • version is 0.15.4
    • on macOS, M1 32GB
    • export OLLAMA_CONTEXT_LENGTH=40000
> ollama ps
NAME           ID              SIZE     PROCESSOR    CONTEXT    UNTIL
gpt-oss:20b    17052f91a42e    14 GB    100% GPU     40000      Forever
  • codex --oss
    • on Ubuntu
    • codex config:
model = "openai/gpt-oss-20b"
model_temperature = 0.0
model_context_window = 40000
model_reasoning_effort = "high"
model_verbosity = "medium"
model_reasoning_summary = "none"
model_supports_reasoning_summaries = false
model_provider = "ollama"
oss_provider = "ollama"
  • try to use context
  • /status

What is the expected behavior?

Correct percentage of context used.

Additional information

I suspect this also affects auto-compact.

Activity

  1. added
    custom-modelIssues related to custom model providers (including local models)
    TUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal display
    on Feb 6, 2026
  2. changed the title [-]incorrect context % left in /status in oss mode[/-] [+]incorrect context window % left in /status in oss mode[/+] on Feb 6, 2026
  3. dkhokhlov commented on Feb 6, 2026

    @dkhokhlov
    ContributorAuthor

    Findings:

    The status card's "XX% left" value comes from percent_of_context_window_remaining, which subtracts a 12,000-token baseline before calculating the percentage, creating an apparent mismatch with raw numbers

    The method computes an "effective" window by subtracting BASELINE_TOKENS (12,000) from both the total window and used tokens:

    • effective_window = context_window - 12,000
    • used = (tokens_in_context_window - 12,000).max(0)
    • percent = (effective_window - used) / effective_window * 100

    Why 89% left appears with 40K window and ~14.9K used

    With a 40,000-token window and ~14,900 tokens used:

    • Effective window: 40,000 - 12,000 = 28,000
    • Effective used: 14,900 - 12,000 = 2,900
    • Remaining: 28,000 - 2,900 = 25,100
    • Percentage: 25,100 / 28,000 ≈ 89.6% → rounded to 89%

    Looks like it needs to be fixed in UI and auto-compact.

  4. swma24 commented on Apr 8, 2026

    @swma24

    I can reproduce this in current Codex CLI and confirmed the root cause is a mixed metric in /status.

    Example observed output:

    • Context window: 99% left (14.5K used / 258K)

    Why this happens:

    • % left is computed on the effective context window (window - 12,000 baseline)
    • but used / window in the same line was shown with raw values

    So the line combines two different denominators, which makes it look incorrect.

    I prepared a fix that aligns both values to the same effective-window basis in the status card:

    • used -> effective used (total_tokens - 12,000, floored at 0)
    • window -> effective window (context_window - 12,000)
    • % left still uses the same baseline logic, now consistent with the displayed absolute values

    Patch branch (fork):

    Validation run locally:

    • just fmt
    • cargo test -p codex-protocol
    • cargo test -p codex-tui

    If useful, I can open an invited upstream PR from this branch.

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

    TUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal displaybugSomething isn't workingcustom-modelIssues related to custom model providers (including local models)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions