OpenCode Integration
This page describes how OpenCode (the agent coding tool) integrates with the Yabanin gateway — i.e., the gateway-side contract: which models OpenCode is routed to, how subscription executors are delegated, and how an OpenCode-driven session is governed (budgets, task tagging, guard hooks).
Local development, stand-up, and credential handling are covered in the Development Guide. This page does not repeat that setup; it documents the integration surface itself.
Model routing for the yabanin agent
The yabanin OpenCode agent talks to the gateway's OpenAI-compatible endpoint
(POST /v1/chat/completions). The gateway routes each request by task shape, so
the agent's "thinking model" and its "fast coder" can be different providers
under one key. The routing decision is exposed on the
X-Yabanin-Decision response header (see
Agent Governance — Decision header) so a
session can log why a given response used a given model.
Agent wiring (make opencode-remote-wire, the public stand at
https://yabanin.ai/gw) routes the OpenCode agents through Yabanin gateway
models and routes by task shape:
| Route | Model | Used for |
|---|---|---|
Primary agent yabanin | the configured planning model | Session leading, planning, complex reasoning. |
Subagent reason | the configured analysis model | Deep analysis, architecture, trade-offs, research synthesis. |
Subagent code | the configured local coder | Clear, well-specified code edits — templates, tests, docs, instruction-driven refactors. |
Subagent complex-code | the configured flash model (with fallback) | Heavy algorithmic codegen. |
The concrete model names are deployment configuration (registry / org routing settings), not part of the gateway contract. What the contract guarantees: a request is routed deterministically by class, the decision is logged, and cache / cost / tier accounting all apply exactly as they do for any API-key client.
Subscription delegation (tr_delegate)
For hard coding tasks, OpenCode can delegate to a Codex or Cursor
subscription executor through the local MCP tool tr_delegate:
tr_delegate { mode: "analyze" | "implement", task: "…", provider?: "auto" | "codex" | "cursor" }analyzeis read-only review;implementwrites to the workspace.provider: autopicks the available executor;codex/cursorforce one.tr_delegation_statusreports whether each executor is configured (it does not return credentials).
Delegation is off by default and enabled with
YABANIN_DELEGATION_ENABLED=true. Credentials stay on the machine (Codex from
~/.codex/auth.json, Cursor from official agent login); the gateway never
sees them. Delegation is a sidecar concern (services/subscription-bridge/); the
gateway only handles the OpenAI-compatible chat/tool traffic.
Delegate only when the in-agent routes above are not enough — the leading model should use its native tools for ordinary work.
Governing an OpenCode session
Because an OpenCode-driven session is just a gateway client, the full agent governance surface applies. The practical recommendations:
- Task tag every logical unit of work. Send
X-Yabanin-Taskper task (e.g.stand-opencode/feature-42). This makes the session's spend attributable in CTOR / task analytics and lets you cap it withYABANIN_TASK_TOKEN_BUDGET. - Cap runaway sessions. Set
YABANIN_TASK_TOKEN_BUDGET(recommended 500000) and/orYABANIN_SESSION_TOKEN_BUDGET(recommended 200000). At ≥80% the gateway setsX-Yabanin-Budget-Warning; at 100% it returns a 429 the client can back off on. - Route cheap work to cheap hours. Enable
YABANIN_TIME_ROUTINGwith aYABANIN_TIME_CHEAP_WINDOW(default22:00-07:00); batch work (X-Yabanin-Batch: true) is always downgraded, interactive work can opt out withX-Yabanin-Priority: high. - Screen egress. For sessions that may emit sensitive data, run
YABANIN_GUARD_MODE=log(observe) and tighten toredact/denyonce the false-positive profile is known. See the guard-hook FP caveat. - Verify the lineage. After a run,
yb lineage verify --org <org>confirms the per-request attestation chain is intact, andyb lineage export … --s3 … --lock-complianceproduces a WORM evidence copy. See Lineage — hash chain + export.
Evaluation before shipping routing changes
Because OpenCode traffic is the real load on the router, regression-test routing and guard changes with the offline suites before they reach a stand:
make evaluate-routing
make evaluate-guards
See Evaluation Suites.