OpenCode v2 installation, commands, enforcement mechanics, and
troubleshooting. The shared configuration,
command contracts, enforcement contract, and
gate troubleshooting apply here and to DSH.
Install through the README. Requires OpenCode
v2.x (live-verified on v2.0.26 and v2.2.0). V1 agent frontmatter and
the V1 plugin API are deprecated upstream and unsupported.
Point the plugin entry at the package or repository root, not directly at
dist/: one root entry resolves both the server adapter and the bundled TUI
companion through package.json exports. For a checkout, see
Local development.
The server adapter registers the agent-facing dev_framework_* tools described
in the shared command reference.
Follow the shared lifecycle checklist for project template updates and post-upgrade verification.
To check and update a registry installation:
opencode plugin check opencode-dev-framework
opencode plugin update opencode-dev-frameworkRestart the opencode serve backend afterward; restarting only the terminal or
TUI can leave the old adapter loaded. For a source checkout, update and rebuild
the checkout, then follow Stale version after switching sources
if a registry build was previously installed.
To remove a plugin installed through the OpenCode plugin manager:
opencode plugin remove opencode-dev-frameworkIf you declared the plugin manually in opencode.json, remove its plugins
entry instead. Restart the serve backend. Project configuration and scaffolding
are preserved; see Remove the plugin before
deleting any project files.
How the plugin enforces on OpenCode v2 (idle hook landed via
anomalyco/opencode#59437).
Profiles and the host-independent semantics are in the shared
enforcement contract.
| Mechanism | Primary layer | Backstop / fallback | Strength |
|---|---|---|---|
| Pre-flight gate | tool.execute.before deny |
— | Hard block on every build: the edit never lands. |
| Protected paths + dangerous commands | tool.execute.before deny/throw (load-bearing: the pipeline runs before-hooks first) |
permission.evaluate native layer (deny) as defense-in-depth — it only ever sees calls the primary already passed; matters if core ever reorders the pipeline |
Hard block via the primary deny; the native layer is belt-and-braces, never a weakening (it only denies or abstains). |
| Per-edit lint | tool.execute.after track + lint |
filesystem.changed event |
Report-only: the edit already landed, so failures log loudly but never throw. |
| Completion gate | session.hook("experimental.idle") (+ idle alias) → session.synthetic (same execution) |
event.subscribe idle net for the boundaries the hook skips (deduped; synthetic-first, prompt fallback) |
Async, bounded by gate.max_blocks. /df-status shows Continuation (idle): active once the hook has completed an evaluation, else the event-subscribe fallback. execute.before stays the only true hard wall. |
| Session duty roster | context hook injection at session start |
— | Legibility only, never blocks: a checklist of the duties above (steps, scope, review, block budget) so the agent sees the whole contract upfront. off produces no roster. |
flowchart TD
U["user prompt\nplain or /df-goal plan"] --> A["agent implements"]
A --> B{"tool.execute.before"}
B -- "deny: protected /\ndangerous / pre-flight" --> X["blocked before landing"]
B -- allow --> C["edit lands"]
C --> D["per-edit lint\n+ change tracker"]
D --> V["agent runs\ndev_framework_verify"]
V --> R{"verdict"}
R -- PASS --> OK["gate green"]
R -- FAIL --> A
D --> S{"session idle"}
S --> GT["completion gate\nsame full contract"]
GT -- PASS --> DONE["done"]
GT -- "FAIL, within max_blocks" --> SYN["synthetic continuation"]
SYN --> A
GT -- "FAIL, past max_blocks" --> SD["stand down:\nhonest unmet report"]
GT -- "FAIL, identical x3\nwith no new edits" --> SD
G["/df-goal plan\n(optional wrapper)"] -. "delegates once,\nappends contract" .-> N["native /goal\nowns objective + review"]
N -. "wraps the loop:\ndrives turns" .-> A
OK -. "in a goal: PASS reported\nas evidence into /goal" .-> N
npmjs.com does not render mermaid. The README embeds the rendered
docs/assets/flow.svg (absolute raw URL, so npm shows it too) plus the same
flow as a plain-text diagram for text-mode readers. Regenerate the SVG from
the mermaid block above after any change:
npx @mermaid-js/mermaid-cli -i <(sed -n '/^```mermaid$/,/^```$/p' docs/user/opencode.md | sed '1d;$d') -o docs/assets/flow.svgUpdate mermaid, SVG, and README text together.
The command behavior is shared; this section covers only OpenCode registration and rendering. See the shared command reference.
Five slash commands are TUI commands registered by the bundled ./tui
companion module. They open instantly and never feed text back to the LLM:
/df-status— profile, guardrails, completion gate, and configured commands in a modal dialog./df-runtime— plugin version, live hook/gate runtime state, dispatch history, and template drift in a modal dialog./df-help— available dev-framework commands in a modal dialog./df-profile— profile picker; an argument such as/df-profile standardswitches directly with a toast instead of opening the picker./df-verify— manual gate result in a pass/fail modal dialog.
/df-init, /df-update, /df-ignore, and /df-goal are server-side commands.
The first two use the server command API and return work to the session rather
than displaying a modal:
/df-initscaffolds and trial-runs the project setup, then hands the wizard brief to the agent. On an already-configured project it reports status instead of touching anything. A clean non-interactivedf initrerun stays silent server-side./df-updatedetects template drift and hands differing or missing files to the agent throughsession.prompt; it never writes the templates itself. It stays silent when everything matches because the server command API has no result channel and a no-op agent turn would be waste. Startup also mentions drift once./df-ignoremanages the session or stored ignore hotlist through the server command and its corresponding agent tool./df-goaldelegates exactly once to native/goal, which owns objective state, review, pause/resume/clear, and continuations. The objective plus addendum must fit native/goal's 4,000-character limit; overflow is rejected with exact lengths, never truncated. See Verified goals.
- The completion gate steers; it does not veto. At the would-go-idle
boundary the plugin admits a synthetic continuation in the same execution
on failure inside
gate.max_blocks; the event net covers the boundaries the hook skips. The user can always close the session — treat the gate as the strongest available enforcement, not an unbreakable lock. A pre-terminal vote hook is proposed upstream (anomalyco/opencode#60461, implemented by PRanomalyco/opencode#54487, both open). The pre-flight gate, by contrast, is a genuine hard block on every build: it denies edit tools before the edit lands. As a backstop, the completion gate blocks finishing with changed files until the artifact exists. - Guardrails run inside OpenCode.
tool.execute.beforeruns after OpenCode's own permission system; it adds project rules on top, it does not replace OpenCode permissions. - Formatting is OpenCode core's job. The plugin's
commands.format/on_edit.formatare accepted but ignored, deliberately not duplicated, and the plugin never rewrites youropencode.json. Configure the host formatter instead.
The shared enforcement contract covers mid-session weakening, bounded budgets, zero-progress stand-down, and secret handling.
Real runs against disposable fixtures show the OpenCode loop end to end:
- First gated session — the full loop on a green tree: constitution, per-edit lint, verify, idle gate.
- Blocked gate, fix, pass — a red tree blocks the session; the agent proves the failure, fixes, and re-verifies.
- Plan under
/df-goal— a written plan run with the verification contract and a final tool-result PASS. - More runs — settlement gate, pre-flight backstop, plan review — live in the sessions index.
For gate scope, deleted files, scratch files, review artifacts, and logs, use the shared troubleshooting guide.
Each project must register the plugin exactly once. Plugin arrays merge
across config files (global ~/.config/opencode/cli.json "plugins" list,
global opencode.jsonc, project ./opencode.jsonc,
./.opencode/opencode.json[c]), so a second entry in another file — even one
pointing at a different path of the same repo such as dist/ — loads the same
plugin ID twice and the duplicate fails. A leftover tui.json entry for the
same path is the same bug: current OpenCode auto-resolves the ./tui
companion from the server entry (local paths included), so the old
local-dev workaround of listing the repo in both opencode.json[c] and
tui.json now double-loads the plugin ID and the duplicate fails. Keep the
single root entry in opencode.json[c] and remove the tui.json entry.
Check all locations, and verify with:
opencode api get "/api/plugin?location[directory]=/path/to/project"The server log only shows harmless loading plugin lines for both entries —
the API view is the one that tells the truth.
Point the entry at the repository root, not at dist/ directly: a bare
directory without package.json/exports resolves only the server part. One
root entry loads every part (server via dist/adapters/opencode/index.js, TUI
via tui.tsx, resolved through the exports map).
OpenCode caches downloaded plugins in
~/.cache/opencode/packages/opencode-dev-framework*/. If you previously loaded
a published version and then switch to a local source, clear that cache so
OpenCode does not reuse the old build:
rm -rf ~/.cache/opencode/packages/opencode-dev-framework*After every source change, rebuild — OpenCode loads the compiled dist/ output:
npm run buildPlugin code runs in the shared opencode serve backend, not in your terminal or
TUI process. Restarting the client alone reuses the old server, so a rebuilt
dist/ sits unread. After every plugin upgrade or rebuild, restart the serve
backend so new and continued sessions pick up the new code.
Requires OpenCode v2.x (@opencode/plugin ^2) — tested on v2.0.26 and
v2.2.0. On v1.18.18–1.18.31 use the v1 branch of this plugin (plugin
key). The ./tui companion is auto-discovered from the server entry on v2
(npm and local-path entries alike) — no separate tui.json needed.
Run a private server with the plugin trace on and read the log:
OPENCODE_DEV_FRAMEWORK_LOG_FILE=/tmp/odf.log opencode run --standalone --print-logsPlugin code runs in the opencode serve backend, not in your terminal process —
a variable exported only in the TUI shell never reaches it.