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

<img src="docs/assets/hero-banner.svg" alt="Codex Swarm Banner" width="100%" />

<br />
<br />

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square)](LICENSE)
[![Python 3.11+](https://img.shields.io/badge/Python-3.11%2B-3776AB.svg?style=flat-square&logo=python&logoColor=white)](requirements.txt)
[![Platform: Windows](https://img.shields.io/badge/Platform-Windows%2010%2F11-0078D6.svg?style=flat-square&logo=windows&logoColor=white)](#2-quick-start)
[![Protocol: MCP Streamable HTTP](https://img.shields.io/badge/MCP-Streamable%20HTTP-6366F1.svg?style=flat-square)](#3-architecture)
[![Runtime: codex app-server](https://img.shields.io/badge/Codex-app--server%20JSON--RPC-10A37F.svg?style=flat-square)](#3-architecture)

<p>
  <strong>An Antigravity-style multi-agent swarm orchestrator for OpenAI Codex โ€” featuring true peer-to-peer <code>@mention</code> wakeups, zero-token parked workers, isolated Git worktrees, and an interactive Hive &amp; Mention Graph Web UI.</strong>
</p>

<p>
  ๐ŸŒ <strong>English</strong> ยท <a href="README.zh-CN.md">็ฎ€ไฝ“ไธญๆ–‡</a> ยท <a href="README.ja.md">ๆ—ฅๆœฌ่ชž</a>
</p>

<p>
  <a href="#1-why-codex-swarm">Why Codex Swarm?</a> โ€ข
  <a href="#2-interface-showcase">Interface Showcase</a> โ€ข
  <a href="#3-architecture">Architecture</a> โ€ข
  <a href="#4-quick-start">Quick Start</a> โ€ข
  <a href="#5-try-peer-to-peer-collaboration">P2P Prompt</a> โ€ข
  <a href="#6-mcp-tool-reference">MCP Tools</a>
</p>

</div>

---

## 1. Why Codex Swarm?

Native Codex subagents use a strict parent-child hierarchy where siblings cannot talk to each other, active waits consume turn runtime, and every subagent shares the parent working directory by default. **Codex Swarm** bridges those gaps using `codex app-server` + a local Streamable HTTP MCP bus so you can orchestrate a full swarm right inside **Codex Desktop App / CLI** via `$swarm`.

| Capability | Native Codex Subagents | Codex Swarm (`Path 3 ยท Form A`) |
|---|---|---|
| **Peer-to-Peer `@mention` Comms** | Parent โ†” child relay only | **Direct P2P** (`author` โ†” `verifier` wake each other via `@name` / `@all` / `@#channel`) |
| **Idle Worker Cost** | Active wait eats turn timeout | **Zero-token parked threads** โ€” turns end cleanly and wake on `@mention` (`turn/start` / `turn/steer`) |
| **Workspace Isolation** | Shared parent CWD | **Automatic `git worktree`** per parallel author (`.swarm-worktrees/<id>/<worker>`) |
| **Single-Window Experience** | Terminal / thread tree only | **Auto-opens in Codex Side Browser (`iab`)** next to your chat, plus Desktop shortcut |
| **Live Swarm Visualization** | No shared board or graph | **4-Tab Web UI** with **Hive** & **Mention Graph** timeline playback (`0.5ร—โ€“4ร—`) |
| **Model Hot-Switching** | Requires fresh spawn | **Hot-switch `waiting` worker models** while preserving full `threadId` history |
| **Stall Detection & Approvals** | Manual inspection | **Built-in 180s stall watchdog** + one-click **Allow / Session / Decline** UI cards |

---

## 2. Interface Showcase

Light-first, zero-CDN offline Web Dashboard (`http://127.0.0.1:8765/`) with one-click Dark mode toggle and responsive narrow-pane layout (`โ‰ค640px`) built specifically for Codex's side browser.

<table>
  <tr>
    <td width="50%" align="center">
      <strong>๐Ÿ Hive View (่œ‚ๅทข) &amp; Timeline Playback</strong><br />
      <sub>Pixel Queen Bee Coordinator, status-colored hexes, blue active &amp; amber waiting arrows</sub><br /><br />
      <img src="docs/assets/preview-hive.png" alt="Hive Graph View" width="100%" />
    </td>
    <td width="50%" align="center">
      <strong>๐Ÿ•ธ๏ธ Mention Graph (ๆๅŠๅ›พ)</strong><br />
      <sub>Directed P2P interaction network with message-count badges (<code>ร—1</code>, <code>ร—2</code>)</sub><br /><br />
      <img src="docs/assets/preview-mention.png" alt="Mention Graph View" width="100%" />
    </td>
  </tr>
  <tr>
    <td width="50%" align="center">
      <strong>๐Ÿ“Š Overview (ๆฆ‚่งˆ)</strong><br />
      <sub>Live KPIs, <code>plan.json</code> outcome threads, approval queue, and worker live stream</sub><br /><br />
      <img src="docs/assets/preview-overview.png" alt="Overview Tab" width="100%" />
    </td>
    <td width="50%" align="center">
      <strong>๐Ÿ’ฌ Shared Message Board (ๆถˆๆฏๆฟ)</strong><br />
      <sub>Sequence-numbered <code>#seq</code> feed, channel filters, <code>[done]</code> tags, and quick <code>@mention</code> chips</sub><br /><br />
      <img src="docs/assets/preview-board.png" alt="Message Board Tab" width="100%" />
    </td>
  </tr>
</table>

---

## 3. Architecture

<div align="center">
  <img src="docs/assets/architecture.svg" alt="Codex Swarm Architecture" width="100%" />
</div>

1. **Stay in your Codex chat**: Your active Codex Desktop App / CLI thread acts as `Coordinator` via the `$swarm` skill and connects to `http://127.0.0.1:8765/mcp`.
2. **Event-driven worker threads**: The local Python Daemon manages a persistent `codex app-server --stdio` process. Every worker runs in its own `threadId` and **ends its turn immediately** after posting to the board โ€” consuming zero tokens while parked.
3. **Instant wakeup & steer**: When any worker or coordinator posts `@target`, the daemon injects unread `#seq` context via `turn/start` (if `waiting`) or `turn/steer` (if `working`).
4. **Single-window side browser**: On Codex Desktop App, `$swarm` automatically reveals the built-in In-App Browser (`iab`) and pins the dashboard tab (`markDeliverable`) right beside your conversation.

---

## 4. Quick Start

### Prerequisites
- **Windows 10 / 11** + PowerShell
- **Python 3.11+** (`pip install -r requirements.txt` โ€” only `aiohttp` is required)
- **Git** (for `workspace="share"` worktree isolation)
- **OpenAI Codex Desktop App** or **Codex CLI** signed in (auto-discovers `CODEX_CLI_PATH`, `PATH`, or bundled `WindowsApps\OpenAI.Codex_*\...\codex.exe`)

### Install in 4 Commands

```powershell
git clone https://github.com/moonrzz/codex-swarm.git
cd codex-swarm
pip install -r requirements.txt
.\install.ps1
```

`install.ps1` automatically:
1. Installs the `$swarm` skill to `%USERPROFILE%\.agents\skills\swarm\SKILL.md`;
2. Backs up `%USERPROFILE%\.codex\config.toml` and registers `[mcp_servers.swarm_board]` (`default_tools_approval_mode = "approve"`);
3. Creates a silent one-click **ใ€ŒCodex ่œ‚็พค็œ‹ๆฟใ€** shortcut on your Desktop (pass `-DesktopShortcut:$false` to skip).

### Launch & Use

```powershell
# Start background daemon manually (or let $swarm / Desktop shortcut start it automatically)
.\start-swarm-daemon.ps1 -Background

# Stop background daemon
.\stop-swarm-daemon.ps1
```

Open a new conversation in **Codex Desktop App / CLI** and type:

```text
$swarm Refactor the auth module into token and session layers, add unit tests, and run a peer review
```

---

## 5. Try Peer-to-Peer Collaboration

Want to verify direct sibling-to-sibling communication without modifying any repository files? Paste this read-only prompt into Codex:

<details>
<summary><strong>Click to expand ready-to-paste P2P verification prompt</strong></summary>

```text
$swarm Verify direct peer-to-peer (P2P) collaboration between sibling workers without editing any files:

1. Spawn two read-only workers (`workspace="inherit"`, `sandbox="read-only"`):
   - `proposer`: Draft a 3-point minimal code review checklist, then post directly to `@reviewer` for critique (do NOT `@coordinator` and do NOT write `[done]`), and end your turn immediately.
   - `reviewer`: Wait for `@reviewer`, point out at least 1 vague rule, and post directly to `@proposer` requesting measurable criteria (do NOT `@coordinator` or `[done]`), then end your turn.
2. Have `proposer` revise the checklist and post v2 back to `@reviewer` (still without `@coordinator`).
3. Have `reviewer` verify v2 and post `@coordinator [done]` summarizing both rounds.
4. As Coordinator, do not relay between them; only report to me after receiving `@coordinator [done]`, listing the P2P `#seq` numbers.
```

Then open the **ๅ…ณ็ณปๅ›พ โ†’ ๆๅŠๅ›พ** tab to see direct bidirectional arrows (`proposer โ†” reviewer`) bypassing `Coordinator`!

</details>

---

## 6. MCP Tool Reference

<details>
<summary><strong>12 Tools exposed at <code>http://127.0.0.1:8765/mcp</code></strong></summary>

| Tool | Role | Description |
|---|---|---|
| `swarm_init` | Coordinator | Create a new active swarm bound to `repo_root` and `title` |
| `swarm_title` | Coordinator | Rename the active swarm |
| `swarm_plan` | Coordinator | Publish `plan.json` (`goal`, `tasks`, `threads`) for Overview & Hive |
| `swarm_models` | Coordinator | List available Codex models from `codex app-server` |
| `swarm_add` | Coordinator | Spawn a persistent worker (`inherit` or isolated `share` git worktree) |
| `swarm_status` | All | Inspect roster states, head `#seq`, dashboard URL, and pending approvals |
| `swarm_model` | Coordinator | Hot-switch a `waiting` worker's model while keeping its `threadId` |
| `swarm_kill` | Coordinator | Terminate a worker and optionally clean up its worktree/branch |
| `swarm_channel` | All | `create`, `list`, `archive`, `subscribe`, or `unsubscribe` channels |
| `post_message` | All | Post to the board and auto-wake `@name` / `@all` / `@#channel` recipients |
| `read_board` | All | Read incremental messages after `since` `#seq` |
| `swarm_wait` | Coordinator | Block until `@coordinator` / `[done]` / `[stall]` arrives after `since` |

</details>

---

## 7. Worktree Merge & Project Structure

When parallel authors run with `workspace="share"`, each commits on `swarm/<swarm_id>/<worker>`:
1. Have a read-only `verifier` audit diffs and test results;
2. Merge verified branches: `git merge --no-ff swarm/<swarm_id>/<worker>`;
3. Clean up: `swarm_kill(name="<worker>", remove_worktree=True, delete_branch=True)`.

<details>
<summary><strong>Project Structure &amp; Automated Tests</strong></summary>

```powershell
python -m unittest discover -s tests -v
```

```text
codex-swarm/
โ”œโ”€ codex_swarm/
โ”‚  โ”œโ”€ app_server.py    # codex app-server --stdio JSON-RPC 2.0 client
โ”‚  โ”œโ”€ orchestrator.py  # @mention wakeup router, model hot-swap, approvals, stall watchdog
โ”‚  โ”œโ”€ mcp_http.py      # Streamable HTTP MCP server (/mcp)
โ”‚  โ”œโ”€ web_ui.py        # Light-first 4-tab Web UI + Hive/Mention Graph & playback
โ”‚  โ”œโ”€ store.py         # SQLite WAL + append-only JSONL persistence
โ”‚  โ”œโ”€ worktree.py      # Git worktree isolation & cleanup
โ”‚  โ””โ”€ config.py        # Settings & automatic codex.exe discovery
โ”œโ”€ docs/assets/        # Vector banner, architecture diagram & UI showcase screenshots
โ”œโ”€ skills/swarm/SKILL.md
โ”œโ”€ assets/swarm-icon.ico
โ”œโ”€ tests/test_swarm_daemon.py
โ”œโ”€ install.ps1
โ”œโ”€ start-swarm-daemon.ps1
โ”œโ”€ stop-swarm-daemon.ps1
โ”œโ”€ launch-dashboard.ps1
โ””โ”€ launch-dashboard-silent.vbs
```

</details>

---

## License

Released under the [MIT License](LICENSE).