/ docs / adapters / desktop / codex.md
codex.md
 1  # Codex
 2  
 3  Control the **OpenAI Codex Desktop App** headless or headfully via Chrome DevTools Protocol (CDP). Because Codex is built on Electron, OpenCLI can directly drive its internal UI, automate slash commands, and manipulate its AI agent threads.
 4  
 5  ## Prerequisites
 6  
 7  1. You must have the official OpenAI Codex app installed.
 8  2. Launch it via the terminal and expose the remote debugging port:
 9     ```bash
10     # macOS
11     /Applications/Codex.app/Contents/MacOS/Codex --remote-debugging-port=9222
12     ```
13  
14  ## Setup
15  
16  ```bash
17  export OPENCLI_CDP_ENDPOINT="http://127.0.0.1:9222"
18  ```
19  
20  ## Commands
21  
22  ### Diagnostics
23  - `opencli codex status`: Checks connection and reads the current active window URL/title.
24  - `opencli codex dump`: Dumps the full UI DOM and Accessibility tree into `/tmp`.
25  - `opencli codex screenshot`: Captures DOM + snapshot artifacts of the current window.
26  
27  ### Agent Manipulation
28  - `opencli codex new`: Simulates `Cmd+N` to start a completely fresh and isolated Git Worktree thread context.
29  - `opencli codex send "message"`: Robustly finds the active Thread Composer and injects your text.
30    - *Pro-tip*: You can trigger internal shortcuts, e.g., `opencli codex send "/review"`.
31  - `opencli codex ask "message"`: Send + wait + read in one shot.
32  - `opencli codex read`: Extracts the entire current thread history and AI reasoning logs.
33  - `opencli codex extract-diff`: Automatically scrapes any visual Patch chunks and Code Diffs.
34  - `opencli codex model`: Get the currently active AI model.
35  - `opencli codex history`: List recent conversation threads from the sidebar.
36  - `opencli codex export`: Export the current conversation as Markdown.