---
name: codegrid-agent-bus
description: How to collaborate with other AI agents running in CodeGrid using the codegrid-agent-bus MCP tools (list_agents, read_pane, message_agent). Use whenever the user asks you to delegate to, consult, coordinate with, or hand work to another agent (e.g. "ask Codex to…", "have Gemini review…", "get the other agent to…").
---

# Working with other agents in CodeGrid

You are running inside **CodeGrid**, a canvas where several AI agents (Claude, Codex, Gemini, …) run side‑by‑side, each in its own pane. The **`codegrid-agent-bus`** MCP server lets you talk to the others.

## Your tools
- `list_agents()` → every pane: `session_id`, pane number, command (claude/codex/gemini/…), status, working dir. **The `session_id` is how you address an agent.**
- `read_pane(session_id, max_bytes?)` → that pane's recent output (already ANSI‑stripped).
- `message_agent(session_id, text, submit?)` → types `text` into that pane and (by default) presses Enter, so the agent acts on it.

## The protocol — always read before and after you write
1. **`list_agents`** to find the target by its command/role (e.g. the `codex` pane) and grab its `session_id`.
2. **`read_pane`** the target first, so you know it's idle/ready and don't talk over it.
3. **`message_agent`** with a clear, self‑contained request. Identify yourself and state exactly what you want back, e.g.:
   `"[from Claude] Please review src/auth.ts for security issues and reply with a short bullet list. Don't edit files."`
4. **Wait, then `read_pane`** again to collect the reply. Give the other agent time — re‑read after a short pause; if it's still working, read again rather than spamming new messages.

## Etiquette & safety
- **One message, then wait.** Don't fire multiple messages before the other agent answers — you'll garble its input.
- **Be explicit about scope.** Other agents may be in autonomous/YOLO mode and will *act* on what you send. Say "propose only" / "don't edit" when you just want analysis.
- **Address by `session_id`, never guess.** Pane numbers can shift; the `session_id` from `list_agents` is stable.
- **Don't loop.** If you message an agent that might message you back, avoid infinite ping‑pong — converge on a result and report to the user.
- **Read‑only when unsure.** `read_pane` is always safe; use it to observe a long‑running agent without interrupting it.

## Patterns
- **Delegate:** Claude → `message_agent(codex, "implement X")` → poll `read_pane` until done → summarize.
- **Second opinion / review:** finish a change, then `message_agent(other, "review this diff: …")`, read the critique, apply.
- **Pipeline:** Gemini researches → you implement → Codex reviews. Each hand‑off is read → message → read.
- **Monitor:** `read_pane` a build/test/shell pane to react to its output.

## Example
> User: "Have Codex implement the export button, then check its work."
1. `list_agents` → find `codex` pane `acc7bc6d-…`.
2. `read_pane(acc7bc6d-…)` → confirm it's idle.
3. `message_agent(acc7bc6d-…, "[from Claude] Implement an Export button in the toolbar that downloads the current view as JSON. Reply DONE when finished.")`
4. Wait; `read_pane(acc7bc6d-…)` until you see DONE + a summary.
5. Review the result and report back to the user.

If a tool errors with "Can't reach CodeGrid," the app isn't running. If `list_agents` shows only yourself, no other agents are open yet — tell the user to open another agent pane (`Cmd+N`).
