{"slug": "letting-astra-decide-when-to-compact-its-own-context", "title": "Letting Astra decide when to compact its own context", "summary": "Developer Manuel Cecchetto released codex-context-gc, an unofficial tool that exposes a compact_context function letting OpenAI's Codex desktop app compact its own context after a verified phase and continue work automatically. The tool runs on the original OpenAI-signed runtime via a Python adapter with no Rust build or app-bundle modification, and was tested on macOS with the ChatGPT.app bundle and bundled CLI 0.155.0-alpha.9, requiring Git and Python 3.9+. Cecchetto states the project is \"Unofficial; not an OpenAI product\" and was inspired by pi-context-gc.", "body_md": "Expose `compact_context` so the model can compact after a verified phase, before carrying old tool results into the next phase. Codex runs its native compaction, the complete model-authored checkpoint is appended, and work continues automatically.\n\nThe default desktop setup now uses the **original OpenAI-signed runtime** with a small Python adapter. No Rust build or app-bundle modification is required. Native compaction, checkpoint preservation, automatic continuation, and shell plus in-app browser access after compaction passed a live desktop test.\n\nUnofficial; not an OpenAI product. Inspired by [pi-context-gc](https://github.com/manuelcecchetto/pi-context-gc).\n\nInstall [https://github.com/manuelcecchetto/codex-context-gc](https://github.com/manuelcecchetto/codex-context-gc) for my local Codex desktop app. Follow README.md and INSTALL.md, use the signed-runtime adapter, check compatibility, and install the included compaction instructions while preserving my existing setup. Test it and give me the launch command. Don't quit my running app.\n\nTested on macOS with the `ChatGPT.app` bundle and bundled CLI `0.155.0-alpha.9`. The launcher checks the exact CLI version and OpenAI signing identity. Other versions and platforms need separate verification.\n\nRequires Git and Python 3.9+; keep the cloned repository in place.\n\n```\ngit clone https://github.com/manuelcecchetto/codex-context-gc.git\ncd codex-context-gc\npython3 stock_gc_launch.py --check\npython3 manage.py instructions install\n```\n\nThe instruction command preserves unrelated content in `$CODEX_HOME/AGENTS.md` (default `~/.codex/AGENTS.md`) and backs it up before changes. If you already have unmarked GC instructions, ask your agent to merge [AGENTS-snippet.md](https://github.com/manuelcecchetto/codex-context-gc/blob/main/AGENTS-snippet.md) into them.\n\nQuit the app normally, then launch from the repository:\n\n```\npython3 stock_gc_launch.py\n```\n\nFor a different app location, pass `--app /path/to/ChatGPT.app`. Start a **new task**: tasks created before installing the adapter do not automatically acquire the tool. Use this launcher on subsequent starts. It refuses to terminate an already running app and changes only the environment of the app it launches.\n\nAsk the new task to test `compact_context`, then verify shell and Codex in-app browser access after automatic continuation.\n\nUpdate the repository to `main`, run the check above, quit normally, and use `stock_gc_launch.py` instead of the previous launcher. Keep your existing GC instructions. No rebuild is needed; you may retain the old build for rollback. `manage.py install`, `manage.py launch`, and `manage.py doctor` are **legacy Rust-build commands**, not the default desktop setup.\n\n1. The model finishes and verifies a phase.\n2. It calls `compact_context` alone with useful working state, then ends the phase turn.\n3. Native lifecycle hooks coordinate compaction and insert the complete checkpoint before continuation.\n4. Work continues in a **new turn within the same task** . Active goals use Codex's own continuation scheduler.\n\nThe checkpoint is the tool-call arguments, separate from the native summary:\n\n```\n{\n  \"completed_phase\": \"Located and verified the bug\",\n  \"next_focus\": \"Implement the fix and run the regression test\",\n  \"keep\": [\"Objective, scope, constraints, relevant paths and findings\"],\n  \"verification\": [\"Regression test fails for the intended reason\"],\n  \"open_loops\": [\"Fix remains to be implemented\"],\n  \"ruled_out\": [\"Cache invalidation is not responsible\"]\n}\n```\n\nThe first four fields are required. There is no checkpoint byte cap, list-length cap, truncation, or compaction-count cap. JSON formatting is normalized and omitted optional lists become empty; supplied string values and list entries are preserved. Checkpoints are marked as model-authored state, not new user authorization. New user input cancels pending automatic continuation. Normal native automatic compaction remains enabled.\n\n[AGENTS-snippet.md](https://github.com/manuelcecchetto/codex-context-gc/blob/main/AGENTS-snippet.md) contains the phase-boundary instructions used in the author's workflow. There are no preset modes. Ask Astra to edit your instructions to prefer smaller verified phases for more frequent compaction, or major boundaries with substantial obsolete context for less frequent compaction. Keep unresolved investigations together.\n\nThese are model instructions, not token thresholds or guaranteed schedules. Rerunning `instructions install` restores the shipped wording, so avoid that after customization unless you want to reset it.\n\nThe original custom Rust binary caused `missing-code-signing-identity` failures in the desktop browser and app-tools bridges. The signed-runtime adapter preserves the original signed CLI and its desktop parent. It does not disable peer authorization, re-sign binaries, or modify the app bundle.\n\nLive verification on 2026-09-19 passed native compaction, automatic continuation, complete checkpoint preservation, and post-compaction shell and in-app browser access. A separate app-tools read also passed. See [SIGNED-RUNTIME.md](https://github.com/manuelcecchetto/codex-context-gc/blob/main/SIGNED-RUNTIME.md) for the implementation and validation details. The old build is retained under [LEGACY-RUST.md](https://github.com/manuelcecchetto/codex-context-gc/blob/main/LEGACY-RUST.md).\n\nThe 21-test suite includes real bundled-runtime tests with a localhost fixture provider: ordinary continuation, six compactions in an active goal, goal completion, and the desktop's configuration-argument ordering. These tests use an isolated home and make no paid model calls.\n\n```\nCODEX_GC_TEST_STOCK=/Applications/ChatGPT.app/Contents/Resources/codex \\\n  python3 -m unittest discover -s tests -v\n```\n\nThis remains experimental. Live desktop proof covers one end-to-end handoff, not every failure case or workflow. Crash recovery, forked-task inheritance, and broader failure recovery need further validation. A finished phase may display as interrupted during handoff. Checkpoints persist with owner-only permissions in `$CODEX_HOME/context-gc-checkpoints/` and may contain private task state. Native compaction and checkpoint insertion are not one atomic operation.\n\nProvider context limits still apply. Earlier compaction can discard useful information; large checkpoints consume context. Cost and quality gains are not guaranteed, and measurements from the original Rust patch are not benchmarks of this adapter.\n\nAn app update may change the bundled CLI. Do not bypass the version guard: ask your agent to adapt and test the adapter against the new protocol and hooks before changing the pinned version.\n\nQuit and reopen the app normally from Finder or the Dock. To remove the managed instruction block:\n\n```\npython3 manage.py instructions off\n```\n\nThis preserves your tasks, rollouts, and unrelated configuration. See [LICENSE](https://github.com/manuelcecchetto/codex-context-gc/blob/main/LICENSE) and [NOTICE](https://github.com/manuelcecchetto/codex-context-gc/blob/main/NOTICE) for licensing.", "url": "https://wpnews.pro/news/letting-astra-decide-when-to-compact-its-own-context", "canonical_source": "https://github.com/manuelcecchetto/codex-context-gc", "published_at": "2026-09-21 08:22:07+00:00", "updated_at": "2026-09-21 08:53:54.764361+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "large-language-models"], "entities": ["Manuel Cecchetto", "codex-context-gc", "OpenAI", "Codex", "ChatGPT.app", "pi-context-gc", "macOS", "Python"], "alternates": {"html": "https://wpnews.pro/news/letting-astra-decide-when-to-compact-its-own-context", "markdown": "https://wpnews.pro/news/letting-astra-decide-when-to-compact-its-own-context.md", "text": "https://wpnews.pro/news/letting-astra-decide-when-to-compact-its-own-context.txt", "jsonld": "https://wpnews.pro/news/letting-astra-decide-when-to-compact-its-own-context.jsonld"}}