[Bug]: The plugin cannot be installed to opencode v2
Expected Behavior
The plugin is installed to opencode v2 successfully.
Actual Behavior
I add the plugin to opencode.json and it told me the installation failed. Check the log below.
Environment
- OS: Windows 11
- OpenCode Version: 2.0.14
- Plugin Version: latest
OpenCode Configuration
opencode.json (sanitized)
{
"$schema": "https://opencode.ai/config.json",
"mcp": {...},
"plugins": ["superpowers@git+https://github.com/obra/superpowers.git", "opencode-pty/v2"]
}
Debug Logs
Click to expand debug logs
timestamp=2026-09-23T05:13:27.176Z level=WARN run=14923000 message="failed to load plugin" target=opencode-pty/v2 ref=err_294b60db cause="Cause([Fail(NpmInstallFailedError (cause: Error: An unknown git error occurred))])" http.span=454666 role=server
If you use opencode plugin add opencode-pty/v2, it will tell you:
PS> opencode plugin add opencode-pty/v2
NpmInstallFailedError:
at catch (B:/~BUN/root/chunk-ns0jvcsz.js:3:9737)
at ~effect/Utils/internal (B:/~BUN/root/chunk-jqd4mbxb.js:8:1540)
at s (B:/~BUN/root/chunk-jqd4mbxb.js:24:5696)
at processTicksAndRejections (native:7:39)
at Npm.reify (B:/~BUN/root/chunk-ns0jvcsz.js:3:9776)
at Npm.add (B:/~BUN/root/chunk-cpfxj355.js:2:1252)
at Npm.add (definition) (B:/~BUN/root/chunk-ns0jvcsz.js:3:11602)
at cli.plugin.add (B:/~BUN/root/chunk-252qxkab.js:49:15194)
at cli.plugin.add (definition) (B:/~BUN/root/chunk-cpfxj355.js:2:1064) {
[cause]: Error: An unknown git error occurred
at Bn (B:/~BUN/root/chunk-9833mmcn.js:8:9366)
at <anonymous> (B:/~BUN/root/chunk-9833mmcn.js:8:10929)
at processTicksAndRejections (native:7:39)
}
Also hitting this on opencode 2.0.14 (macOS, arm64, [email protected] from npm) — with some detail on what's actually failing, because there are two separate gaps, and fixing the subpath install alone won't be enough:
1. The subpath ref is treated as an install spec. "opencode-pty/v2" never resolves to the ./v2 export — the loader attempts to npm-install a package literally named opencode-pty/v2:
message="failed to load plugin" target=opencode-pty/v2 cause="Cause([Fail(NpmInstallFailedError ...)])"
(same as the report above, reproduced on macOS)
2. The bare ref loads the V1 entrypoint. plugins: ["opencode-pty"] resolves exports["."] → dist/index.js, which is still the V1 shape, so it's rejected by the v2 plugin schema:
PluginModule.LoadError: Plugin must export a default definition with an id and an effect or setup function.
(cause: SchemaError(Missing key at ["default"]["effect"] / ["default"]["setup"]))
So even if the loader learned to resolve subpath refs, the bare-name path still fails — the . entrypoint doesn't carry the V2 definition, and main hasn't changed the packaging yet (the post-0.4.0 9be51267e only improves the V2 internals).
What appears to fix it is packaging, not loader-side. opencode-mem hit the same problem and solved it upstream (tickernelz/opencode-mem#311) by making the default entrypoint itself dual-mode — the dist/plugin.js default export spreads the V2 { id, setup } plugin and keeps the legacy hooks alongside:
export default {
...OpenCodeMemPluginV2, // { id, setup(ctx) }
id,
server: OpenCodeMemPlugin, // legacy V1 hooks
} satisfies PluginModule & V2Plugin;
With that, plugins: ["opencode-mem"] loads cleanly on 2.0.14 — no subpath needed (verified live end-to-end). For opencode-pty, the equivalent would be re-exporting dist/src/v2/index.js's Plugin through the . entrypoint's default export while keeping the V1 hooks for ./server and older hosts.
Workaround until then — a discovery-dir shim that re-exports the named Plugin from the installed copy (loads and runs on 2.0.14):
// ~/.config/opencode/plugins/opencode-pty-local/index.js
// point this at your installed opencode-pty dist
export { Plugin as default } from "<cache-path>/node_modules/opencode-pty/dist/src/v2/index.js";
Workaround tested, based on @jss79 comment
Slash commands do not work. AI knowns nothing of pty tools.
What i tried:
-
on windows powershell and linux:
cd ~/.config/opencode/ mkdir plugins cd plugins echo 'export { Plugin as default } from "./module/node_modules/opencode-pty/dist/src/v2/index.js";' > index.js npm install --prefix ./module opencode-pty@latestno need to edit .config/opencode/opencode.jsonc ...
open opencode, and type /plugins ->
opencode-pty localshould appear -
i tried importing from
~/.cache/opencode/npm/opencode-pty@latest/1791285270457/opencode-pty/dist/src/v2/index.js" which did work the same as before (opencode plugin add opencode-ptythen removedplugins` from config because of the autooading)
What did work for me: (crude wrapper)
Additional features of this wrapper:
- extra config file for any kind of settings
- config includes webfont family,size,lineheight
- fixed notifyOnExit to work wiht this v2 wrapper
- added resize notification to underlying tty (checking width and height will be correctly reported by its actual size in browser)
- changing config requires opencode "/restart" ... and a lot more.
Plugin is saved to this gist: https://gist.github.com/BananaAcid/e0374ff83a2d774d4cf8d76d54ea10da
to install using this workaround:
From cli:
opencode plugin add gist:e0374ff83a2d774d4cf8d76d54ea10da
Confirmed still broken on opencode 2.0.27 (macOS, arm64, [email protected] from npm). Adding some source-level detail on why this fails, plus what the README needs to change — both the config field and the spec parsing are wrong for V2 right now.
1. The README's V2 example uses the V1 field name
The README's "OpenCode V2" section says:
{
"$schema": "https://opencode.ai/config.json",
"plugin": [
{ "package": "opencode-pty/v2", "options": { } }
]
}
plugin is the V1 field name; V2 reads plugins (see the V2 plugins doc). On 2.0.27 the object entry under plugin is silently skipped before the installer is even reached:
level=WARN message="configuration normalization diagnostic" source=~/.config/opencode/opencode.json path=$.plugin.0 kind=invalid action="skipped malformed recognized value" role=server
2. Why opencode-pty/v2 fails with a git error
With the field fixed to plugins (string or object form — parse() in packages/core/src/config/plugin/source.ts maps the object form to the same target string, so both hit the same installer), the target goes to the npm installer, which parses specs with npm-package-arg (parse() in packages/util/src/npm.ts). npa classifies opencode-pty/v2 as a GitHub shorthand (owner/repo), so it attempts a git clone of github.com/opencode-pty/v2:
level=WARN message="failed to load plugin" target=opencode-pty/v2 cause="Cause([Fail(NpmInstallFailedError (cause: Error: An unknown git error occurred))])" role=server
level=WARN message="failed to check plugin update" target=opencode-pty/v2 cause="Cause([Fail(NpmInstallFailedError (cause: Error: Package is not installed: opencode-pty/v2))])" role=server
That's where the "unknown git error" comes from even though no git URL was ever configured.
3. Even a successful install wouldn't reach ./v2
Host.resolve() (packages/plugin/src/host.ts) only probes server / tui / rpc subpaths for an installed package:
return { server: entry(["server", ""]), tui: entry(["tui"]), rpc: entry(["rpc"]) }
So the ./v2 export is unreachable via the config-driven install path today; entrypoint resolution would need subpath awareness too — matching what @jss79 described from the outside ("fixing the subpath install alone won't be enough").
Workaround verified on 2.0.27
Install the package next to the global config and re-export the V2 plugin through a discovered plugin file. This goes through the package's exports map, so it survives version bumps (no hardcoded dist/ paths):
cd ~/.config/opencode
npm install opencode-pty@latest
~/.config/opencode/plugins/opencode-pty.ts:
export { Plugin as default } from "opencode-pty/v2"
opencode auto-discovers ~/.config/opencode/plugins/*.ts, and the bare specifier resolves against ~/.config/opencode/node_modules. Result: GET /api/plugin reports opencode-pty [local] active, and the pty_* tools load. To update later: cd ~/.config/opencode && npm update opencode-pty.