[codex] Add context remaining tool - #27518
Merged
Merged
Conversation
pakrym-oai
marked this pull request as ready for review
June 11, 2026 02:47
Contributor
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a29a07eb8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| }; | ||
| let active_context_tokens = match invocation.session.token_usage_info().await { | ||
| Some(token_info) => token_info.last_token_usage.total_tokens, | ||
| None => invocation.session.get_total_token_usage().await, |
Contributor
There was a problem hiding this comment.
token_usage_info and get_total_token_usage
we are really good at naming
aibrahim-oai
approved these changes
Jun 11, 2026
pakrym-oai
force-pushed
the
pakrym/get-context-remaining-tool
branch
from
June 11, 2026 03:01
3a29a07 to
7926acc
Compare
…maining-tool # Conflicts: # codex-rs/core/src/context/token_budget_context.rs # codex-rs/core/src/session/turn.rs # codex-rs/core/tests/suite/token_budget.rs
…indow-tool # Conflicts: # codex-rs/core/src/session/turn.rs # codex-rs/core/tests/suite/token_budget.rs
… into pakrym/get-context-remaining-tool
…maining-tool # Conflicts: # codex-rs/core/src/tools/spec_plan.rs
pakrym-oai
enabled auto-merge (squash)
June 11, 2026 04:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The token budget feature can inject remaining-context notices into model-visible context, but the model does not have a direct way to ask for that same remaining-token fragment on demand.
This PR adds a small model tool for the token budget feature so the model can request the current remaining context window message without duplicating the fragment format.
What changed
get_context_remainingdirect-model tool behindFeature::TokenBudget.TokenBudgetRemainingContext, matching the existing budget message shape.new_contextin the token budget tool set.<token_budget>remaining fragment already present in context.Validation
just test -p codex-core token_budget