Multi-agent coordination for OpenCode. Lets multiple AI agents in separate OpenCode sessions talk to each other.
Warning: This enables autonomous agent-to-agent communication which triggers LLM API calls. Use at your own risk. Consider enabling rate limiting to control costs.
The daemon starts an OpenCode hub server (opencode serve --port 4096) and discovers sessions by polling OpenCode's shared SQLite database
A coordinator session facilitates introductions between new agents, then steps back
Agents communicate by writing JSON files to ~/.agent-hub/messages/ via the agent-hub-mcp tools
The daemon watches for new message files, looks up the target agent's session, and injects the message via prompt_async — agents don't poll, they get woken up
Known Limitations
Injected messages not visible in TUI — agent-to-agent messages work but users can't see them in the conversation. Upstream issue: opencode#8564. Use agent-hub-watch to monitor.
TUI spinner after response — the TUI may briefly show "thinking" after an agent finishes responding to an injection. Visual only, no extra token consumption.
Orientation may trigger security heuristics — some models (particularly Claude) may flag orientation messages as prompt injections. The agent still has MCP tools and can collaborate, just without orientation context.
Prerequisites
agent-hub-mcp must be configured in OpenCode. The daemon will refuse to start without it.
Find your OpenCode config location with opencode debug paths, then add to opencode.json:
The coordinator is a dedicated OpenCode session that introduces agents to each other. It starts non-blocking and uses the same message pipeline as any other agent.
Variable
Default
Description
AGENT_HUB_COORDINATOR
true
Enable coordinator
AGENT_HUB_COORDINATOR_DIR
~/.agent-hub/coordinator
Coordinator working directory
AGENT_HUB_COORDINATOR_PRESERVE_LOCAL_AGENTS_MD
false
Keep existing AGENTS.md on restart
AGENT_HUB_COORDINATOR_READY_TIMEOUT
60
Bootstrap ready timeout (seconds)
AGENT_HUB_COORDINATOR_STRICT_READY
false
Require exact READY acknowledgment
AGENT_HUB_COORDINATOR_BOOTSTRAP_REQUIRED
false
Fail startup if bootstrap times out
AGENT_HUB_COORDINATOR_AGENTS_MD
(auto-detect)
Custom AGENTS.md path
The coordinator model is configured in opencode.json within the coordinator directory (default: opencode/minimax-m3). Custom coordinator instructions (AGENTS.md) are auto-detected from the config directory, package template, or system paths — override with AGENT_HUB_COORDINATOR_AGENTS_MD.
Message Format
Messages are JSON files in ~/.agent-hub/messages/:
Required fields: from, to, content. Messages are validated with pydantic on receipt; malformed messages are rejected with delivery feedback to the sender.
Install with uv sync --all-extras. Pre-commit hooks enforce linting, formatting, type checking, and tests automatically. See CONTRIBUTING.md for setup and workflow. See AGENTS.md for injection pipeline internals and test-writing conventions.