Skip to main content
Glama
README.md
<div align="center">

**English** · [简体中文](README.zh-CN.md)

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-dark.png">
  <source media="(prefers-color-scheme: light)" srcset="docs/assets/logo.png">
  <img alt="Codex Castor logo" src="docs/assets/logo.png" width="136" height="136">
</picture>

# Codex Castor

*Gemini talks human. Codex shuts up and ships. Zero tokens spent waiting.*

[![Release](https://img.shields.io/github/v/release/JAY201368/codex-castor?style=flat-square&color=274c5b)](https://github.com/JAY201368/codex-castor/releases/latest)
[![Python 3.9+ Zero Deps](https://img.shields.io/badge/python-3.9%2B%20%C2%B7%20zero%20deps-8f2d22?style=flat-square)](#quickstart)
[![Platforms](https://img.shields.io/badge/platforms-macOS%20%C2%B7%20Linux%20%C2%B7%20Windows%2011-4b3626?style=flat-square)](#quickstart)
[![License: MIT](https://img.shields.io/badge/license-MIT-5b7a5a?style=flat-square)](LICENSE)

[Why Codex Castor](#why-codex-castor) · [Benchmark](#same-prompt-benchmark) · [Quickstart](#quickstart) · [Monitoring](#live-monitoring--analytics) · [Permissions](#security--permissions) · [Developer Docs](#architecture--lifecycle) · [Homepage](https://jay201368.github.io/codex-castor/)

</div>

<!-- DEMO VIDEO SLOT: Drag and drop your 25-second .mp4 recording into GitHub's README editor and paste the generated https://github.com/user-attachments/assets/... URL on its own line below. -->

https://github.com/user-attachments/assets/5ef7cb4c-914b-4e5f-a55f-bbb533259cee

---

<a name="why-codex-castor"></a>

## Why Codex Castor?

Local Codex CLI writes solid, low-hallucination code — yet working with it directly often feels exhausting: dense jargon, defensive disclaimers leaking into your UI and READMEs, dated frontend taste, and subagent polling loops that burn tokens while waiting. Meanwhile, Gemini in Antigravity speaks plainly, nails visual taste, and clarifies requirements quickly.

**Codex Castor puts Gemini in the architect seat and keeps Codex quietly executing in the background.** You stay in one conversation with Gemini — no window-switching, no manual spec copy-pasting, and no token-burning status loops.

| Pain point when running Codex solo | How Codex Castor fixes it |
| --- | --- |
| Robotic jargon & defensive disclaimers leaking into UI/docs | **Gemini owns requirements, UX copy, and final review.** Codex executes headless specs and returns structured reports. |
| Polling loops / `sleep` burning quota while waiting | **True zero-token idle wait.** Antigravity runs `codex_dispatch` & `codex_resume` with `background: "always"`, sleeps at 0 LLM tokens, and wakes Gemini automatically when Codex finishes. |
| Parallel tasks colliding in one working directory | **Managed Git worktrees.** Concurrent workers run on isolated `codex/<task_id>` branches; Gemini inspects diffs and merges cleanly. |
| Expensive full repo re-reads on rework | **In-session `codex_resume`.** Sends file-specific review feedback back to the same Codex session with memory intact — preserving prior model & effort automatically. |
| Blindly cranking reasoning effort to `xhigh` | **Empirical routing loop.** Logs duration, tokens, rework rate, inline 1–5 ratings, and verbatim first replies (`PreInvocation` hook) into a Model × Effort matrix so Gemini routes smarter over time. |
| Switching windows to check quota, Fast mode, or approvals | **Antigravity Composer Widget + Codex Monitor.** Toggle Codex **Fast mode**, switch **permission policies** (`full_access`, `approve_for_me`, `workspace_write`, `read_only`), and watch 5h/7d quota right from the chat bar. |

> **Studying MCP or multi-agent design?** Even if you aren't on Antigravity yet, Codex Castor is a clean, self-contained reference implementation of a **zero-dependency Python 3.9+ stdio MCP server** (`mcp/server.py`), a standalone **`ui://` MCP App** (`mcp/monitor.html`), and a **zero-polling async delegation protocol**.

---

<a name="same-prompt-benchmark"></a>

## Same-prompt benchmark

What happens when you give the exact same prompt — *build a local single-page Pour-Over Coffee Tasting Atlas & Brew Studio with editorial magazine aesthetics, 6 single-origin beans, live preference matching, interactive brew curve, and unit tests* — to **Solo Codex (`xhigh`)** vs. **Codex Castor (`Gemini + Codex medium`)**?

![Same-prompt benchmark: Solo Codex xhigh vs Codex Castor Gemini + Codex medium](docs/assets/ab-benchmark.jpg)

| Metric | Solo Codex (`gpt-6.2-sol · xhigh`) | Codex Castor (`Gemini + Codex medium`) | Delta |
| --- | --- | --- | --- |
| First-draft wall time | `13m 33s` | **`5m 33s`** (parallel) | **2.4× faster** |
| Reasoning tokens | `8,764` | **`4,102`** | **−53%** |
| Passing unit tests | `6` | **`17`** | **+183%** |
| UI & repository cleanliness | 3-screen landing page; `"model estimate"` / `"for reference only"` disclaimers in UI & README | **Single-viewport editorial UI**, clean copy, zero disclaimers | Night-and-day |

<sub><em>Note: Real side-by-side run (UI labels translated to English for readability). Exact numbers vary by task, but separating architecture &amp; visual review from headless implementation consistently beats throwing maximum reasoning effort at a single agent.</em></sub>

---

<a name="quickstart"></a>

## Quickstart

**Prerequisites:** **Python 3.9+**, **Git**, a configured local **Codex CLI**, and **Antigravity**. Zero third-party Python packages required.

### macOS & Linux

```sh
git clone https://github.com/JAY201368/codex-castor.git && cd codex-castor && ./scripts/install.sh --install-statusline
```

Reload Antigravity to pick up the MCP server, composer widget, hook, and orchestrator skill, then verify the installation:

```sh
python3 scripts/doctor.py
```

### Windows 11 x64 (native PowerShell — no WSL or Git Bash required)

Install [Python for Windows](https://www.python.org/downloads/windows/) (with the `py` launcher), [Git for Windows](https://git-scm.com/install/windows), the [native Codex CLI](https://learn.chatgpt.com/docs/codex/cli), and [Antigravity](https://antigravity.google/download), then run:

```powershell
git clone https://github.com/JAY201368/codex-castor.git
Set-Location codex-castor
py -3 scripts/install.py --install-statusline
```

Restart Antigravity and verify with `py -3 scripts/doctor.py`. If `codex.exe` is outside `PATH`, pass `--codex-bin 'C:\path\to\codex.exe'`.

<details>
<summary><strong>Installation options, manual setup, upgrading &amp; uninstalling</strong></summary>

<br>

- **Upgrading:** Pull the latest changes (or download a [release archive](https://github.com/JAY201368/codex-castor/releases/latest)) and re-run `./scripts/install.sh` (or `py -3 scripts/install.py` on Windows). Include `--install-statusline` when upgrading the optional CLI status line, and add `--force-statusline` only when replacing an existing custom status line.
- **Common flags:** `--symlink` (link installed files to your checkout; requires Developer Mode / symlink permission on Windows), `--gemini-dir PATH`, `--python PATH`, `--codex-bin PATH`, `--skip-gemini-md`, `--dry-run`. Pass the same `--gemini-dir` to `doctor.py`; add `--json` for machine-readable diagnostics.
- **Hook backup:** The installer registers the `PreInvocation` hook in `~/.gemini/config/hooks.json` and backs up any existing file to `hooks.json.bak` before modifying it.
- **Uninstalling:** Run `python3 scripts/install.py --uninstall` (or `py -3 scripts/install.py --uninstall` on Windows). Add `--purge-state` only if you also want to delete saved Castor telemetry and task logs.

**Manual setup on macOS or Linux:** Merge the `codex-castor` entry from [`config/mcp_config.example.json`](config/mcp_config.example.json) into `~/.gemini/config/mcp_config.json`. Point `command` to Python 3.9+ and pass the absolute path to `mcp/server.py`. Keep `telemetry.py`, `castor_platform.py`, `windows_process.py`, `composer_bridge.py`, `composer_widget.js`, `report.schema.json`, and `monitor.html` alongside `server.py` (plus `analytics.py` and executable `hook.py` for an installed copy). Set `CODEX_BIN` to your Codex executable, install [`skills/codex-orchestrator/SKILL.md`](skills/codex-orchestrator/SKILL.md) to `~/.gemini/config/skills/codex-orchestrator/SKILL.md`, and merge [`config/GEMINI.md`](config/GEMINI.md) into `~/.gemini/GEMINI.md`.

Merge this entry into `~/.gemini/config/hooks.json` with your absolute Python and hook paths:

```json
{
  "codex-castor": {
    "PreInvocation": [
      {
        "type": "command",
        "command": "[ ! -f '/path/to/hook.py' ] || '/path/to/python3' '/path/to/hook.py'",
        "timeout": 5
      }
    ]
  }
}
```

</details>

---

<a name="live-monitoring--analytics"></a>

## Live monitoring & analytics

Codex Castor gives you full visibility at **zero LLM tokens**:

- **Antigravity Composer Widget** (`mcp/composer_widget.js`, `mcp/composer_bridge.py`): Adds a native status entry beside the Antigravity model selector to check live **5h / 7d Codex quota**, toggle **Fast mode**, and switch the default **permission policy** (`full_access`, `approve_for_me`, `workspace_write`, `read_only`) in one click.
- **Codex Monitor MCP App** (`ui://codex-castor/monitor.html`): Open in the Antigravity side panel or full-page view via `codex_monitor`. Refreshes every 1 second while active and every 8 seconds when idle via `tools/call`.
  - **Tasks** groups live runs and collapsible **By Project** history with filter counts (`All`, `Active`, `Rated`, `Unrated`), model/effort/Fast badges, concise failure summaries, two-step **Cancel** confirmation, full-screen **Prompt** & categorized **Activity Stream** viewers (per round for multi-round rework), and inline 1–5 star ratings & notes.
  - **Analytics** displays overall KPIs and a **Model × Reasoning Effort** matrix (excluding failed runs from aggregates) so Gemini and you can pick the fastest, cleanest tier for each kind of task.
- **Zero-token Wakeup Hook** (`scripts/hook.py`): An Antigravity `PreInvocation` hook that renders each finished round's model, effort, duration, and token count inline via `metadata.user_markdown` and silently captures your first reply verbatim.
- **Terminal & Antigravity CLI**: Run `python3 scripts/watch.py` (or `--follow [TASK_ID]`) for a standalone live terminal dashboard, or enable `--install-statusline` to stack active tasks beneath Antigravity CLI's default status bar (`stack_with_default: true`; silent when idle).
- **Standard MCP notifications**: Pass `_meta.progressToken` for `notifications/progress`, or set `logging/setLevel` to `info`/`debug` for `notifications/message`.

<div align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="docs/assets/monitor-tasks-dark.png">
    <source media="(prefers-color-scheme: light)" srcset="docs/assets/monitor-tasks-light.png">
    <img alt="Codex Monitor live tasks view in Antigravity" src="docs/assets/monitor-tasks-light.png" width="100%">
  </picture>
  <sub><strong>Tasks view</strong> — live progress, 5h/7d Codex quota, model &amp; effort badges, categorized activity streams, and inline 1–5 star ratings.</sub>
</div>

<br>

<div align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="docs/assets/monitor-analytics-dark.png">
    <source media="(prefers-color-scheme: light)" srcset="docs/assets/monitor-analytics-light.png">
    <img alt="Codex Monitor Analytics view showing Model by Reasoning Effort matrix" src="docs/assets/monitor-analytics-light.png" width="100%">
  </picture>
  <sub><strong>Analytics view</strong> — empirical Model × Reasoning Effort matrix synced with local <code>telemetry.jsonl</code>, <code>telemetry.csv</code>, and <code>report.md</code>.</sub>
</div>

<details>
<summary><strong>Telemetry &amp; analytics CLI reference (<code>scripts/analytics.py</code>)</strong></summary>

<br>

Run from the repository (use `py -3` instead of `python3` on Windows). Every subcommand accepts `--state-dir PATH`:

```text
python3 scripts/analytics.py summary [--model MODEL] [--effort EFFORT] [--project PROJECT] [--since YYYY-MM-DD] [--limit N] [--json]
python3 scripts/analytics.py backfill [--json]
python3 scripts/analytics.py feedback TASK_ID [--rating 1-5] [--verdict VERDICT] [--tags TAG1,TAG2] [--notes TEXT] [--user-prompt TEXT] [--round N]
python3 scripts/analytics.py export [--md PATH] [--csv PATH]
```

- `summary` prints overall KPIs, the Model × Effort matrix, and recent tasks (15 by default; `--since` filters inclusively by creation date).
- `backfill` reconstructs the ledger and exports from saved task artifacts while preserving existing feedback.
- `feedback` updates the same records as `codex_feedback` (defaults to the current round).
- `export` regenerates `report.md` and `telemetry.csv` in the state directory, or writes to a specific path.

Effective model and reasoning effort are resolved in priority order from the current rollout's `turn_context`, explicit `codex_dispatch`/`codex_resume` overrides, the previous round, project `.codex/config.toml`, and user `~/.codex/config.toml` (or `$CODEX_HOME/config.toml`).

</details>

---

<a name="security--permissions"></a>

## Security & permissions

Codex Castor supports four configurable permission policies (default: `full_access`), configurable globally in `~/.gemini/codex-castor/settings.json` or via the Antigravity composer widget, and overridable per round via `permission_mode`:

- `full_access` *(default)*: passes `--dangerously-bypass-approvals-and-sandbox` and `--dangerously-bypass-hook-trust` for unattended execution.
- `approve_for_me`: uses Codex's auto-review approval flow (`--approve-for-me` on dispatch; `workspace-write` sandbox with `on-request` / `auto_review` on resume).
- `workspace_write`: restricts writes to the workspace (`workspace-write` sandbox with `approval_policy="never"`).
- `read_only`: restricts Codex to read-only inspection (`read-only` sandbox with `approval_policy="never"`).

When using `full_access`, run Codex Castor only in trusted local developer workspaces. Managed Git worktrees isolate files and branches, while Codex retains the local user's OS permissions — always inspect `git diff` and run verification checks before merging.

---

<a name="architecture--lifecycle"></a>

## Architecture & lifecycle

```mermaid
flowchart LR
    U["User"] --> G["Gemini / Antigravity"]
    G -->|"spec or review feedback"| B["MCP stdio · mcp/server.py"]
    B -->|"codex exec / codex exec resume"| C["Local Codex CLI"]
    C --> W["Optional managed Git worktrees · codex/task-a, codex/task-b"]
    C -->|"JSON events and final report"| B
    B -->|"Tool result → Antigravity wakes Gemini"| G
    G -->|"Independent diff and tests"| W
```

1. **Write a self-contained spec.** Gemini inspects the codebase and covers objective, key files, requirements, constraints/non-goals, verification commands, and acceptance criteria.
2. **Route, dispatch, and yield.** Gemini checks `~/.codex/models_cache.json` (falling back to `~/.codex/config.toml`) and past telemetry, picks `model` and `reasoning_effort`, prefixes `toolSummary` with `[<model>·<effort>]`, enables `use_worktree: true` for concurrent workers, and **ends its turn cleanly** — zero status loops, zero `sleep`, zero polling timers.
3. **Review independently.** On automatic wakeup, Gemini receives a compact result containing the six-field structured [report schema](mcp/report.schema.json) (`status`, `summary`, `files_changed`, `commands_run`, `tests_summary`, `open_issues`), `git.diff_stat`, `git.status_short`, and telemetry. Gemini inspects the actual diff, runs tests, and either sends file-specific rework via `codex_resume` or merges and cleans up the worktree.
4. **Close the feedback loop.** The `PreInvocation` hook displays round telemetry inline and records your first reply verbatim; ratings and notes from Codex Monitor feed straight back into future routing.

See the [Orchestrator Skill](skills/codex-orchestrator/SKILL.md) for the complete protocol, or read the [Illustrated Engineering Manuscript](https://jay201368.github.io/codex-castor/).

<a name="mcp-tools"></a>

## MCP tools reference

All seven tools use `eager: true` in Antigravity (`timeoutSeconds: -1`). The stdio server speaks newline-delimited JSON-RPC 2.0 and runs each tool call in a worker thread.

| Tool | Background | Key inputs | When to use |
| --- | --- | --- | --- |
| `codex_dispatch` | `always` | Absolute `workdir`, `spec` or `spec_file`. Optional `title`, `task_id`, `use_worktree` (`false`), `base_ref` (`HEAD`), `model`, `reasoning_effort`, `permission_mode`, `fast_mode`, `extra_writable_dirs`. | Start a new implementation from a self-contained Markdown spec. |
| `codex_resume` | `always` | `task_id` (or `session_id` + `workdir`), and `feedback` or `feedback_file`. Optional `model`, `reasoning_effort`, `permission_mode`, `fast_mode` (omitted model/effort inherit from the prior round). | Send concrete review feedback back to an existing Codex session. |
| `codex_feedback` | `off` | `task_id`. Optional `rating` (`1–5`), `verdict` (`accepted`, `rework`, `partial`, `rejected`, `abandoned`), `tags`, `notes`, `user_first_prompt`, `round`. | Record or update ratings/verdicts or store the user's first reply verbatim. |
| `codex_status` | `off` | `task_id` or `limit` (default `20`). | One-off inspection on explicit request or post-mortem debugging. |
| `codex_cancel` | `off` | `task_id`. | Stop Codex and all child processes (Job Object on Windows; `SIGTERM` → `SIGKILL` on macOS/Linux). |
| `codex_cleanup_worktree` | `off` | `task_id`. Optional `delete_branch` (`false`), `force` (`false`). | Remove a managed Git worktree after merge or discard. |
| `codex_monitor` | `off` | Optional `task_id`, `limit` (`20`), `include_detail` (`false`), `refresh_quota` (`false`). | Open the **Codex Monitor** MCP App or fetch structured snapshots, quota, analytics, and per-round prompt/activity detail. |

## What's included

| Path | Purpose |
| --- | --- |
| [`mcp/server.py`](mcp/server.py) | Zero-dependency stdio MCP server managing subprocesses, worktrees, rollout model/effort tracking, quota refresh, failure summaries, and Monitor snapshots. |
| [`mcp/monitor.html`](mcp/monitor.html) | Self-contained MCP App (`ui://codex-castor/monitor.html`) with Tasks, Analytics, per-round prompt/stream drill-down, and inline feedback. |
| [`mcp/composer_widget.js`](mcp/composer_widget.js) · [`mcp/composer_bridge.py`](mcp/composer_bridge.py) | Antigravity chat composer widget and local bridge for live 5h/7d Codex quota, Fast mode toggle, and permission policy selector. |
| [`mcp/telemetry.py`](mcp/telemetry.py) | Locked telemetry/feedback ledger, synced JSONL/CSV/Markdown exports, historical backfill, and analytics aggregation. |
| [`mcp/report.schema.json`](mcp/report.schema.json) | Six-field JSON Schema enforced on Codex's final handoff report. |
| [`mcp/castor_platform.py`](mcp/castor_platform.py) · [`mcp/windows_process.py`](mcp/windows_process.py) | Cross-platform path/process helpers and native Windows Job Object termination. |
| [`skills/codex-orchestrator/SKILL.md`](skills/codex-orchestrator/SKILL.md) | Gemini's end-to-end procedure for specs, model routing, independent review, and telemetry reporting. |
| [`config/mcp_config.example.json`](config/mcp_config.example.json) · [`config/GEMINI.md`](config/GEMINI.md) | Antigravity MCP wiring (`background: "always"`) and global role-division protocol. |
| [`scripts/install.py`](scripts/install.py) · [`scripts/install.sh`](scripts/install.sh) · [`scripts/doctor.py`](scripts/doctor.py) | Cross-platform installer, hook merger, uninstaller, and stdio handshake health check. |
| [`scripts/hook.py`](scripts/hook.py) · [`scripts/analytics.py`](scripts/analytics.py) | Zero-token `PreInvocation` wakeup/reply hook and CLI analytics tool. |
| [`scripts/statusline.py`](scripts/statusline.py) · [`scripts/watch.py`](scripts/watch.py) | Antigravity CLI native status line and standalone live terminal watcher. |
| [`tests/`](tests/) | Automated Python `unittest` and Node.js UI fixture suite run across macOS, Linux, and Windows CI. |

<details>
<summary><strong>Runtime state layout &amp; environment variables</strong></summary>

<br>

```text
~/.gemini/codex-castor/
├── settings.json                # default fast_mode & permission_mode
├── telemetry.jsonl
├── telemetry.csv
├── report.md
├── hook_state/
│   └── <conversation_id>.json   # transcript cursor and pending rounds
├── tasks/
│   └── <task_id>/
│       ├── spec.md
│       ├── meta.json
│       ├── events-r1.jsonl
│       ├── stderr-r1.log
│       ├── report-r1.json
│       ├── feedback-r2.md
│       ├── events-r2.jsonl
│       ├── stderr-r2.log
│       └── report-r2.json
└── worktrees/
    └── <task_id>/               # managed checkout on codex/<task_id>
```

Override the state root with `CODEX_CASTOR_STATE_DIR` and the Codex binary with `CODEX_BIN`. Outer process status and the worker's `report.status` are tracked separately — inspect both before accepting or resuming.

</details>

## Testing & development

```sh
python3 -m unittest discover -s tests -v
python3 scripts/doctor.py --repo-only
```

On Windows, run `py -3 -X utf8 -m unittest discover -s tests -v` and `py -3 scripts/doctor.py --repo-only`. See the [Windows 11 x64 verification guide](docs/windows-testing.md) for CI matrix and live Antigravity App/CLI verification details.

---

<div align="center">

If Codex Castor saves your quota, sanity, or gives you a useful reference for async MCP Apps, a ⭐️ helps others find it.

[Illustrated Manuscript Homepage](https://jay201368.github.io/codex-castor/) · [Glama Registry](https://glama.ai/mcp/servers/JAY201368/codex-castor) · [Releases](https://github.com/JAY201368/codex-castor/releases) · [MIT License](LICENSE)

<br>

[![Codex Castor MCP server – quality and maintenance score on Glama](https://glama.ai/mcp/servers/JAY201368/codex-castor/badges/score.svg)](https://glama.ai/mcp/servers/JAY201368/codex-castor)

</div>

TDQS

A3.6/5.0

Scored across 7 tools

Disambiguation4/5

Most tools have clearly distinct lifecycle roles: dispatch, resume, cancel, cleanup, feedback, monitor, and status. The main ambiguity is between codex_monitor and codex_status, since both can report on running/recent tasks, though the descriptions distinguish a live UI/snapshot from explicit non-blocking inspection.

Naming Consistency4/5

All tools consistently use the codex_ prefix with snake_case, making the set predictable. Most names are action-oriented, though a few are noun-like (feedback, status, monitor), causing minor deviation from a strict verb_noun pattern.

Tool Count5/5

Seven tools is well-scoped for a Codex task orchestration server. Each tool maps to a distinct lifecycle operation, and there are no obvious redundant or filler tools.

Completeness4/5

The surface covers the core task lifecycle: dispatch, monitor, status, resume with feedback, cancel, worktree cleanup, and effectiveness feedback. Minor gaps may exist around retrieving full task output or configuring policy dynamically, but core workflows are supported.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues