Skip to main content

opencode-agent-hub

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.

Demo

https://github.com/user-attachments/assets/b591f1d2-01d7-4408-bf60-67eb7a8fbf0c

How It Works

  • 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:

{
  "mcp": {
    "agent-hub": {
      "type": "local",
      "command": ["npx", "-y", "agent-hub-mcp@latest"],
      "enabled": true
    }
  }
}

Verify with opencode mcp list (should show agent-hub connected).

Quickstart

git clone https://github.com/xnoto/opencode-agent-hub
cd opencode-agent-hub

# Terminal 1: start the daemon
uv run agent-hub-daemon

# Terminal 2: monitor activity
uv run agent-hub-watch

Installation

Homebrew (macOS)

brew install xnoto/opencode-agent-hub/opencode-agent-hub

Linux Packages

Debian / Ubuntu:

curl -fsSL https://xnoto.github.io/opencode-agent-hub/KEY.gpg | sudo gpg --batch --yes --dearmor -o /etc/apt/keyrings/xnoto.gpg
echo "deb [signed-by=/etc/apt/keyrings/xnoto.gpg] https://xnoto.github.io/opencode-agent-hub/apt ./" | sudo tee /etc/apt/sources.list.d/xnoto.list
sudo apt update && sudo apt install opencode-agent-hub

Rerun the first command to refresh an existing keyring after the repository signing key is renewed.

Fedora / RHEL:

sudo curl -o /etc/yum.repos.d/xnoto.repo https://xnoto.github.io/opencode-agent-hub/xnoto.repo
sudo rpm --import https://xnoto.github.io/opencode-agent-hub/KEY.gpg
sudo dnf install opencode-agent-hub

Arch Linux (AUR):

yay -S opencode-agent-hub

See GitHub Releases for direct .deb/.rpm downloads.

uv / pipx (PyPI)

uv tool install opencode-agent-hub
# or
pipx install opencode-agent-hub

From source

git clone https://github.com/xnoto/opencode-agent-hub
cd opencode-agent-hub
uv sync

Running as a Service

macOS (Homebrew)

brew services start opencode-agent-hub
tail -f ~/Library/Logs/agent-hub-daemon.log
brew services stop opencode-agent-hub

Linux (systemd)

agent-hub-daemon --install-service     # install + start
journalctl --user -u agent-hub-daemon -f
systemctl --user stop agent-hub-daemon
agent-hub-daemon --uninstall-service   # remove

If installed via RPM/DEB, a system-wide service file is included — enable with systemctl --user enable --now agent-hub-daemon.

Configuration

Config file: ~/.config/agent-hub-daemon/config.json (all fields optional). Environment variables override config file values.

{
  "hub": {
    "port": 4096,
    "model": "opencode/minimax-m3"
  },
  "log_level": "INFO",
  "rate_limit": {
    "enabled": false,
    "max_messages_per_window": 100,
    "window_seconds": 3600,
    "cooldown_seconds": 5
  },
  "coordinator": {
    "enabled": true,
    "directory": "~/.agent-hub/coordinator",
    "agents_md": ""
  },
  "agent": { "stale_seconds": 600 },
  "message": { "ttl_seconds": 3600 },
  "poll": { "session_seconds": 5, "gc_seconds": 60, "metrics_seconds": 60 },
  "cache": { "session_ttl_seconds": 5 },
  "injection": { "workers": 3, "retries": 3, "timeout_seconds": 30 },
  "orientation": { "retry_delay_seconds": 30, "retry_max": 5 }
}

Environment Variables

Variable Default Description
OPENCODE_PORT 4096 Hub server port
AGENT_HUB_MODEL opencode/minimax-m3 Hub server default model (provider/model)
AGENT_HUB_DEFAULT_AGENT (none) Agent name for undetectable sessions
AGENT_HUB_DAEMON_LOG_LEVEL INFO Log level
AGENT_HUB_MESSAGE_TTL_SECONDS 3600 Message TTL (seconds)
AGENT_HUB_AGENT_STALE_SECONDS 600 Agent stale threshold (seconds)
AGENT_HUB_SESSION_POLL_SECONDS 5 Session poll interval (seconds)
AGENT_HUB_GC_INTERVAL_SECONDS 60 GC interval (seconds)
AGENT_HUB_METRICS_INTERVAL 60 Metrics write interval (seconds)
AGENT_HUB_SESSION_CACHE_TTL 5 Session cache TTL (seconds)
AGENT_HUB_INJECTION_WORKERS 3 Injection worker threads
AGENT_HUB_INJECTION_RETRIES 3 Injection retry attempts
AGENT_HUB_INJECTION_TIMEOUT 30 Injection timeout (seconds)
AGENT_HUB_ORIENTATION_RETRY_DELAY 30 Orientation retry delay (seconds)
AGENT_HUB_ORIENTATION_RETRY_MAX 5 Max orientation retries

Rate Limiting

Variable Default Description
AGENT_HUB_RATE_LIMIT_ENABLED false Enable rate limiting
AGENT_HUB_RATE_LIMIT_MAX_MESSAGES 100 Max messages per agent per window
AGENT_HUB_RATE_LIMIT_WINDOW_SECONDS 3600 Window size (seconds)
AGENT_HUB_RATE_LIMIT_COOLDOWN_SECONDS 5 Min seconds between messages

Coordinator

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/:

{
  "from": "agent-id",
  "to": "target-agent-id",
  "type": "message|completion|delivery-status|task|question|context|error",
  "content": "Message content",
  "priority": "normal|urgent",
  "threadId": "auto-generated-or-provided",
  "timestamp": 1234567890000
}

Required fields: from, to, content. Messages are validated with pydantic on receipt; malformed messages are rejected with delivery feedback to the sender.

Directory Structure

~/.agent-hub/
├── agents/                 # Registered agent files
├── messages/               # Pending messages
│   └── archive/            # Processed messages
├── threads/                # Conversation threads
├── metrics.prom            # Prometheus metrics (prometheus_client format)
├── oriented_sessions.json  # Orientation cache
└── session_agents.json     # Session-to-agent mapping

~/.config/agent-hub-daemon/
└── config.json             # Optional config

Development

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.

Acknowledgments

License

AGPL-3.0 - See LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencode_agent_hub-1.6.2.tar.gz (89.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opencode_agent_hub-1.6.2-py3-none-any.whl (73.3 kB view details)

Uploaded Python 3

File details

Details for the file opencode_agent_hub-1.6.2.tar.gz.

File metadata

  • Download URL: opencode_agent_hub-1.6.2.tar.gz
  • Upload date:
  • Size: 89.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for opencode_agent_hub-1.6.2.tar.gz
Algorithm Hash digest
SHA256 f8e0bc064b713f448dd6e77e41c4d06ab04d395c2bf620f340d260d6d9933fe6
MD5 2d2e880a2b86f69ec4b7c5b3603f56a0
BLAKE2b-256 d64a1a9d51cf04fd8044184e84ba4b5c37a46fc21a382b4e21309e04a672e379

See more details on using hashes here.

File details

Details for the file opencode_agent_hub-1.6.2-py3-none-any.whl.

File metadata

File hashes

Hashes for opencode_agent_hub-1.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dc42d4992d10ef3abacef18c0393afb9b1cb4769ac6fdb1c6488edc345519435
MD5 46ea98ae178431b066d93ff0556b903a
BLAKE2b-256 32d4c5ee01deee5225ec4a4f8e0c457cf4e6fbd57c9dd3a539595ac40984c971

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.6.2 This release

2 files

1.6.1

2 files

1.6.0

2 files

1.5.0

2 files

1.4.3

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.5

2 files

0.3.4

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page