Skip to main content
Glama
README.md
# codex-cu-bridge

> [中文文档 (README.zh-CN.md)](./README.zh-CN.md)

**Lightweight, zero-dependency CLI + MCP bridge to OpenAI Codex's native macOS Sky Computer Use engine (`cua_repl`) via `codex app-server`.**

Run batched, background-friendly macOS desktop automation from **Antigravity**, **T3 Code**, **Claude Code**, **Cursor**, or any MCP/shell-capable agent — with **zero Codex LLM token cost**, a hot-reloaded local App allowlist, and clean macOS menu bar session release.

---

## Why `codex-cu-bridge`?

OpenAI's Codex / ChatGPT desktop app ships an exceptionally fast macOS Computer Use runtime (`cua_repl` + `SkyComputerUseService`) that reads accessibility trees, takes screenshots, and batches multi-step UI interactions in a persistent JavaScript REPL.

`codex-cu-bridge` exposes that engine through **sanctioned local interfaces only** (`codex app-server`'s `mcpServer/tool/call` JSON-RPC protocol + `SkyComputerUseClient turn-ended`) without running any Codex LLM turn:

- **Zero npm dependencies, single-file core**: ~1,800-line Node.js ESM script ([`src/bridge.mjs`](./src/bridge.mjs)) + a tiny optional Swift helper ([`native/sky-menu-inspector.swift`](./native/sky-menu-inspector.swift)).
- **Zero Codex LLM tokens**: invokes `cua_repl.js` directly via `codex app-server` `mcpServer/tool/call` on an ephemeral thread — no OpenAI model completions are called.
- **Fast CLI + persistent Unix-socket daemon + 6-tool MCP server**:
  - Boots only `cua_repl` (automatically disables all other configured `[mcp_servers.*]` and `features.apps` on the dedicated child `codex app-server`).
  - Warm CLI calls complete in ~200–300 ms and keep `globalThis` / `var` app handles alive across turns.
  - Strips the 19 KB boilerplate first-use documentation by default (cached locally via `codex-cu-bridge docs`) and auto-retries once after inactivity kernel resets for self-initializing scripts.
- **Local App allowlist**: intercepts `mcpServer/elicitation/request` with exact bundle ID & display name, auto-approves allowlisted apps, and safely cancels unlisted/denied apps with `[APPROVAL_REQUIRED]` instructions.
- **Dual-path macOS menu bar & Software Cursor cleanup**:
  - Injects `_meta["x-codex-turn-metadata"]` (`session_id`, `turn_id`, `thread_id`) and invokes the official `SkyComputerUseClient turn-ended` hook on `end` / `stop` / 20s idle (works seamlessly in hosts with `NSAppleEventsUsageDescription` such as T3 Code, Cursor, and Terminal).
  - Includes `codex-cu-bridge release` using macOS `CGWindowListCopyWindowInfo` + Retina `Vision` OCR + [`cua-driver`](https://github.com/trycua/cua) as a safe UI fallback for hosts that lack `NSAppleEventsUsageDescription` (e.g. standalone Antigravity Desktop), supporting multi-monitor setups, full-screen auto-hidden menu bars, and localized app names (e.g. `Finder` ↔ `访达`).
- **Ready-to-use Agent Skill**: includes [`skills/codex-cu-bridge/SKILL.md`](./skills/codex-cu-bridge/SKILL.md) with batching patterns and the Sky `cua` JS API cheat sheet.

---

## Architecture

```text
Any Agent (Antigravity / T3 Code / Claude Code / Cursor / Shell)
  │
  ├── CLI: `codex-cu-bridge js / end / release / allow / status`
  └── MCP: `codex-cu-bridge mcp`  (tools: js, end_turn, release, js_reset, allowlist, status)
        │
        ▼ (Unix socket: ~/Library/Caches/codex-cu-bridge/bridge.sock)
  codex-cu-bridge daemon (auto-exits after 3m idle)
        │
        ├── JSON-RPC stdio ──▶ `codex app-server` (ephemeral thread, cua_repl only, 0 LLM tokens)
        │                        └── mcpServer/tool/call (`cua_repl.js` + `x-codex-turn-metadata`)
        │                              └── ChatGPT `cua_node` → `SkyComputerUseService`
        │
        ├── Local policy ─────▶ ~/.config/codex-cu-bridge/allowlist.json (hot-reloaded)
        └── Cleanup ──────────▶ 1) `cua_repl.turn_ended` + `SkyComputerUseClient turn-ended`
                                2) Optional `release`: `sky-menu-inspector` + `cua-driver`
```

---

## Prerequisites

1. **macOS** with **Node.js >= 18**.
2. **Codex CLI** (`codex` in `PATH`, or bundled inside `/Applications/ChatGPT.app`).
3. **ChatGPT / Codex Desktop Computer Use already enabled** on this Mac (this installs `/Applications/ChatGPT.app/Contents/Resources/cua_node/` and `~/.codex/computer-use/Codex Computer Use.app` with macOS Accessibility & Screen Recording permissions).
4. *(Optional, only needed for `codex-cu-bridge release` UI fallback)*: Xcode Command Line Tools (`swiftc`) and [`cua-driver`](https://github.com/trycua/cua) installed and granted macOS Accessibility / Screen Recording permissions.

> This repository contains **zero OpenAI binaries** — it only speaks the documented `codex app-server` JSON-RPC protocol and official `SkyComputerUseClient` CLI already installed on your machine.

---

## Installation

```bash
git clone https://github.com/DASungta/codex-cu-bridge.git
cd codex-cu-bridge

# Install CLI launcher (~/.local/bin/codex-cu-bridge) & compile native menu inspector
./install.sh

# Or also symlink the Agent Skill into detected ~/.gemini, ~/.cursor, ~/.claude, ~/.agents dirs
./install.sh --skills
```

Make sure `~/.local/bin` is on your `PATH`.

### MCP Configuration (Antigravity / Cursor / Claude Code)

Add `codex-cu` to your MCP config file (e.g. `~/.gemini/config/mcp_config.json` or `~/.cursor/mcp.json`):

```json
{
  "mcpServers": {
    "codex-cu": {
      "command": "/Users/<you>/.local/bin/codex-cu-bridge",
      "args": ["mcp"]
    }
  }
}
```

> Tip: When your agent has shell access (e.g. Antigravity, T3 Code, Claude Code), **prefer the CLI (`codex-cu-bridge js ...`)** over MCP — it avoids per-call MCP serialization/schema overhead and runs in ~200–300 ms against the warm daemon.

---

## Usage

### Run JavaScript in `cua_repl`

Batch discovery, clicks, typing, loops, and final `getAXState()` into **one** call:

```bash
# List running macOS apps
codex-cu-bridge js 'const apps = await cua.listApps({emit:false}); nodeRepl.write(JSON.stringify(apps.filter(a=>a.isRunning).map(a=>({name:a.displayName,id:a.id}))));'

# Bind an app persistently across calls (use globalThis or var)
codex-cu-bridge js --title "Inspect Calculator" - <<'JS'
globalThis.calc = await cua.getApp("com.apple.calculator");
const ax = await globalThis.calc.getAXState({ emit: false, disableDiffing: true });
nodeRepl.write(ax.split("\n").slice(0, 20).join("\n"));
JS
```

### App Allowlist Management

Config lives at `~/.config/codex-cu-bridge/allowlist.json` and hot-reloads immediately:

```bash
codex-cu-bridge allow list
codex-cu-bridge allow add "com.apple.Notes"
codex-cu-bridge allow add "com.t3tools.*"     # glob patterns supported
codex-cu-bridge allow remove "com.apple.Notes"
codex-cu-bridge allow deny "com.apple.systempreferences"
codex-cu-bridge allow mode allowlist          # allowlist | ask | allow-all
```

Unlisted or denied apps are **cancelled** (not permanently declined) and return `[APPROVAL_REQUIRED]` with the exact app name and bundle ID so the agent can ask you before allowing them.

### Session Lifecycle & Cleanup

```bash
codex-cu-bridge end                  # Send cua_repl.turn_ended + SkyComputerUseClient turn-ended
codex-cu-bridge release              # Dismiss macOS pink dot / Software Cursor (tries Sky notify first, falls back to UI)
codex-cu-bridge release Finder       # Release only matching app(s) (preserves other concurrent sessions)
codex-cu-bridge release --dry-run    # Inspect active Stop Using items without clicking
codex-cu-bridge release --all        # Release all active Stop Using items
codex-cu-bridge reset                # Reset persistent JS bindings in cua_repl
codex-cu-bridge status               # Show daemon, codex app-server, touchedApps, and allowlist status
codex-cu-bridge docs                 # Print cached full cua_repl API docs
codex-cu-bridge stop                 # End active turn and stop background daemon
```

Environment variables:

| Variable | Default | Description |
| --- | --- | --- |
| `CODEX_HOME` | `~/.codex` | Codex configuration directory |
| `CODEX_CU_CODEX_BIN` | auto-detected | Override path to `codex` binary |
| `CODEX_CU_TURN_IDLE_SEC` | `20` | Seconds of inactivity before automatic `turn_ended` |
| `CODEX_CU_IDLE_TIMEOUT_SEC` | `180` | Seconds of inactivity before daemon auto-exits |
| `CUA_DRIVER_BIN` | auto-detected | Override path to `cua-driver` for `release` fallback |

---

## macOS Cleanup Note (`NSAppleEventsUsageDescription`)

On macOS, Codex's official `SkyComputerUseClient turn-ended` helper bootstraps its XPC cleanup connection to `SkyComputerUseService` via **Apple Events** (`kTCCServiceAppleEvents`):

- **Hosts declaring `NSAppleEventsUsageDescription`** (e.g. **T3 Code**, **Cursor**, **Terminal.app**, **iTerm2**): macOS prompts once for Automation consent, after which `codex-cu-bridge end` (and the 20s idle timer) silently dismisses the menu bar pink dot and `Software Cursor`.
- **Hosts missing `NSAppleEventsUsageDescription`** (e.g. standalone `/Applications/Antigravity.app` as of v2.35.1): macOS `tccd` silently refuses `kTCCServiceAppleEvents` without prompting. Use `codex-cu-bridge release` (or click the OpenAI menu bar icon → `Computer Use` → `Stop Using <App>`) when running inside such hosts, or run your agent inside T3 Code / Terminal.

---

## Known Limitations

- **Native macOS apps only**: `cua.getApp(...)` works fully. Codex's turn-scoped browser plugin (`cua.getTab` / `@oai/browser-desktop`) requires an active Codex LLM turn and returns `Cannot verify browser access without the current turn` under `mcpServer/tool/call`. Use a DOM-native browser tool (Playwright / Chrome DevTools MCP) for web pages.
- **macOS only**: relies on macOS `SkyComputerUseService` and CoreGraphics/Vision helpers.

---

## Comparison with Related Projects

- **[amontlabs/lcu](https://github.com/amontlabs/lcu)**: Full-featured decoupling layer with Chrome extension support, Touch ID approval management, and native Claude Code approval UI mods.
- **[tmustier/codex-computer-use-mcp](https://github.com/tmustier/codex-computer-use-mcp)**: MCP server + Pi adapter for the Codex Computer Use broker with browser support.
- **`codex-cu-bridge` (this repo)**: Minimalist, single-file, zero-npm-dependency bridge using only official `codex app-server` JSON-RPC (`mcpServer/tool/call`), optimized for CLI-first agent speed, local JSON allowlist governance, and resilient macOS menu bar cleanup.

---

## License

[MIT](./LICENSE)