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

<img src="assets/banner.png" alt="Switchboard: run your coding agents from anywhere, even by voice" width="100%">

Start, monitor and steer **Claude Code** and **Codex** sessions on your Mac from your phone,
through the Claude app, using the Model Context Protocol.

[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
![Platform: macOS](https://img.shields.io/badge/platform-macOS-lightgrey.svg)
![Node 20+](https://img.shields.io/badge/node-%E2%89%A520-339933.svg)
![MCP](https://img.shields.io/badge/MCP-Streamable%20HTTP%20%2B%20OAuth-7c3aed.svg)

[Voice mode](#-voice-mode) · [Quick start](#-quick-start) · [Tools](#-tools) · [Configuration](#%EF%B8%8F-configuration) · [Security](#-security)

</div>

---

> *"Start a Claude session in my app and have it fix the failing tests."*
> *"What are my sessions doing?"*
> *"What does it want to approve? … OK, approve it."*
> *"Tell me when it's done."*

Switchboard is a small MCP server that runs on your Mac. It launches agents in [Ghostty](https://ghostty.org)
windows, keeps track of what each one is doing, and lets any MCP client — including the Claude mobile app in voice
mode — read their output, answer their questions and give them new work.

## ✨ Features

- **Start agents anywhere you're allowed:** Claude Code or Codex, in a project you name out loud ("my app",
  "feature x"), with an optional first prompt.
- **Live status for every session:** `working`, `needs_approval`, `waiting_input`, or `exited`, from agent hooks
  combined with screen detection.
- **Safe approvals:** reads the actual on-screen menu and moves to the option you asked for. No blind key
  presses that could pick "No, exit".
- **"Tell me when it's done":** waits for a turn to finish, an approval request, or an exit, then summarises it.
- **Sessions outlive windows:** every agent runs in its own tmux session; Ghostty just displays it. Close the
  window and it keeps working.
- **Private by default:** binds to `127.0.0.1`, reachable from outside only through your Cloudflare Tunnel,
  behind OAuth with a passphrase-gated consent page.

## 🧭 How it works

```mermaid
flowchart LR
    A["Claude app<br/>(voice or text)"] -->|HTTPS| B["claude.ai<br/>MCP connector"]
    B -->|OAuth bearer| C["Cloudflare Tunnel"]
    C --> D["Switchboard<br/>127.0.0.1:8787"]
    D -->|send-keys / capture-pane| E["tmux session<br/>sb-&lt;id&gt;"]
    D -->|AppleScript| F["Ghostty window"]
    F -. attached to .- E
    E --> G["claude / codex"]
    G -->|hooks / notify| H["~/.switchboard/events"]
    H --> D
```

| Piece | Role |
|---|---|
| **tmux** | Source of truth. Typing into and reading from sessions works with or without a window. |
| **Ghostty** (AppleScript) | Opens, focuses and closes the window attached to each session. |
| **Claude hooks / Codex `notify`** | Report prompts, tool use, notifications and finished turns, plus the agent's latest reply. |
| **Screen detection** | Recognises approval dialogs, trust prompts, and "working" vs idle states; tested against real captures. |

## 🎙 Voice mode

Switchboard is built to be used hands-free from the **Claude app's voice mode**. Claude does the listening and
talking; Switchboard gives it the tools to act on your Mac. Tool replies are kept short so they read well aloud.

### Set it up once

1. Complete the [remote setup](#remote-claude-app--claudeai) below, so Switchboard is connected to your claude.ai
   account as a custom connector.
2. In the Claude app on **iOS or Android**, start a new chat and turn on **switchboard** in the tools menu.
3. Tap the **voice** button and talk.

When Claude first uses a tool it may ask permission. Choose **Always allow** for the read-only tools
(`list_sessions`, `get_summary`, `read_output`, `wait_for_change`) so conversations flow without interruptions.
Keeping the approval for `respond` and `kill_session` is a good idea.

### Things to say

| You say | What happens |
|---|---|
| *"What projects can you see?"* | `list_projects` |
| *"Start a Codex session in my app and ask it to add input validation."* | `start_session` opens a Ghostty window and sends the prompt |
| *"Call it validation."* | Sessions can have a spoken label, so you can say *"How's validation doing?"* later |
| *"What are my sessions doing?"* | `list_sessions`, with anything waiting on approval first |
| *"What does it want?"* | `get_summary` reads out the pending approval dialog |
| *"Approve it."* / *"Approve and don't ask again."* / *"Deny it."* | `respond` picks the matching menu option |
| *"Tell it to also update the tests."* | `send_prompt` |
| *"Tell me when it's done."* | `wait_for_change`, then a summary of the result |
| *"Stop it."* | `interrupt` |
| *"What did it change?"* | `read_output` with recent replies from the transcript |
| *"Close the window but keep it running."* | `close_window` |

### Tips for voice

- **Use labels.** "The validation session" is much easier to say than `a3f9`.
- **Say "tell me when it's done" again** if a task runs long. Each wait lasts up to about a minute, and Claude
  can keep checking.
- **Keep your Mac awake** while you're away (System Settings → Energy → *Prevent automatic sleeping*). Switchboard
  runs on your Mac, so a sleeping Mac can't answer.
- **Approvals are read back before acting.** The server tells Claude to describe what an agent wants and to wait
  for your go-ahead before calling `respond`.

## 🚀 Quick start

### Requirements

- macOS with [Ghostty](https://ghostty.org) **1.3+** (for its AppleScript support)
- [tmux](https://github.com/tmux/tmux) (`brew install tmux`) and Node.js **20+**
- `claude` (Claude Code) and/or `codex` on your `PATH`
- For remote use: a domain on Cloudflare (the free plan is fine) and `cloudflared`

### Install

```bash
git clone https://github.com/David-Feldt/switchboard.git
cd switchboard
npm install && npm run build
cp .env.example .env   # then edit it (see Configuration)
```

### Local: Claude Code on the same Mac

No tunnel or sign-in needed:

```bash
claude mcp add switchboard -- node "$PWD/dist/server.js" --stdio
```

### Remote: Claude app / claude.ai

1. **Create a tunnel** on your domain: see [`scripts/setup-tunnel.md`](scripts/setup-tunnel.md).
2. **Set** `SB_PUBLIC_URL` and a long `SB_PASSPHRASE` in `.env`.
3. **Install the background services** (they start at login and restart on failure):
   ```bash
   scripts/install-launchd.sh <tunnel-name>
   ```
4. **Add the connector:** claude.ai → Settings → Connectors → *Add custom connector* → `https://<your-host>/mcp`.
5. **Sign in:** a consent page opens; enter your passphrase.

The first time a window opens, macOS asks whether Switchboard may control Ghostty. Click **Allow**.

## 🧰 Tools

| Tool | Description |
|---|---|
| `list_projects` | Folders that sessions can be started in |
| `list_sessions` | Every session with its status, last activity, pending question, and latest reply |
| `start_session` | Launch `claude` or `codex` in a project, with optional `prompt`, `label`, `model`, `show_window` |
| `send_prompt` | Type a message and press Enter. Refuses while a dialog is open, so text can't answer it by accident |
| `respond` | `approve`, `approve_always` or `deny`, by navigating the on-screen menu; raw `keys` also accepted |
| `interrupt` | Escape, or Ctrl-C with `hard: true` |
| `read_output` | The current screen, or `mode: "transcript"` for the agent's recent replies |
| `get_summary` | A short, read-aloud summary of one session |
| `wait_for_change` | Block until a session finishes its turn, needs approval, or exits (up to 55 s per call) |
| `show_session` / `close_window` | Open or focus a session's Ghostty window, or close it without stopping the session |
| `kill_session` | End a session for good |

Sessions can be referred to by id (`a3f9`), label (`"validation"`), or project name.
Each session's screen is also exposed as an MCP resource at `session://<id>/screen`.

## ⚙️ Configuration

Settings are read from `.env` in the project folder (or `~/.switchboard/.env`); real environment variables take
precedence.

| Variable | Default | Description |
|---|---|---|
| `SB_PUBLIC_URL` | (none) | Public URL served by your tunnel. Required for HTTP mode |
| `SB_PASSPHRASE` | (none) | Passphrase for the consent page. At least 12 characters; make it long and random |
| `SB_PROJECT_ROOTS` | `~/Projects` | Comma-separated folders. Each folder and its subfolders can host sessions |
| `SB_PORT` | `8787` | Local port (always bound to `127.0.0.1`) |
| `SB_ALLOW_SKIP_PERMISSIONS` | `false` | Allow `skip_permissions`, which runs agents without approval prompts |
| `SB_TMUX` / `SB_CLAUDE` / `SB_CODEX` | `/opt/homebrew/bin/tmux` / `claude` / `codex` | Binary locations |

Folders inside a root are found by spoken name, as are folders one level deeper (for example git worktrees).
New folders show up automatically; adding a new root needs a server restart:

```bash
launchctl kickstart -k gui/$(id -u)/com.switchboard.server
```

## 🔒 Security

Switchboard gives whoever is signed in control over coding agents on your machine. Treat access like an SSH key.

- **Local-only listener.** The server binds to `127.0.0.1`; your Cloudflare Tunnel is the only way in.
  `Host` headers are checked against `SB_PUBLIC_URL`.
- **OAuth 2.1 with PKCE.** `/mcp` requires a bearer token. Tokens are issued only after the passphrase is entered
  on the consent page (five wrong attempts lock it for a minute). Access tokens last one hour, refresh tokens seven
  days, and both are stored hashed. **To revoke all access, delete `~/.switchboard/oauth.json`.**
- **No arbitrary shell.** The server starts only `claude` or `codex`, only inside `SB_PROJECT_ROOTS`. Agents keep
  their own permission modes, and `skip_permissions` is refused unless you enable it.
- **Prompt injection is possible.** Agent output is passed back to Claude, and text an agent read on the web or in
  a file could try to steer it. Keep `respond` behind a confirmation in the Claude app.

**Recommended hardening (free on Cloudflare):**
- Put **Cloudflare Access** in front of `/authorize` and `/consent`, so only your email can reach the sign-in page.
- Add a **WAF rule** that allows `/mcp`, `/token` and `/register` only from Anthropic's published IP ranges.
- Use a random subdomain rather than `mcp.` or `claude.`.

## 🩺 Troubleshooting

| Symptom | Fix |
|---|---|
| No Ghostty window appears | System Settings → Privacy & Security → **Automation**: allow it to control Ghostty |
| "Folder … does not exist" or "outside the allowed folders" | Check `SB_PROJECT_ROOTS`, then restart the server |
| Claude says it can't reach the tools | `curl https://<your-host>/healthz` should print `ok`; check `~/.switchboard/logs/` |
| A session is stuck on a dialog | Ask *"What does it want?"* and answer it, or attach with `tmux attach -t sb-<id>` |
| Unreachable while you're away | Your Mac is probably asleep; prevent automatic sleeping |

## 🛠 Development

```bash
npm run dev          # tsc --watch
npm test             # vitest: screen detection, menu navigation, project resolution
tmux ls              # sb-* sessions
tmux attach -t sb-<id>
tail -f ~/.switchboard/events/*.jsonl   # hook events as they arrive
```

State lives in `~/.switchboard/`: `sessions.json`, `events/`, `oauth.json`, `windows.json`, `logs/`.

```
src/
├── server.ts       HTTP (Streamable HTTP + OAuth) and stdio entry point
├── auth.ts         single-user OAuth provider and consent page
├── tools.ts        MCP tool definitions
├── sessions.ts     session registry, status, turn tracking
├── status.ts       screen classification and menu parsing
├── tmux.ts         tmux wrapper
├── ghostty.ts      Ghostty AppleScript wrapper
├── projects.ts     project roots and spoken-name resolution
├── hook-relay.ts   called by agent hooks; appends events
└── agents/         launch commands and transcript reading for claude / codex
```

## 📄 License

[MIT](LICENSE)