This branch (main in neumark/opencode) is the integration branch for OpenCode 2. It tracks upstream (anomalyco/opencode) dev — the live v2 line, where releases are cut as orphan release: commits pinned by tags, with the matching release: vX.Y.Z (#PR) commit on the branch carrying the same tree (the sync release versions shape was replaced by release PRs around 2.2.0). The branch is based at the release: v2.2.5 (#60744) commit (4878a0e30f, tree-identical to tag v2.2.5; rebased up from v2.1.2 on Nov 2 2026 with feature 1 dropped — see below) and rebases onto release commits only, never moving dev tips, to keep rebases bounded. The upstream 2.0 branch is a stale April-2026 exploration branch — not the port target.
Branch history: the port started as the v2 branch (first rebase v2.0.27, then v2.1.2 on Oct 21 2026); releases v2.0.27-neumark.3 through v2.1.2-neumark.2 were tagged off it while main still mirrored the v1 line. On Nov 2 2026 the owner moved main onto the v2 line (the deployment had transitioned; the v1 line is retired) — main and v2 now point at the same history. The v1 fork's feature specs, release lineage, and the incidents that bought each feature live in fc-opencode's INCIDENT_HISTORY.md; the pre-transition main history stays pinned by the v1.*-neumark.* release tags, which are never moved.
Current state: rebased onto v2.2.5, feature 1 removed — features 2, 4, 5a, and 7 are in (plus the v2-only 8–11); 1 was removed (superseded by upstream #59131); 3 and 6 stay dropped by design. Also carried: a tmp-root fallback (packages/util/src/global.ts, v2.0.27-neumark.2) — the default $TMPDIR/opencode root crashed startup with EEXIST whenever a file named opencode sat in the shared tmp dir (observed live deploying the first v2 build); it now falls back to a private mkdtemp directory.
Upstream dev is the v2 rewrite: packages/opencode is deleted, split into cli/server/core/schema/protocol/…; every file the v1 fork patches is gone or rewritten. This is a reimplementation project, not a rebase (already noted in main's FORK.md). What v2 buys this deployment:
- The fork's most fragile dependency — the undocumented
experimental_workspaceplugin API — is replaced by a supported worktree-strategy plugin API (ctx.worktree.transformin@opencode/plugin; upstream ships test fixtures for plugin-provided strategies:packages/server/test/fixture/worktree-plugin/). /sync/historyand its full-table-scan read spiral (fc-opencode incident 14, upstream issue #52270) is architecturally gone: v2 syncs clients over an SSE event feed (event.subscribeinpackages/server/src/handlers/event.ts) with no polling catch-up.- The web app natively attributes worktree sessions to their projects (workspace inventory,
managedWorkspaceDirectories, per-workspace session grouping) — the v1 fork's feature 3 exists upstream, built properly. - v1 is in guided-sunset maintenance (v1.19.0 is chores plus the V2 update dialog and
opencode upgrade --major); v2 is where fixes land. - Official linux-arm64 builds exist — the fork's x64-only releases were an operator concession, and arm64 could revive Pi-5 slots.
What it costs: v2 currently has no LSP integration (v1 fed language-server diagnostics to the agent; v2.0.27 retains only the config schema, normalizeLsp, and a settings display panel — there is no launch machinery anywhere in packages/), the port below is real work, v2 moves fast (~daily releases; the worktree-strategy and plugin APIs are fresh and may drift), and the daemon's IO/memory profile under this deployment's 24/7 agent-loop load is unmeasured (Phase A exists to measure it).
Ported at v2.0.27 (packages/cli/src/services/web-ui.ts: <title> replacement with HTML-escaping and a function replacement so $ sequences stay literal, CSP hash over the rewritten HTML; env through packages/cli/src/env.ts) and carried through v2.1.2. Removed on the v2.2.5 rebase: upstream #59131 (in v2.2.0) shows the open session's title in the browser tab via @solidjs/meta (<session title> · OpenCode, falling back to OpenCode), which covers what the override existed for — telling concurrently open tabs apart. The env var is now ignored; fc-opencode's serve unit can drop OPENCODE_WEB_UI_TITLE=%H (it is inert, not an error).
v2 model: sessions live at Location.Ref { directory, workspaceID? }; session.create accepts location and parentID (children keep the parent's location natively — subagent sharing parity for free). Worktrees are first-class: WorktreeStrategies (packages/core/src/worktree/strategies.ts) holds per-project strategies; editor.add(strategy) registers one and selects it as the default; the new-session picker (main/create/existing) is client-side, and the workspaces.defaultDestination setting is app-local — headless/SDK creates bypass both. Port, two halves:
- The guest plugin registers an
overlayfsworktree strategy (below). - Server-side default binding, same contract as v1 (
60d0229), landed at thesession.createhandler (packages/server/src/handlers/session.ts) with strategy selection threaded throughWorktree.create(strategyinput, no protocol change): envOPENCODE_NEW_SESSION_WORKSPACE=<strategyID>, top-level creates get a fresh strategy worktree and a rewrittenlocation.directory; unregistered strategy degrades to pass-through (never errors);parentIDcreates untouched.OPENCODE_EXPERIMENTAL_WORKSPACESis dropped — worktrees are not experimental in v2. Integration tests:packages/server/test/session-create-workspace-default.test.ts.
v2's location/project model natively lists, labels, groups, and opens worktree sessions under their project; worktree directories are tracked with their strategy (WorktreeTable), and the app exposes workspace inventory without project-card hacks. All three v1 gaps (exact-directory filter, unresolvable projects, per-directory store adoption) were v1-app-specific.
v1: 1059467 in packages/opencode/src/tool/shell.ts. v2: the spawn in Shell.create (packages/core/src/shell.ts) wraps with nice -n 19 ionice -c 2 -n 7 on linux, keeping the pid-preserving exec property the fence annotation (5a) relies on. The shell.create.before plugin hook can also mutate the invocation, but a wrapped command string would show in Info.command; the spawn is patched as in v1.
- 5a — OOM-killed command annotation (port, ported). v2's
finish()inpackages/core/src/shell.tsalready captures the kill signal (CrossSpawnSpawner.KilledBySignal) on the exit path;util/cgroup.ts(0c929ca) ported topackages/core/src/util/cgroup.tsminusfenceLsp(see 5b) — the guest mechanics (FC_AGENT_CGleaf resolution,fc-cmd-<pid>-*scan,oom_killinmemory.events) are opencode-independent — and the annotation is appended to theShell.resultcapture (signal deaths without fence evidence are annotated too; exit 137 with evidence gets the fence annotation). - 5b — fenced LSP leaves (no target). v2 has no LSP launch machinery; nothing to fence. Dropped together with the LSP regression noted above. If upstream reintroduces LSP, fence it at the spawn site the same way.
No /sync/history exists in v2; the SSE feed plus per-aggregate indexed reads replaces the polling protocol, eliminating the defect class rather than fixing it. Nothing to port; watch incidents, not code.
v1: 45dfb2b + 318f171 (hardened). util/fence-breaker.ts ported nearly verbatim to packages/core/src/util/fence-breaker.ts (kill/refusal message builders added beside the state machine); the gate runs at the top of Shell.create before the plugin hooks and the permission ask (a refused command never prompts), tripped by 5a's fence-kill detection in Shell.result; the shell tool pre-checks the pure refusing() read to return the refusal as a normal tool result before create's gate claims the half-open probe. OPENCODE_FENCE_BREAKER knob semantics unchanged. test/util/fence-breaker.test.ts ported alongside. Known shared limit (reproven by the Oct 13 vm0 storm): the breaker counts fence kills — a page-cache re-fault storm whose trees sit under their memory caps never OOMs and never trips it; the io fences/governor remain the aggregate defense there.
v1 served on the trusted tailnet with no auth; stock v2 always enforces a password (random when unset — rotating per boot, pairing screen per browser). The server layer already supports an open mode (ServerAuth.required is false for an empty password) but nothing could reach it: the CLI always generated one, and the pre-API dispatch layer enforced credentials independently of required(). OPENCODE_SERVER_UNSECURED=1 (cli server-process.ts, read directly like the fork's other knobs — Effect Config treats an empty env value as unset, so the empty-OPENCODE_SERVER_PASSWORD spelling can't work) serves with an empty password; ServerProcess.start's guard and dispatch now let the empty password through, and the middleware no-ops. Guests set it in the serve unit; fc-sessions/fc-transcript-archive detect the open mode (and verify journal passwords before trusting them — stale lines linger across mode switches).
v2's 20260805200742_import_legacy_credentials migration imports a v1 ~/.local/share/opencode/auth.json, but only on the upgrade path: a FRESH database takes DatabaseMigration.apply's bootstrap branch, which creates the full schema and records every migration id WITHOUT running any up() — so a fresh install over a pre-staged auth.json (exactly the fc-opencode guest model: secrets disk stages auth.json into every new VM) silently loses all provider credentials. The fork runs importLegacyCredentials inside the bootstrap transaction (idempotent — per-integration existence checks — and tolerant of a missing file), so a seeded auth.json lands in credential on first boot. The stop-side round trip (guest DB credentials exported back to the slot's auth.json at VM stop) lives in fc-opencode.
opencode serve sends READY=1 once listening and WATCHDOG=1 every WatchdogSec/2 (from systemd's WATCHDOG_USEC), so a unit declared Type=notify with WatchdogSec= is restarted by systemd itself when the event loop stops servicing (fc-opencode incident 21: daemon green-but-dead — unit active, HTTP unresponsive, PSI under every kill line, nothing to restart it). bun's node:dgram has no unix-datagram support, so pings shell out to the systemd-notify binary; failed pings are swallowed (telemetry must never take the server down), and the whole path is inert without NOTIFY_SOCKET (foreground/dev). Complements the guest's external HTTP watchdog: this one is in-process precision, that one is cause-agnostic and carries the forensics snapshot.
The fleet's tooling consumes opencode's CLI surface and export JSON across repo boundaries — docs/scripts/session-usage.mjs builds the token-usage ledger from opencode session export <id> / opencode session list --format json. The v1→v2 port silently moved the export command (top-level export → session export) and restructured the payload (info.role→type, info.tokens→tokens, parts→content), taking the ledger offline with only "no API calls in the window" as a symptom (fc-opencode incident 24). packages/core/test/session-export-contract.test.ts pins the export payload fields the parser reads (per-message type/tokens/model{id,providerID}/time/content, session-level info.tokens aggregate); the CLI surface itself is verified in the fleet. Rule: when these tests fail on a rebase, the upstream restructure MUST be mirrored into docs/scripts/lib/sessionUsage.mjs in the same change — the test failure is the tooling break arriving early.
v1: ~/.config/opencode/plugins/overlay-workspace.js against experimental_workspace. v2 rewrite against the promise plugin API (@opencode/plugin, Plugin.define):
ctx.worktree.transform((editor) => editor.add({ id: "overlayfs", create, remove, list }))—createstartsfc-overlay@<slug>and returns{ directory: "/home/dev/workspaces/<slug>" };removestops it (unmount + delete upper);listreturns mounted workspaces as worktree entries.branchis accepted and ignored (workspaces branch from the repos-base snapshot by construction — same semantics as v1).- Auto-reclaim:
ctx.event.subscribeon session archived/deleted — when no other non-archived session shares the workspace, remove the worktree; archive first pushes the transcript (fc-transcript-archive), as in v1. Fail safe: if the session list can't be read, nothing is destroyed. - The fc-opencode guest units (
[email protected], sudoers,fc-overlay-add/remove/diff) are unchanged — the plugin stays a thin adapter over systemd.
opencode-serve.service:OPENCODE_NEW_SESSION_WORKSPACE=overlayfsactive;OPENCODE_EXPERIMENTAL_WORKSPACESretained while v1 guests share the image (ignored by v2).OPENCODE_WEB_UI_TITLE=%His no longer consumed (feature 1 removed; superseded by upstream #59131's session titles) — harmless if still set, to be dropped from the unit when convenient.WorkingDirectory=/home/dev/repos— the trunk git root (fc-repos-setup inits it) that gives the binding its worktree source: v2 project resolution registers sources only for vcs-backed projects, and a plain-directory project failsWorktree.createwithSourceDirectoryNotFoundError(every new-tab session 500s — found live).- Yolo-permission global config (
TPL_OPENCODE_GLOBAL_CONFIG): verified natively migrated — v2's normalizer translates the v1permissionblock into native rulesets (live check via/api/config); no rewrite needed.opencode.jsoncis read as-is. - The overlayfs plugin ships as
~/.config/opencode/plugins/overlayfs.js(v2) alongside the v1overlay-workspace.jsfor the transition; reclaim is delete-only in v2 (no archive API upstream yet — the app's archive button is stubbed). fc-transcript-archive: continuous capture until v2 grows an archive API — the plugin exports after every run reaches a terminal state and an hourly timer sweeps--all(same design as the deployment's claude-code hook indocs/.claude/hooks/archive-transcript.sh); deletion costs at most the in-flight run. Replaced by an archive-API hook when upstream ships one.fc-sessions/fc-transcript-archive: dual-version (v1 unauthenticated/session, v2/api/sessionunder basic auth with the password pulled from the guest's serve journal); v2 links are/server/<base64url(origin)>/session/<id>.- Release resolver: unchanged — verified against
v2.0.27-neumark.3(asset nameopencode-linux-x64.tar.gz,find-based install, serve smoke test all match). - Secrets channel: v2 imports legacy
~/.local/share/opencode/auth.jsoncredentials — on the upgrade path at migration, and (fork feature 9) on fresh-database bootstrap. Keep shippingauth.jsonthroughsecrets/vm$SLOT; fc-opencode's stop path exports guest DB credentials back into it.
- Phase A — stock v2 in one slot, no fork features. Build upstream v2.0.x, run it in one VM behind the existing tailnet serve; guest plumbing only (serve unit env, yolo-config translation, the overlayfs strategy plugin with auto-reclaim and transcript archiving). Validate: long-loop agent sessions at incident-history workloads; overlay semantics (per-tab isolation, subagent sharing via
parentID); daemon IO/memory profile (fc-disk,/proc/<pid>/io, per-cgroupio.stat— the incident-14 amplification class); serve stability across days. (Status: slot 3 runsv2.0.27-neumark.3behindtailscale serve :4104with the overlayfs plugin live — binding/distinctness/parent-sharing/delete-reclaim validated end-to-end; yolo config natively migrated (verified via/api/config); oomd backstops hot-patched. Transcript archiving runs as continuous capture (per-run export + hourly sweep, fc-opencode1feb472). Soak in progress; promote when satisfied.) - Phase B — fork features. (Done —
v2.0.27-neumark.3: 1, 4, 5a+7, then 2. Tests per v2's per-packagebun testlayout;fence-breaker.test.tsandcgroup.test.tsported; feature 2 covered bysession-create-workspace-default.test.ts.) - Promote. (Done — releases
v2.0.27-neumark.3→v2.1.2-neumark.2were tagged off thev2port branch with fc-opencode's resolver pointed at them; on Nov 2 2026, with the deployment transitioned to v2,mainwas moved onto this line and the v1 mirror retired.)
# bun version is pinned by the root package.json packageManager field ([email protected] on v2.2.5) bun install cd packages/cli OPENCODE_VERSION=v<x.y.z>-neumark.N bun script/build.ts --single # → dist/cli-linux-x64/{bin/opencode, package.json}; the embedded web app is built and # compiled in (asset map + CSP), so UI changes always need a full binary rebuild. # On a constrained build host, install the two native packages for the current # platform first (bun install @opentui/core@<v> @opencode/pty@<v>, then revert the # package.json/bun.lock pin) and pass --skip-install: the bare command fetches # every platform's binaries (~3GB) even for a single-target build. cd dist/cli-linux-x64/bin && tar -czf /tmp/opencode-linux-x64.tar.gz opencode gh release create v<x.y.z>-neumark.N /tmp/opencode-linux-x64.tar.gz \ --repo neumark/opencode --target main
- Always build with
OPENCODE_VERSIONset (leadingvincluded, e.g.v2.2.5-neumark.1): without it the channel resolves from the branch name, and channel-suffixed database naming (packages/cli/src/database-path.ts) makes the binary open a fresh database. With it, the channel islatestand the standard database is used. - Releases are tagged off
mainand published manually (no CI: upstreampublish.ymlis gated ongithub.repository == 'anomalyco/opencode'); x64 asset only (opencode-linux-x64.tar.gz, binary at archive root — fc-opencode installs via find). - Keep upstream current by rebasing
mainonto the tracked upstream ref: on the v2 line that is therelease: vX.Y.Z (#PR)commit on upstreamdevwhose tree matches the release tag (thesync release versionsshape ended around 2.2.0; locate it withgit log upstream/dev --grep='release: v'). Push with--force-with-lease; release tags pin released binaries and are never moved by rebases.
- LSP regression: no agent-facing diagnostics in v2 as of v2.0.27 — a real capability loss for code-heavy loops. Track upstream; nothing this fork can port onto.
- API drift: worktree strategies and the plugin API are fresh v2 surface; expect adjustments on rebase — the price of leaving a frozen line.
- Load profile unproven: the Effect-based core, drizzle storage, and SSE feed have never run this deployment's 24/7 loops and giant transcripts; Phase A measures before Phase B commits.
- Release cadence: v2 ships ~daily; base and rebase only on
sync release versionscommits.