@timmyjl12/pi-opencode-bridge
v0.2.3
Published
Owned OpenCode bridge for Pi: registers oc-bridge / oc-go-bridge providers over the local opencode CLI. Free models work without login; all catalog models available. Built-in opencode/opencode-go providers are never touched.
Readme
pi-opencode-bridge (@timmyjl12/pi-opencode-bridge)
Owned replacement for the npm pi-opencode-bridge package. Registers two bridge
providers in Pi that delegate model calls
to the local opencode CLI:
| Provider | Catalog | Notes |
|---|---|---|
| oc-bridge | opencode/* (Zen) | free models work without OpenCode login |
| oc-go-bridge | opencode-go/* (Go) | same, Go catalog |
pi's built-in opencode / opencode-go providers are never touched — they
serve normal models and back the opencode-go/* fallback-chain / thinking-map
entries in settings.
Why a bridge (not plain API providers)?
Free models (*-free) are refused by OpenCode's plain chat-completions endpoints
(429/400, with or without a key) but work through the CLI with no login. The
bridge therefore spawns opencode run -m <provider/model> --format json per
turn and maps the NDJSON stream into pi's model stream. pi's tools cross the
boundary via a <pi_tool_call> marker protocol (OpenCode's own tools disabled).
Install
pi install npm:@timmyjl12/pi-opencode-bridgeor run ad hoc: pi -e npm:@timmyjl12/pi-opencode-bridge. The provider ids stay oc-bridge and oc-go-bridge.
Commands
/oc-bridge-status— CLI binary, catalog counts, fallback state
Failure policy
No silent failures: missing opencode binary, empty catalog, or unparseable
CLI output raises a visible warning naming the cause and the remedy. Model
discovery is live (opencode models) with a curated fallback list.
Testing
Two committed layers, both hermetic (no network model calls):
npm test— helper-level tests: catalog cache/auth, marker and DSML parsing, thinking levels, usage math (node --test test/*.test.ts).powershell -ExecutionPolicy Bypass -File test\run-battery.ps1— stub-CLI battery over a realpiprocess: marker/tolerant-tag/chunk-split/DSML round trips, empty responses, key hygiene, thinking variants (max → #max, unsupported levels clamp), reload safety. Needspiandnodeon PATH.
Run both after touching the parser, the thinking-level mapping, or when an upstream OpenCode change is suspected.
Thinking levels
/thinking offers exactly the effort values the OpenCode catalog advertises for the selected
model (capabilities.reasoning.effort): GLM-5.3, for example, offers low, high, and max
— nothing else. The selected level crosses the bridge as an OpenCode model variant:
opencode run -m opencode/glm-5.3#max --thinking ...- Levels the catalog does not list are hidden, so pi clamps a stored unsupported level to the
nearest offered one instead of sending a variant the CLI rejects (
provider.no-route). offis offered only when the catalog can disable thinking (none); otherwise the lightest real effort is the floor and pi clampsoffto it.- A model with no effort metadata keeps pi's default levels (
off–high) and runs at the provider's default effort (no variant).
Compatibility
Checked against the installed CLI (2026-11-26):
| Component | Version | What the bridge uses |
|---|---|---|
| opencode CLI | 2.4.1 | run --format json, -m provider/model#variant, --agent, --auto, --thinking; NDJSON text / reasoning / step-start / step-finish / error |
| @opencode/schema | 2.4.2 | capabilities.reasoning.effort, model selection {providerID, model, variant?}, step-finish tokens/cost |
| @opencode/sdk | 2.4.2 | current SDK line (the older @opencode-ai/sdk 1.x describes the v1 CLI) |
Known limitations
- Images are not bridged — bridge models are registered text-only; image parts are referenced as
[image … omitted]in the prompt. - Free models share an upstream free-usage quota (429
FreeUsageLimitErrorwhen exhausted; surfaces as a normal bridge error). - Bridge turns are latency-heavy — every turn spawns
opencode runwith the full transcript (measured 37.8s for a trivial turn on 2026-11-05); multi-step agentic tasks take minutes. A persistent-server transport is the documented swap-in if this bites. - Usage is reported when the CLI reports it —
step-finishcarries tokens and billed cost on CLI 2.4.x; very old CLI versions emit neither and show 0. - The bridge is text-marker tool calling — models that ignore the
<pi_tool_call>protocol produce plain text instead of tool calls (the prompt and a deterministic parser minimize this; echoed transcript reminders are filtered out).
Uninstall / shared state
The extension creates one file outside its repo on first run — the deny-all
agent profile ~/.config/opencode/agents/oc-bridge.md (created if missing;
rewritten only when it still matches an older extension-generated version, with
a .bak-pre-v2 backup kept beside it). It keeps spawned OpenCode turns tool-less. After removing
the extension, optionally delete it:
Remove-Item "$env:USERPROFILE\.config\opencode\agents\oc-bridge.md"Plan
Work is tracked under .plan/replace-opencode-bridge/.
