Since 2.3.1 OpenCode 2 reads CLAUDE.md of every directory without AGENTS.md, and ~/.claude/CLAUDE.md as the global fallback, into every prompt (source v2.3.2: packages/cli/src/server-process.ts reads OPENCODE_DISABLE_CLAUDE_CODE_PROMPT at server start for instructions.claude; documented in docs/instructions and migrate-v1). Measured on the pinned 2.3.2 in a sandbox (/var/tmp/ocv2-bac-e56, fake server, canary key): with the project's CLAUDE.md and the HOME one in place, both markers land in the system message of every request, for run and for serve; with OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1 both are gone and /api/info answers 200 JSON. On a box ~/.claude/CLAUDE.md is the owner's private file, which must not leave in every Agent tab prompt. So the v2 render of opencode-web (the CAP_LINE block of install-agent.sh, which the 1.x render does not share) now carries Environment=OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1, and the v2 oc launcher exports it with a :-1 default (0 is not truthy for opencode, so the user can bring the files back by hand). The 1.x unit and launcher are byte-identical to before. Tests red on the old code: the v2 unit carries the line, the v1 unit does not; the v2 launcher exports it to the child and yields to an explicit 0, the v1 one does not. Generated by Mistral Vibe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 KiB
opencode integration
What the installer writes for opencode, why each piece is there, and how to opt out.
The installer writes a complete, ready-to-use opencode config at ~/.config/qwen38/opencode.json (the API key is referenced via {file:...}, no secret inside). It contains one provider per installed lane (qwen38 for the 27B, flashnext for flash, flash-local, flash-unsloth, kolibri, nemotron, nemotron-super, ornith-122b, lfm25 and lfm3), the four Qwen ones with lean / low / medium / xhigh reasoning-effort variants (no variant = the patched template's default, lean, or Qwen's xhigh on a box installed with LEAN_DEFAULT=0, and on the Qwen3.8 Flash-Next FP4-Local lane installed with FLASH_LOCAL_EFFORT=xhigh, its model card's default (that lane's variants list xhigh first whatever its default: the order decides no request); the vLLM ones offer none / low / medium / high, but Ornith's none / high, as its template turns reasoning on or off and nothing between, and Liquid AI LFM3's high / none for the same reason, while Liquid AI LFM2.5 24B-A2B's offers none, as its template reasons before every answer and reads no switch and no level), and its default model follows the installed target (./switch-model.sh re-points it on every switch):
A box with no opencode config of its own gets this one as ~/.config/opencode/opencode.json
(since v1.18.4: before, it was printed as a cp command, and a first install left opencode,
oc and the Agent view with no provider for the box's own model, "Provider not found: qwen38").
A config you already have is kept: the installer merges the served lane's limits into it,
and adds the provider of a lane installed since (the 27B first, the flash lane later) when
it already has one of this repo's providers. When it has none of them, the installer says
so and leaves it alone: merge this repo's provider blocks (qwen38, flashnext, flash-local, flash-unsloth, kolibri, nemotron, nemotron-super, ornith-122b, lfm25, lfm3) from
~/.config/qwen38/opencode.json into it yourself.
oc # opencode on this box's model, with the output cap lifted (see below)
oc and the cockpit's Agent view also load that generated config through
OPENCODE_CONFIG, which opencode reads over your global one: their default is the model
this box serves even when your own config names another, and opencode can never fall back
to its free hosted model there. That fallback is what a fresh box got before v1.18.4 (with
no provider for the box, opencode answered with big-pickle, a cloud model). Plain
opencode reads only your own config.
Which opencode: one pinned version, on every box
Four things this repo does were read out of one opencode binary and checked against its
behaviour: the compaction threshold oc-fit-limits.py sizes the limits for, the hidden
32,000-token output cap the oc launcher lifts, the overflow phrases the proxy answers
with so that a refusal makes opencode compact instead of failing, and --yolo /
OPENCODE_PERMISSION for the Agent view. So install.sh pins the opencode it runs:
1.19.6 (OPENCODE_VERSION, with the sha256 GitHub publishes for
opencode-linux-arm64.tar.gz in OPENCODE_SHA256). CI runs the Agent view against that release
on its arm64 runners, with that digest; dashboard/tests/agent-bench.mjs also carries the digest of
opencode-linux-x64.tar.gz for the same release (X64_SHA256), for a run on an x86_64 machine: a new pin needs both. 1.18.32 was checked against the
1.18.27 the repo was measured on, on 2026-09-23: the same 21 overflow phrases and 3
exclusions verbatim, max_tokens 182,000 with the launcher's variable and 32,000 without
it on both (recorded on a fake endpoint), the same compaction and permission code once the
bundler's chunk names are set aside, serve --hostname and the hidden --yolo on both.
1.18.35 was checked against 1.18.32 the same way on 2026-10-10: the list of phrases and
exclusions is the same block of the binary byte for byte, max_tokens 32,000 and 182,000
on the fake endpoint again, serve --hostname and --yolo there, and the release diff
touches neither the compaction nor the permission code. What changed for this box: its
model requests carry one more header, x-opencode-session-id, with the session id
x-session-id already carried (the proxy and the engine pass it by), and opencode debug config prints a provider's key as ***, where 1.18.32 printed this box's key in clear.
1.19.4 was checked against 1.18.35 on 2026-10-22, the binaries side by side: the same 21
phrases and 3 exclusions, max_tokens 32,000 and 182,000 on the fake endpoint with the same
headers, the release diff leaves the compaction, overflow, permission, flag and request code
as it was, keys still masked, and the sessions one wrote the other lists and reads, both ways.
Behind a copy of the cockpit's relay, reached by a name that is not loopback as the tailnet
address is, both answered a prompt from the interface and ran a command in its terminal, and
the phone layer found the same parts of the interface. One thing changed for the relay: 1.19.4
sends its index chunked, where 1.18.35 sent a length, and the relay injected the phone layer
only into a document with a length (it reads a chunked one too since v1.38.6). It runs on
Bun 1.4.4 (read in its binary), whose Brotli carries the fix for CVE-2026-111497, an
out-of-bounds write in the decoder: 1.18.35 runs on Bun 1.3.14, without it, and the agent's
web fetch decodes whatever a page sends.
1.19.5 was checked against 1.19.4 on 2026-10-30, the binaries side by side again: the list of
phrases and exclusions is the same block byte for byte, max_tokens 32,000 and 182,000 on the
fake endpoint with the same headers, the same default permissions, --yolo still read as
--auto, keys masked, and the sessions one wrote the other lists and reads, both ways. Behind
a copy of the cockpit's relay, both answered a prompt, ran a command in the terminal and passed
the phone layer, and an endpoint that asked for a shell command naming an aliyuncs.com host had
it refused by both, under --yolo and under AGENT_AUTO's permission. The release diff lets a
terminal's ticket stand for the password only on the route the server dispatches the request
to, no longer on a pattern of its path, answers a request of the TUI's worker that fails
instead of leaving it waiting, updates the package of GitLab's provider, which this repo does
not use, and otherwise removes unused code: the compaction, overflow, permission, flag and request
code is as it was. It runs on the same Bun 1.4.4.
1.19.6 was checked against 1.19.5 on 2026-11-18, the binaries side by side: both assets match the
digests GitHub publishes, the 21 phrases and 3 exclusions are all there, and the block adds two,
request body too large and multimodal data size is too large; max_tokens 32,000 and 182,000 on
the fake endpoint with the same headers, the same default permissions, --yolo still read as
--auto, keys masked, the sessions one wrote the other lists and reads, both ways, and the
aliyuncs.com command refused by both under --yolo and under AGENT_AUTO's permission. On an
endpoint that refuses a request the way this box's proxy does (413 for a body past its cap, 400
context_too_long for a window passed), both compact and send it again; a 400 that says only
Request body too large failed the turn in 1.19.5 and is compacted and sent again in 1.19.6. Both
opencode run exit 1 after such a recovery, though the answer comes. The release diff adds those two
phrases and bounds the images a session sends inline (past 25 MiB, the oldest become a placeholder
until 15 MiB), and offers OpenCode 2 in the desktop application only; the permission, flag and
request code is as it was, on the same Bun 1.4.4. dashboard/tests/agent-bench.mjs passes 34 of 34
with it (the Agent view behind the cockpit's relay, its terminal and the phone layer).
What a run does with the opencode it finds:
| found | what install.sh does |
|---|---|
| none | downloads the pinned release, checks its sha256, installs it where opencode's own installer does (~/.opencode/bin) and adds that to PATH in ~/.bashrc |
| the pinned version | nothing |
an older one in ~/.opencode/bin |
replaces it the same way, checked |
| an older one elsewhere (npm, bun) | opencode upgrade <pinned>, opencode's own upgrader, which knows how it was installed |
an older one from opencode's own Homebrew tap (anomalyco/tap, sst/tap before the project moved, as its keg's install receipt says) |
the same upgrader, which runs brew upgrade and so moves it to the tap's own version, a 1.x (the pinned one on 2026-10-22) |
| an older one from Homebrew Core (or a keg whose install receipt names no tap) | keeps it and says how to get the pinned one: brew upgrade installs the formula's own version whatever version it is asked for, Homebrew Core's formula is OpenCode 2 now (2.1.2 on 2026-10-22), whose server is not the 1.x opencode serve the Agent view relays, and up to 1.19.1 the upgrader took it (brew uninstall opencode and a new run of the installer, or brew install anomalyco/tap/opencode, opencode's own 1.x formula) |
| a newer one | keeps it and says so: going back a version can leave sessions a newer opencode wrote unreadable |
Up to 1.18, left alone, opencode installed its own patch releases (read out of its binary:
only "autoupdate": false, "notify" or a minor/major release stopped it), which is how
two boxes installed a week apart ended up on two versions. 1.19 installs nothing by itself,
but with any value other than false its TUI checks every 10 minutes and, once it is on
the newest 1.x, shows "/update to upgrade to OpenCode 2.0" on its home screen; 1.18.35
announces 2.x as soon as GitHub's latest release is one. OpenCode 2's server is not the
1.x opencode serve the Agent view relays. So, with the pin, the generated config and
yours get "autoupdate": false: no check and no notice (OPENCODE_DISABLE_AUTOUPDATE=1
does the same for one run). The Agent view says when the opencode it serves is not the
pinned one. An update that installs the cockpit restarts the Agent view's server on a new
opencode, after the cockpit that relays it, whatever lane the box boots on and however that
opencode came (since v1.38.6: before, only an update with a text lane at boot did, and only
for a binary dated after the server's start, which npm and Homebrew do not give). An update
that installs no cockpit (--no-cockpit, or --no-start on a box booting a text lane) leaves
the server on the opencode it runs until it restarts.
dashboard/install-agent.sh never points it at OpenCode 2, whose server the Agent view is
not written for yet: it says so and keeps the opencode it runs.
OPENCODE_PIN=0 ./install.sh keeps whatever opencode you have and leaves autoupdate
alone. OPENCODE_VERSION=<x> OPENCODE_SHA256=<its digest> pins another release (a
version without its checksum is refused: it would not be a pin). A download that does
not match its sha256 is not installed, and nothing about opencode fails the rest of the
install.
OpenCode 2, opt-in
OpenCode 2 is not the default of anything: the box stays on the tested 1.19.6 until you ask. ./install.sh --opencode 2 (one-liner: | bash -s -- --opencode 2) installs the pinned 2.3.2 (GitHub's release asset, OPENCODE2_VERSION with its OPENCODE2_SHA256, refused without its checksum like 1.x), remembers the choice in ~/.config/qwen38/opencode.major, and wires everything to it: the Agent unit, the oc launcher, the generated config. ./install.sh --opencode 1 goes back: it takes this repo's permissions array out of your global config (OpenCode 1.19 refuses to start while one holds it, measured against 1.19.5 on 2026-11-14; an array that is not the one this repo wrote is left alone and said, with the way back), erases the marker and installs the pinned 1.x again. A stray 2.x found on the PATH (Homebrew Core's formula is one) never opts a box in: the choice wins, and a run that cannot download serves neither major as the other.
What the 2.x server is, measured on 2.3.0 on this box (the binary, its answers and its bundle, 2026-11-14 and 15):
servetakes--hostname --port --cors --serviceand the globals, and no--yolo:oclaunches 2.x with--auto, which approves every tool call no rule asks about (a rule of yours still asks, a deny still stops).- the unit's
ExecStartsays--print-logs --log-level info: 2.x refuses the capitals 1.x wants (Invalid value for flag --log-level: "INFO"), so the flag's case follows the major. - the health probe is
GET /api/info, JSON behind the Basic auth, and it must be read as JSON:/global/healthanswers the app's HTML page with a 200 on 2.x (the 1.x health route), so a probe that takes any 200 certifies a dead server. /api/config,/api/provider,/api/modelanswer the provider options after resolving{file:...}: the box's API key came back in clear on each of them, and/api/credentialcarries stored secrets too. The Agent relay reads these answers, scrubs every secret and refuses what it cannot read (compressed, not JSON, oversized), and asks for identity encoding to begin with. A path is classified after normalizing it, because the server's router answers/api//configand/foo/../api/configas/api/config.- the generated 2.x config adds what the 2.x defaults would otherwise leave open:
policiesdenyingprovider.useon theopencodeprovider (without it its free cloud models answer on/api/model, and an agent with no provider named goes there),share: "disabled",websearch: false,update: "disable", and thepermissionsarray (this repo's exfiltration denies, last-match-wins, kept under--auto, measured 2026-11-14). Those v2 keys are written only under the v2 choice: 1.19.5 will not start with apermissionskey in its config. - the approvals the unit injects ride
OPENCODE_CONFIG_CONTENT, which the server merges last (it is the document without a path in/api/config); the Agent panel reads the served documents, with the server's own matcher (oc-permissions.py, read in 2.3.0's bundle:*any run,?exactly one character, brackets and dot literal, whole-text match), and says in its guard line whether the exfiltration denies still deny. - 2.x reads neither
OPENCODE_PERMISSIONnorOPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX(dead names in the unit would lie): the output cap is the model'slimit.output, which the table writes as 32,000, measured on the build's own requests. - since 2.3.1, 2.x reads
CLAUDE.mdof every directory without anAGENTS.md, and~/.claude/CLAUDE.mdas the global fallback, into every prompt (measured on 2.3.2 in a sandbox: both files land in the system message of each request). On a box that is the owner's private file leaving in every Agent tab prompt, so the 2.x unit and the 2.xoclauncher both setOPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1, the documented switch read at server start (packages/cli/src/server-process.tsof 2.3.2;0is not truthy there, so it can be brought back by hand). The 1.x unit and launcher are unchanged. - the first boot migrates 1.x's session store (
GET /api/experimental/migration/v1follows it); going back to 1.x after a 2.x session is possible but the newer sessions are then unreadable by the older server, which is why the choice is yours.
Opting out
Do not want any of it? ./install.sh --no-opencode (one-liner: | bash -s -- --no-opencode) installs the API only: no generated config, no oc launcher, and switch-model.sh never touches your opencode default model. The choice is remembered by later runs (marker ~/.config/qwen38/opencode.off); ./install.sh --with-opencode turns it back on. Your own ~/.config/opencode/opencode.json is never rewritten in either mode: when the integration is on, the installer only merges into it the served lane's limits, its compaction block, the provider of a lane installed since, the default model when it is unset or already one of this box's (a default you pointed at another provider is yours, and stays) and, with the version pinned, "autoupdate": false, plus the shell deny rules (a deny holds under --yolo) and a lean variant for the 27B and flash models, each by a targeted edit that keeps your comments (in every form opencode accepts: //, /* */, trailing commas), your other providers and your line endings, with a dated backup first (the ten newest of each file are kept) and in one step, so a full disk leaves the file as it was.
What the shipped config gets right for you:
- The hidden 32K output cap: opencode sends
max_tokens = min(limit.output, OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX or 32000). Without that env var, a long thinking phase hits 32000 tokens, the turn ends silently (finish_reason: length, no text, no tool call) and you have to re-prompt. The installer ships anoclauncher (~/.local/bin/oc, skipped if an unrelatedocbinary exists) that exports the right value and execsopencode --yolo: launch withocinstead ofopencodeand the cap sits above every output limit this repo declares, on every target and in either context mode. It is deliberately a ceiling rather than the installed target's own number, becauselimit.outputis what follows a model switch: a ceiling copied from the installed target survives the switch and cuts the next lane's turn in the same silence (./oc-limits.sh --max-outis where both installers read it). Note that opencode's defaults already run every tool, the shell included, without asking, and--yoloalso approves what would ask (how the reference box runs): for a prompt before each shell command, put"*": "ask"in the"bash"object of your config and start plainopencode(agents and the network). - Limits that can never 400: the server rejects any request where
input + max_tokensexceeds the window (no clamping), and the prompt opencode sends can reach its compaction point (limit.inputminus 20,000) plus one agent step (up to 43,863 tokens measured on this box). So the config shipscontext/input 173000, output 64000in native mode (173,000 - 20,000 + 43,863 + 64,000 = 260,863, under 262,144, whether the 32K cap is lifted or not),205000/32000on the flash lane (and on the Liquid AI LFM3 lane, whose window is the same 262,144),74000/32000on the Liquid AI LFM2.5 24B-A2B lane, whose window is 131,072 (74,000 - 20,000 + 43,863 + 32,000 = 129,863), and700000/200000in 1m mode as a starting pair. Until v1.18.7 the native pair was 194048/64000 and the flash one 225000/32000: both fitted a prompt of exactlycontext, not the one a large step brings past compaction, so a request in that band got a 400 that opencode then compacted on. The 1m pair is a starting pair, which the installer then fits to the pool the boot actually got (oc-fit-limits.py, after step 9): the pool changes from boot to boot (832,993 to 922,094 tokens over sixteen 27B boots on the reference box), and that pair does not fit the smaller ones. Since v1.18.2 the cockpit does the same fit by itself after a switch and a Start. Both fits hold the same window rule, and on a 262,144 window they never go above the lane's pair above (v1.18.7). - Reasoning-effort variants: the generated config declares
lean,low,mediumandxhighvariants (ctrl+t in the TUI),leanfirst because it is what a turn that picks none gets: the patched template's default since v1.13, measured in LEAN.md (LEAN_DEFAULT=0 ./install.shkeeps Qwen'sxhighas the default and still offerslean). This works because the patched template acceptsleanand maps other clients' effort tiers (max/high→xhigh,minimal→low, contributed by helge); any client sending an unmapped tier would get a 500 on the stock template. - Mid-conversation system messages: some agent clients inject system messages after turn 1, and opencode 1.19.4 sends two before the first user message; the stock template raises
System message must be at the beginning. Patched to render them as<system-reminder>blocks, on every lane whose template raises it: the 27B, the two flash lanes and, since v1.40.2, Ornith. - Vision declared:
attachment+modalitiesare set, so image attachments and on-disk image reads work end to end (the model is natively multimodal). The two Liquid AI lanes read no image, and their providers declare text only.
On service installs the generated config points at the keepalive proxy port (PORT+1), not the server directly, and that is deliberate: SGLang buffers tool-call arguments while they stream (127 s of measured silence on one 400-line file write, at native context), and opencode drops a stream after roughly 140-180 s without a real chunk. The proxy (qwen38-keepalive.service, vendored keepalive-proxy.py) fills those silences with protocol-correct keepalives, at SSE event boundaries only, and makes sure a client that gives up does not leave a generation running (v6.14: it names every request with x-override-rid so it can abort one that has not produced anything yet, aborts before closing the socket, and drains the answer where the engine offers no rid to abort with). Since v1.22.5 (proxy v6.31) it also keeps a stream the engine has not started: SGLang sends a stream's headers with its first chunk, after the queue and the prefill, and opencode 1.18.32 gives up on a response whose headers have not come in 300 s (headerTimeout, its default) and sends the request again, while the engine keeps the one it gave up on queued. The proxy opens such a stream itself after 10 s and keeps it alive until the engine answers, and a caller that leaves before then has its request ended in the engine. Several agents at once (opencode's sub-agents, or several sessions) share the lane's KV pool, and past it every turn computes its whole prompt again: keep the sum of their contexts under the pool (flash-lane.md has the measurements). With ./install.sh --no-service there is no proxy: the config then points at the server directly, and huge single-file writes may abort. One more caveat, measured: SGLang's --api-key only accepts Authorization: Bearer, not x-api-key.