Important
English: This repository is a personal fork of OpenAI Codex. The original Codex project is developed and maintained by OpenAI. The Adaptive Context Budget feature in this fork is developed and maintained by rhan637.
中文: 本仓库是 OpenAI Codex 的个人 Fork。Codex 原项目由 OpenAI 开发和维护;本 Fork 中的 Adaptive Context Budget (自适应上下文预算)功能由 rhan637 开发和维护。
Have you ever been deep into a complex Codex task, only to have repeated compactions interrupt the workflow just when the earlier context matters most?
This fork explores a more adaptive approach: start with a conservative soft context budget, then automatically expand it when the results of compaction show that the current budget is no longer sufficient for the task.
Instead of using one fixed automatic compaction threshold, Codex gains more room only when the task actually becomes complex—without bypassing the model's real context-window or catalog limits.
你是否遇到过这样的情况:Codex 正在处理一个复杂、长期的任务,却偏偏在最需要保留 前文信息时反复触发 compaction(上下文压缩),不断打断任务的连续性?
本 Fork 尝试提供一种更加自适应的解决方案:先从相对保守的软上下文预算开始;当压缩 后的实际占用表明当前预算已经不足以支撑任务时,再自动扩大预算档位。
它不再让 Codex 始终受制于一个固定的自动压缩阈值,也不会一开始就把预算拉到最大; 只有当任务真正变得复杂时,才为 Codex 提供更多上下文空间,同时仍然遵守模型真实的 上下文窗口和 catalog 上限。
Warning
The installation commands in the original OpenAI README install the official OpenAI release and do not include this fork's Adaptive Context Budget feature.
OpenAI 官方 README 中的安装命令安装的是官方版本,不包含本 Fork 的自适应上下文 预算功能。
git clone https://github.com/rhan637/codex.git
cd codex
git switch codex/local-dev
cd codex-rs
cargo buildComplete build requirements are available in the original installing and building guide.
完整的构建环境要求见官方安装与构建说明。
Add the following setting to your Codex config.toml:
在 Codex 的 config.toml 中加入:
[features.adaptive_context_budget]
enabled = trueThe feature is now enabled. All other settings are optional and use the following defaults when omitted:
这样就可以启用该功能。其他配置均为可选项;如果不填写,将采用以下默认值:
[features.adaptive_context_budget]
enabled = true
context_window_tiers = [272000, 487000, 872000]
keep_below_percent = 45
expand_at_or_above_percent = 65
ambiguous_compactions_before_expand = 2You can add and customize these optional parameters to define your own context-budget tiers and expansion policy.
你可以按需加入并修改这些可选参数,自定义上下文预算档位和升档策略。
272K → 487K → 872K
After an automatic compaction, Codex compares the remaining context with the current soft budget:
每次自动 compact 后,Codex 会比较剩余上下文与当前软预算:
-
Below 45%: keep the current tier.
低于 45%:保持当前档位。
-
From 45% to below 65%: expand after two consecutive results.
达到 45% 但低于 65%:连续出现两次后尝试升档。
-
At or above 65%: immediately attempt to expand.
达到或超过 65%:立即尝试升档。
The governor only expands to tiers supported by the current model and catalog.
Governor 只会升入当前模型和 catalog 实际支持的档位。
-
ADAPTIVE_CONTEXT_BUDGET_USAGE.md— complete configuration, usage, compatibility, and troubleshooting guide.完整的配置、使用、兼容性和故障排查说明。
-
ADAPTIVE_CONTEXT_BUDGET_DEVELOPMENT.md— implementation design, compaction flow, persistence, checkpoints, tests, and the complete changed-file list.实现思路、compaction 流程、持久化、checkpoint、测试和完整改动文件清单。
Codex CLI is a coding agent from OpenAI that runs locally on your computer.
If you want Codex in your code editor (VS Code, Cursor, Windsurf), install in your IDE.
If you want the desktop app experience, run
codex app or visit the Codex App page.
If you are looking for the cloud-based agent from OpenAI, Codex Web, go to chatgpt.com/codex.
Run the following on Mac or Linux to install Codex CLI:
curl -fsSL https://chatgpt.com/codex/install.sh | shRun the following on Windows to install Codex CLI:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"The standalone installers download from https://releases.openai.com/codex by default and fall back to GitHub Releases if a metadata or asset download is unavailable. To force GitHub Releases, set CODEX_INSTALLER_USE_RELEASES_OPENAI_COM to false (0 and no are also accepted):
curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_INSTALLER_USE_RELEASES_OPENAI_COM=false sh$env:CODEX_INSTALLER_USE_RELEASES_OPENAI_COM='false'; irm https://chatgpt.com/codex/install.ps1 | iexCodex CLI can also be installed via the following package managers:
# Install using npm
npm install -g @openai/codex# Install using Homebrew
brew install --cask codexThen simply run codex to get started.
You can also go to the latest GitHub Release and download the appropriate binary for your platform.
Each GitHub Release contains many executables, but in practice, you likely want one of these:
- macOS
- Apple Silicon/arm64:
codex-aarch64-apple-darwin.tar.gz - x86_64 (older Mac hardware):
codex-x86_64-apple-darwin.tar.gz
- Apple Silicon/arm64:
- Linux
- x86_64:
codex-x86_64-unknown-linux-musl.tar.gz - arm64:
codex-aarch64-unknown-linux-musl.tar.gz
- x86_64:
Each archive contains a single entry with the platform baked into the name (e.g., codex-x86_64-unknown-linux-musl), so you likely want to rename it to codex after extracting it.
Run codex and select Sign in with ChatGPT. We recommend signing into your ChatGPT account to use Codex as part of your Plus, Pro, Business, Edu, or Enterprise plan. Learn more about what's included in your ChatGPT plan.
You can also use Codex with an API key, but this requires additional setup.
This repository is licensed under the Apache-2.0 License.
