# Codex Idle Resume **Return control to the same macOS Codex Computer Use turn after a brief human takeover.** [简体中文](README.zh-CN.md) · [Report a bug](https://github.com/yaro-elipox/codex-idle-resume/issues) > [!WARNING] > Experimental, unofficial community project. It relies on Codex following global `AGENTS.md` instructions after a Computer Use action returns a local-input interruption. ## The problem When a person moves the pointer, types, or changes a controlled window, Computer Use correctly yields control. In current Codex Desktop builds, the interrupted UI action can return an error to an agent whose turn is still alive. Without a recovery rule, the agent may stop instead of continuing after the person walks away. This is especially awkward in long Goal/orchestrator workflows: a parent task may keep waiting while a worker has abandoned an unfinished UI step. ## What it does The installer adds a clearly delimited rule to the current user's global Codex `AGENTS.md`. When Computer Use reports a temporary local takeover, the same Codex turn: 1. runs a local idle-gate helper; 2. waits until mouse and keyboard input have been continuously idle for the configured interval; 3. refuses to hand back while the Mac is locked; 4. re-observes the target app instead of reusing stale coordinates; 5. continues from the first unfinished UI action. ```text Computer Use action ↓ local user changes pointer/keyboard/window ↓ same Codex turn runs the idle gate ↓ continuous physical-input idle for 5 seconds ↓ re-observe the app → continue unfinished action ``` Every new input event resets the operating system's idle clock. If you interact at second 4 and again at second 9, hand-back occurs about five seconds after the second interaction—not at second 5 or 10. ## Real end-to-end validation Version 0.2.0 was validated on August 26, 2026 with a real Codex Desktop Computer Use takeover on macOS: - Codex began five visible, pointer-driven Calculator rounds. - The user moved the pointer after two completed rounds. - Computer Use returned the observed `The user changed ...` interruption. - The same Codex turn passed the five-second physical-input idle gate. - Codex re-read Calculator, confirmed two completed rounds, and completed the remaining three. - Final evidence: `completed_rounds=5` and Calculator displayed `1 + 2 = 3`. Unit tests also cover timer reset, screen-lock blocking, disabled configuration, and invalid timeouts. This validates the tested build and signal; it is not a guarantee that future Codex releases will preserve the same behavior. ## Background and novelty claim Before the initial release on **August 26, 2026**, the maintainers searched public GitHub repositories and code, public `openai/codex` issues, official OpenAI documentation, and the adjacent projects below. That search did not find another publicly documented open-source project aimed at this exact Codex Desktop chain: physical takeover, continuous idle detection, fresh UI observation, and automatic continuation of the unfinished Computer Use action in the same agent turn. **On that evidence, Codex Idle Resume appears to be the first publicly documented open-source implementation of this specific automatic hand-back behavior for Codex Desktop Computer Use.** This is intentionally evidence-scoped. It cannot cover private, unpublished, or unindexed work. “Codex Desktop” is also deliberate: OpenAI uses [Codex IDE extension](https://learn.chatgpt.com/docs/codex/ide) for VS Code, Cursor, and Windsurf integrations; this project targets [Computer Use in the desktop app](https://learn.chatgpt.com/docs/computer-use). ## Why version 0.2.0 changed architecture The original 0.1.x prototype watched Codex session records and attempted `codex exec resume` after the interrupted turn ended. Real testing disproved that approach for the intended outcome: the external CLI process exited with code 1 and, even if it had succeeded, a CLI continuation was not proof that the app-owned Computer Use runtime would resume pointer control. Version 0.2.0 removes that path. It does not start a second Codex process and does not claim to revive a completed Desktop turn. It keeps the already-running turn alive, waits locally, re-observes, and continues. ## Safety and privacy - No background daemon or LaunchAgent is required. - No Codex session or conversation files are read. - The idle helper makes no network requests and does not call a model. - Waiting consumes elapsed time but no model tokens; normal reasoning and resumed Computer Use calls consume usage normally. - The helper reads only macOS input-idle duration and screen-lock state. - The managed global instruction says never to reuse stale coordinates or bypass confirmations. - An explicit request to cancel or stop is not treated as a temporary takeover. - Upgrading from 0.1.x stops and backs up the obsolete LaunchAgent. ## Requirements - macOS - Codex Desktop/ChatGPT Desktop with the Computer Use plugin enabled - Python 3 at `/usr/bin/python3` - Screen Recording and Accessibility permissions required by the [official Computer Use documentation](https://learn.chatgpt.com/docs/computer-use) ## Install Clone the repository, inspect the scripts, then run: ```bash ./install.sh ``` The installer: - installs the helper and configuration under `~/Library/Application Support/CodexIdleResume/`; - adds one managed block to `$CODEX_HOME/AGENTS.md` or `~/.codex/AGENTS.md`; - preserves all instructions outside that block; - disables an obsolete 0.1.x LaunchAgent if present. Start a new Codex task after installation so the global instruction is loaded. A task that was already running before installation may not have read the new `AGENTS.md`. ## Status and configuration ```bash /usr/bin/python3 \ "$HOME/Library/Application Support/CodexIdleResume/codex_idle_resume.py" \ --status ``` Configuration lives at: ```text ~/Library/Application Support/CodexIdleResume/config.json ``` | Setting | Default | Meaning | | --- | ---: | --- | | `enabled` | `true` | Enable or fail closed on hand-back | | `idleSeconds` | `5.0` | Required continuous physical-input idle time | | `pollMilliseconds` | `250` | Local polling interval while waiting | Legacy 0.1.x configuration keys are ignored. The installer preserves an existing file so upgrades do not overwrite user settings. ## Limitations - This works when Computer Use returns the interruption to an agent turn that remains alive. It cannot revive a turn that the Codex runtime has fully terminated. - Global `AGENTS.md` behavior is instruction-driven, not a hard real-time hook. The idle gate is deterministic once invoked, but the agent must first follow the recovery rule. - A Codex or Computer Use update can change interruption behavior and require a compatibility update. - The agent can continue the unfinished intent, but it cannot restore a model's exact internal instruction pointer. - Consequential actions still require normal review and confirmation. ## Related work - [yeahdongcn/tmux-codex-auto-continue](https://github.com/yeahdongcn/tmux-codex-auto-continue) and [thomasnormal/codex-auto-continue](https://github.com/thomasnormal/codex-auto-continue) continue Codex CLI workflows in terminal-oriented environments. - [XIADENGMA/ai-intervention-agent](https://github.com/XIADENGMA/ai-intervention-agent) provides explicit human feedback and resume flows through MCP, not physical-input idle hand-back for Computer Use. - [danecando/pi-codex-computer-use](https://github.com/danecando/pi-codex-computer-use) exposes a Computer Use runtime to Pi agents; it does not implement this idle-return behavior for an interrupted Codex Desktop action. - OpenAI's [Codex App Server documentation](https://learn.chatgpt.com/docs/app-server) documents thread/turn primitives. They do not by themselves prove that a separate process can resume an app-owned Computer Use action. ## Uninstall ```bash ./uninstall.sh ``` The uninstaller removes only the managed `AGENTS.md` block, stops any legacy LaunchAgent, and moves installed project files to a timestamped folder in Trash. ## Development ```bash python3 -m unittest discover -s tests -v python3 codex_idle_resume.py --self-test python3 -m py_compile codex_idle_resume.py tests/test_codex_idle_resume.py zsh -n install.sh uninstall.sh ``` See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md). ## License Apache License 2.0. See [LICENSE](LICENSE). Codex, ChatGPT, and OpenAI are trademarks of OpenAI. This project is not affiliated with or endorsed by OpenAI.