opencode-v2
GitHub指导处理 OpenCode 2.x 相关开发任务,涵盖路由、事件、会话模型及插件机制。用于排查 OpenChamber 与 OpenCode 集成问题,确保基于 2.x API 而非旧版 1.x 进行修复和开发。
Trigger Scenarios
Install
npx skills add openchamber/openchamber --skill opencode-v2 -g -y
SKILL.md
Frontmatter
{
"name": "opencode-v2",
"description": "Load for any work that touches OpenCode — its routes, events, message or session shapes, plugins, the pinned CLI\/client version, \"what's new in OpenCode 2.0.x\", or a bug that looks like OpenCode behaving differently than OpenChamber expects. OpenChamber runs on OpenCode 2.x since 2026-09; 1.x code paths are gone."
}
OpenCode 2.x in this repository
OpenChamber moved from the OpenCode 1.x API to 2.x in one cutover (PR #3837,
2026-09). Everything OpenCode-facing speaks 2.x: routes under /api/*, one
global /api/event stream of session.* events, sessions as cursor-paged
lists, messages with their parts inline, plugins hot-reloaded from watched
config, @opencode/client + @opencode/schema as the only SDK. A bug report
that mentions 1.x behaviour (/session without /api, message.updated
events, auth.json, @opencode-ai/sdk) describes the old world; answer from
the 2.x code, not from memory of 1.x.
Where the boundary lives
packages/ui/src/lib/opencode/client.ts— every official OpenCode call the shared UI makes;projection.tsturns wire shapes into the OpenChamber domain model inmodel.ts;events.tstranslates wire events;plugins.tstranslates the experimental plugin routes;session-stats.tstranslates the experimentalsession.statsusage route;websearch.tstranslates web search (providers, thewebsearchconfig choice, keys, the tool's text result and its first-use consent form). These files are the only place that knows 2.x wire shapes. Rendering and stores read the domain model; fix a missing field there, never with a shim.packages/web/server/lib/opencode/proxy.jsforwards/api/*as-is (2.x serves under/apiitself) and folds OpenChamber-owned session state into the records it serves.env-runtime.jslaunchesopencode serve.- Plugins OpenChamber generates for OpenCode:
plugin-spec.jsandagent-tool/runtime.js, declared through the watched<dataDir>/opencode.managed.json(OPENCODE_CONFIG), so a settings change applies without a restart. Only the binary, port and external toggle restart.
Every directory-scoped read starts a location
On 2.x a read through the location middleware builds that directory's location, and the build starts every configured local MCP server for it. The location then lives until an hour without session events. So each read names a directory, and only one the user is working in:
- Which routes: agent, plugin, model, provider, integration, mcp, project,
form, permission request list, fs, command, skill, rpc, pty, shell,
reference, vcs, websearch, config, location (
protocol/src/api.tslists the groups withlocationMiddleware). Session routes resolve the session's own location;GET /api/session,/api/session/activeand/api/credentialare global and start nothing. - How the directory travels: the
x-opencode-directoryheader, percent-encoded, or alocation[directory]query. A?directory=query is ignored. - A read without one answers for OpenCode's own working directory, the
user's home for a managed OpenCode, and starts a fleet there. The UI reads
through
opencodeClientwith the current directory; server code with no directory of its own uses the lifecycle'sgetDefaultOpenCodeDirectory(), the last-used directory it warmed at startup. - Fan-out is the failure: a loop over every project, worktree or store directory starts one fleet each. A refresh after a catalog event re-reads only the directories the events named; they are already running.
A report of processes multiplying, memory climbing with MCP servers enabled, or MCP servers starting in projects nobody opened: reproduce it with references/mcp-spawn-probe.md before reading code.
Workarounds for what 2.x cannot do
Each exists because 2.x has no route for it. When a tag adds the route, the workaround goes and the record comes from OpenCode.
- Archive: 2.x has no archive route.
openchamber-sessions/archive-store.jskeeps it per data dir and the proxy folds it into session reads. Session metadata is not a workaround since 2.0.15: it lives on the OpenCode record, written by merge-then-PATCH insession-metadata-store.js, which also migrates the oldsessions-metadata.json. Provider credentials are not one either since 2.0.20:opencode/auth.jsreadsGET /api/credential. - 1.x sessions created after the one-shot migration:
v1-migration-topup.jsrewinds the migration cursor before a managed start, only when no revisited session has 2.x activity. - Error bodies: the generated client drops the body of an HTTP status a
route does not declare, so session update/delete/archive report the status
without OpenCode's message or log
ref.
Open asks upstream (OpenCode Slack): declaring 500 bodies on session
mutations; provider.list and agent.list waiting for plugin activation the
way model.list does since 2.0.27, which would retire the cold-catalog
recovery in useConfigStore. Dropped: an import route for missing 1.x
sessions (the top-up workaround is enough). Check the newest tag before re-asking.
Behaviour to expect
Verified against live 2.x servers; re-check on a newer tag before relying on a gap.
- A cold location's catalog is not authoritative. The first provider/model
read for a directory not started yet answers an empty list, then a partial
one without plugin providers, and the full list about two seconds later,
announced by
provider.updated/model.updatedwith thatlocation.directory. Recovery rides on those events (markConfigCatalogStale). Since 2.0.27model.listandmodel.defaultwait up to 5 seconds for the location's plugins;provider.listandagent.liststill answer early, so the recovery stays. - Plugin providers exist only in the running OpenCode. Nothing about them
reaches
opencode.jsonorauth.json;/api/provideris the only view, and it stripsoptions.fetch, so nothing tells a directly callable provider from one that only works through OpenCode. Without a zen login OpenCode setsoptions.apiKey = "public"on zen and trims it to free models: those run on OpenCode's infrastructure and are called only through OpenCode. - A session whose directory was deleted still reads, but location-scoped
requests answer 404
LocationNotFoundError.STATUS_BY_TAGdoes not map it to 404 on purpose:fetchPermissionreads 404 as "settled", which would let auto-accept fail open.POST /api/session/:id/moveworks on such a session. - A background shell or a subagent has no clean cancel.
shell.removekills the process but hands the agent aShell.NotFoundError; interrupting a subagent's child session (no job-cancel route) reports "Subagent cancelled". Agents relaunch either, sostopBackgroundShellandstopSubagentpost a cancellation note to the agent first. opencode run --agent Xuses the default model, not the agent's: pass-m provider/model#variantin batch runs.- A scratch
opencode servestarted from the app's shell answers 401: the shell inherits the desktop'sOPENCODE_PASSWORD, which wins overOPENCODE_SERVER_PASSWORD. Start it withenv -u OPENCODE_PASSWORD(Basic auth useropencode).
Sources of truth
- Reference checkout
~/projects/opencode, branchorigin/v2and itsv2.x.ytags (git fetch origin --tagsthere; never edit it). Maintainer machine only: where the path is absent — CI, a fresh sandbox — report the reference checkout as unavailable and answer what you can from the pins below. Server behaviour:packages/core/src, HTTP surface:packages/server/src/handlers/*, wire types:packages/schema/src,packages/protocol/src/groups. - Minimum supported version:
MINIMUM_OPENCODE_VERSIONinpackages/web/server/lib/opencode/compatibility.js; raise it when OpenChamber starts depending on a route a newer tag added. - Pinned version:
opencodeCli.versioninpackages/electron/package.json(the bundled binary) and@opencode/client/@opencode/schemain the root, ui, web and vscode manifests, plus@opencode/cli@in the Dockerfile. They move together.
"What's new in OpenCode 2.0.x?"
Answer from the diff. Done when every API-facing change between the pinned tag and the newest tag is classified.
- In the reference checkout:
git fetch origin --tags, pinned =opencodeCli.version, newest =git tag -l 'v2.*' | sort -V | tail -1, thengit diff --stat vPINNED..vNEWEST -- packages/schema/src packages/protocol/src packages/server/src packages/client packages/plugin/src. Ignorepackages/tui,packages/app,packages/web. - Classify each change to a route, event, schema or plugin hook: breaks us (name the consuming OpenChamber file), fixes a workaround (name the one above that can go and what the user gains), closes an open ask, or neutral.
- Report in that order with the maintainer's decisions explicit: remove, adopt, still ask.
Bumping the pinned OpenCode
Move every pin to the same tag and check out that tag in the reference
checkout (git checkout vX.Y.Z in ~/projects/opencode), bun install, then tsc in packages/ui,
packages/web, packages/vscode; the isolated ui suites; web vitest; vscode
tests. A new message type or event needs a case in model.ts and
events.ts before it renders. Verify @opencode/cli@<tag> exists on npm:
the desktop packaging and the Docker image install it.
Version History
-
bf977d2
Current 2026-10-19 13:04
记录 model 路由等待插件激活的行为变化,以及 OpenCode 2.0.27 版本更新说明。
- 1f0004f 2026-09-28 05:11


