> ## Documentation Index
> Fetch the complete documentation index at: https://eispatch.framewire.io/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Codex

> Install and use EISPATCH with OpenAI Codex through a UserPromptSubmit hook, Local Composer, and clipboard fallback dispatch.

OpenAI Codex integrates with EISPATCH through a `UserPromptSubmit` hook that blocks execution until you review and approve the prompt in the Local Composer. Because Codex does not expose a direct same-session dispatch API, approved prompts are delivered via clipboard fallback.

## Verified version

EISPATCH v1.1.0 is verified with `codex-cli 0.169.0`.

## Installation

Run the installer from the cloned repository:

```bash theme={null}
node scripts/install-codex.mjs
```

### What the installer writes

The installer modifies `~/.codex/` and adds the following:

1. **MCP server** in `~/.codex/config.toml` under `mcp_servers.eispatch`.
2. **UserPromptSubmit hook** registered in the host.
3. **Skill** installed to `~/.agents/skills/eispatch/`.

> [!WARNING]
>
> Keep the cloned repository in place after installing. The installer references absolute paths inside it; moving the repo breaks the integration.

## Hook flow

When you submit a prompt, the hook reads JSON from stdin containing at least `prompt`, `session_id`, and `cwd`. On trigger it follows this flow:

**1. Intercept**

The hook matches the trigger prefix and identifies that EISPATCH should handle the prompt.

**2. Launch Local Composer**

A detached process spawns `core/launch-local-composer.mjs` with `--host codex`, the prompt, workspace path, and a temporary ready-file path.

**3. Wait for ready signal**

The hook waits up to 2.5 seconds for the ready file to contain a JSON object with `url`, `port`, and `pid`.

**4. Block and respond**

The hook outputs a block JSON containing `composerUrl` so Codex can present the launcher URL.

### Block JSON example

```json theme={null}
{
  "decision": "block",
  "reason": "[EISPATCH] Prompt blocked before execution until approved. Open EISPATCH Local Composer (Codex - Clipboard Fallback): http://127.0.0.1:PORT 1. Review capabilities & edit instructions. 2. Click Approve, then Dispatch to copy the approved prompt. 3. Paste and submit the copied prompt here (prompts containing <!-- DISPATCH_COMPILED_PROMPT --> pass through automatically).",
  "composerUrl": "http://127.0.0.1:PORT"
}
```

If the Local Composer fails to launch, the hook outputs instructions to start it manually via the MCP tool `dispatch_compose` or by running `npm run preview`.

## Clipboard fallback flow

**1. Launch**

Open the Local Composer URL from the block message or start it with `npm run preview`.

**2. Review**

Review discovered capabilities, edit the final prompt, and click **Approve**.

**3. Dispatch**

Click **Dispatch** to copy the approved prompt to your clipboard.

**4. Paste and submit**

Paste the prompt into Codex and submit it. Prompts containing the compiled marker (`<!-- DISPATCH_COMPILED_PROMPT`) pass through the hook automatically.

## Local Composer server

The Codex adapter uses the shared hardened Local Composer server (`core/local-composer.mjs`). It binds to `127.0.0.1` on an ephemeral port, requires a per-session token (**401** if missing or wrong), and rejects requests whose `Host`, `Origin`, or `Referer` does not match the loopback address (**403**). Dispatch requires a one-time approval token bound to the SHA-256 hash of the approved prompt; missing or invalid approvals return **403**, and replay or tampering returns **409**. The hook's launcher closes the server after 30 minutes without requests.

Codex has no session injection API in EISPATCH, so dispatch always uses **clipboard fallback**. Native same-session dispatch is available only in [Antigravity](https://eispatch.framewire.io/agents/antigravity.md).

## Environment variables

| Variable | Effect |
| - | - |
| `EISPATCH_AUTO_INTERCEPT=1` | Intercept every Codex prompt even without a trigger prefix. |
| `EISPATCH_NO_SPAWN=1` | Do not start the Local Composer. The hook still blocks the prompt and tells you to use the MCP tool `dispatch_compose` or `npm run preview` and paste the compiled prompt. |

## Check and uninstall

Verify the installation:

```bash theme={null}
node scripts/install-codex.mjs --check
```

Remove EISPATCH entries:

```bash theme={null}
node scripts/install-codex.mjs --uninstall
```

Uninstall removes only EISPATCH-owned entries.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.