Skip to content

Integration guide

OpenCode Swarm Multi-Agent Setup & Role-Based Model Config

Multi-agent sessions in OpenCode Swarm spawn parallel coder, reviewer, and test subagents that multiply token volume 5x–10x. Decouple roles from models on one Relay API key: keep architect on claude-opus-5-5 (-50%), audit diffs with gpt-6.1-sol (-30%), and offload parallel coder/test workers to deepseek-v4.1-flash ($0.18/1M, $0.0895/1M off-peak) or claude-haiku-5-5 ($0.05/1M).

Recommended OpenCode Swarm Role-to-Model Routing Matrix

Per-role model assignment, mode, USD per 1M token rate, and tool scope
Swarm RoleModeRelay Model IDRelay USD / 1M (In / Out)Permission Scope
architectprimaryrelay/claude-opus-5-5$2.00 / $10.00 (-50% · $0.10 cache)Plan & delegate (write: false, edit: false)
codersubagentrelay/deepseek-v4.1-flash · relay/glm-5.3$0.18 / $0.74 ($0.0895 / $0.37 off-peak)Parallel git worktree edits & bash
reviewersubagentrelay/gpt-6.1-sol$1.40 / $7.00 (-30%)Cross-family diff audit (edit: deny, bash: deny)
test_engineersubagentrelay/claude-haiku-5-5$0.05 / $0.25 (-50%)Unit test execution & lint triage

Setup

  1. 1

    Register ProxyStacks Relay once via opencode /connect (saved to ~/.local/share/opencode/auth.json) or declare provider.relay in ./opencode.jsonc with baseURL "https://proxystacks.com/v1" and apiKey "{env:RELAY_API_KEY}".

  2. 2

    Map native OpenCode roles under "agent" in ./opencode.jsonc (or under "agents" in .opencode/opencode-swarm.json): bind architect to relay/claude-opus-5-5 (-50%) and coder/test_engineer to relay/deepseek-v4.1-flash or relay/glm-5.3.

  3. 3

    Lock read-only boundaries on reviewer with "permission": { "edit": "deny", "bash": "deny" } and set "experimental": { "subagent_depth": 2 } so parallel worktree lanes cannot mutate files outside coder tasks.

Configuration

deepseek-v4.1-flash
./opencode.jsonc (agent roles)
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "relay": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "ProxyStacks Relay",
      "options": {
        "baseURL": "https://proxystacks.com/v1",
        "apiKey": "sk-relay-your-key"
      },
      "models": {
        "claude-opus-5-5": { "name": "Claude Opus 5.5", "limit": { "context": 1000000, "output": 64000 } },
        "deepseek-v4.1-flash": { "name": "deepseek-v4.1-flash", "limit": { "context": 1000000, "output": 64000 } },
        "gpt-6.1-sol": { "name": "GPT-6.1 Sol", "limit": { "context": 1000000, "output": 64000 } },
        "claude-haiku-5-5": { "name": "Claude Haiku 5.5", "limit": { "context": 200000, "output": 32000 } }
      }
    }
  },
  "model": "relay/claude-opus-5-5",
  "small_model": "relay/deepseek-v4.1-flash",
  "agent": {
    "architect": {
      "mode": "primary",
      "model": "relay/claude-opus-5-5",
      "temperature": 0.1,
      "tools": { "write": false, "edit": false, "bash": true }
    },
    "coder": {
      "mode": "subagent",
      "model": "relay/deepseek-v4.1-flash",
      "temperature": 0.2
    },
    "reviewer": {
      "mode": "subagent",
      "model": "relay/gpt-6.1-sol",
      "permission": { "edit": "deny", "bash": "deny" }
    },
    "test_engineer": {
      "mode": "subagent",
      "model": "relay/claude-haiku-5-5"
    }
  },
  "experimental": {
    "subagent_depth": 2
  }
}

Route architect to claude-opus-5-5 (-50%), reviewer to gpt-6.1-sol (-30%), and parallel coder subagents to deepseek-v4.1-flash ($0.18/1M, $0.0895/1M off-peak) in opencode.jsonc or .opencode/opencode-swarm.json.

Advanced config: environment variable API key, multi-model routing & max output tokens

Use a project-specific config or multi-profile setup with environment variable keys, flagship and fast models — Claude Opus/Sonnet 5.5 (-50%), GPT-6.1 Sol / GPT-6 Luna (-30%), DeepSeek V4.1 Flash (-40%), GLM-5.3 & Kimi K3.1 Pro (-30%) — and explicit context/output token limits.

.opencode/opencode-swarm.json
{
  // .opencode/opencode-swarm.json (or ~/.config/opencode/opencode-swarm.json)
  // Overrides per-role models for the OpenCode Swarm plugin while keeping a single Relay balance
  "agents": {
    "architect": {
      // -50% vs official USD ($2.00 / $10.00 per 1M, $0.10 cache read)
      "model": "relay/claude-opus-5-5"
    },
    "coder": {
      // Parallel worktree execution: $0.18/1M standard, $0.0895/1M Beijing Time off-peak
      "model": "relay/deepseek-v4.1-flash"
    },
    "reviewer": {
      // Cross-family diff & security audit (-30% vs official USD: $1.40 / $7.00 per 1M)
      "model": "relay/gpt-6.1-sol"
    },
    "test_engineer": {
      // Fast test runner & lint triage (-50% vs official USD: $0.05 / $0.25 per 1M)
      "model": "relay/claude-haiku-5-5"
    }
  }
}

Troubleshooting

  • 401: check the Relay key and authentication header. Never paste a secret into a support ticket.
  • 404: use an exact published model ID and the documented base URL, not an upstream alias.
  • For streaming use stream: true. Codex uses Responses; keep disable_response_storage = true.

Common questions

What is the difference between "agent" in opencode.jsonc and .opencode/opencode-swarm.json?

OpenCode's built-in "agent" block in ./opencode.jsonc (or Markdown files under .opencode/agents/*.md) defines native primary and subagent roles with per-role model, temperature, tools, and permission rules. If you install the OpenCode Swarm orchestration plugin, it additionally reads .opencode/opencode-swarm.json (or ~/.config/opencode/opencode-swarm.json) under the "agents" key to override models for architect, coder, reviewer, and test_engineer across parallel git worktrees.

How much does role-based model routing save in an OpenCode Swarm session?

If every subagent inherits a flagship model by default, 4–6 parallel coder and test loops quickly burn flagship output tokens. Keeping architect on relay/claude-opus-5-5 ($2.00/$10.00 per 1M, -50% vs official USD), reviewer on relay/gpt-6.1-sol ($1.40/$7.00, -30%), and routing coder + test_engineer to relay/deepseek-v4.1-flash ($0.18/$0.74 standard, $0.0895/$0.37 off-peak) or relay/claude-haiku-5-5 ($0.05/$0.25) cuts total multi-agent session spend by 60%–80% on one prepaid balance.

How do I stop review or planning subagents from editing files or spawning infinite loops?

Set "permission": { "edit": "deny", "bash": "deny" } (or "tools": { "write": false, "edit": false }) on read-only roles like reviewer and architect, and cap nesting with "experimental": { "subagent_depth": 2 } in ./opencode.jsonc.

All docs