opencode-mega-agent
v0.4.0
Published
OpenCode plugin for MegaRouter cloud agents — auto-discovers and registers specialist AI agents (code review, security audit, debugging, etc.) as native subagents
Maintainers
Readme
opencode-mega-agent
OpenCode plugin that connects MegaRouter cloud agents to your editor. Agents are domain-trained specialist AIs (code reviewer, security auditor, debugger, etc.) that can read files, run commands, and search your codebase.
Quick Start
npm install opencode-mega-agentAdd to opencode.json:
{
"plugin": ["opencode-mega-agent"],
"provider": {
"mega-router": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.megarouter.ai/v1",
"apiKey": "sk-mega-..."
}
}
}
}Restart OpenCode. Done — cloud agents appear as native subagents.
Getting an API Key
Sign in at megarouter.ai with your wallet, navigate to API Keys, and click Create New Key. Copy the key immediately — it's shown only once. First key creation grants free credits.
How It Works
On startup the plugin:
- Discovers agents — calls
GET /api/v1/agentsto fetch the catalog - Injects config — registers each agent as a native subagent (
cfg.agent) and model (cfg.provider.models) - Caches manifest — writes
.opencode/.mega-router-agents.jsonfor offline resilience - Injects system prompt — teaches the AI about available agents and how to invoke them
Invocation
Cloud agents run as native OpenCode subagents with full tool access (read files, run commands, edit code):
task(subagent_type="code-reviewer", prompt="Review auth.go for security issues")Available Agents
| Agent | Specialty | |-------|-----------| | code-reviewer | Code review — bugs, security, style | | security-reviewer | OWASP security audit | | frontend-advisor | Frontend/UX — components, a11y, performance | | code-debugger | Root cause debugging | | devops-cli | Infrastructure & deployment | | doc-writer | Technical documentation | | data-analyst | Data analysis & visualization | | research-assistant | Deep research with citations | | git-assistant | Git workflow — commits, rebases | | api-tester | API endpoint testing | | office-hours | Product/business brainstorming | | creative-writer | Stories, poems, copywriting |
Offline / Backend Down
If the MegaRouter API is unreachable at startup, the plugin loads agents from:
- Disk cache (
.opencode/.mega-router-agents.json) — from last successful discovery - Hardcoded fallback — built-in list of 12 standard agents
Configuration
| Source | Priority | Notes |
|--------|----------|-------|
| opencode.json provider.mega-router.options | 1st | Recommended |
| MEGAROUTER_BASE_URL / MEGAROUTER_API_KEY env vars | 2nd | Fallback |
Troubleshooting
"Authentication failed" — API key is invalid or expired. Check opencode.json → provider.mega-router.options.apiKey.
"Insufficient credits" — MegaRouter balance is too low. Top up at the dashboard.
Agents not showing up — Ensure the backend is reachable at the configured baseURL. Check .opencode/.mega-router-agents.json for cached state.
Using with Claude Code
For Claude Code users, cloud agents are available via the MCP server (mega-router-mcp) or through the cloud_agent tool defined in CLAUDE.md. See the project root for setup instructions.
Local Development
For contributors working on the MegaRouter codebase:
# 1. Start all services
make dev # starts PostgreSQL, backend, frontend
# 2. Generate a dev API key (auto-updates opencode.json)
make genkey
# 3. Use local plugin path in opencode.json
{
"plugin": ["./plugins/opencode-cloud-agent"],
"provider": {
"mega-router": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "http://127.0.0.1:8080/v1",
"apiKey": "sk-mega-..."
}
}
}
}
# 4. Run plugin tests
cd plugins/opencode-cloud-agent && npx vitest run
# 5. Run backend tests
cd backend && go test -race ./...
# 6. CLI integration test (headless)
opencode run --format json "use the code-reviewer agent to review main.go"Publishing
# Bump version in package.json, then:
npm config set //registry.npmjs.org/:_authToken=$NPM_AUTOMATION_TOKEN
npm publish --access public
npm config delete //registry.npmjs.org/:_authToken