#1083·caveman

OpenCode 2: generated native plugin uses incompatible V1 API

Author: ranokayCreated Sep 17, 2026Updated Sep 17, 2026

What happened

The native plugin generated by caveman enable opencode fails to load in OpenCode 2.0.5. The installed generator still emits a V1 named export returning a Hooks object.

The matching OpenCode server log entry reports:

2026-09-17T09:01:23.371Z
role=server
ref=err_ac6c5897
message="failed to load plugin"
target=~/.config/opencode/plugins/caveman-native.js
cause="PluginModule.LoadError: Plugin must export a default definition with an id and an effect or setup function. (cause: SchemaError(Missing key at [\"default\"])))"

The installed @caveman-ai/cli/dist/index.js generator contains:

// Contract: @opencode-ai/plugin 1.17.8 Hooks (installed local type source).
export const CavemanNative = async () => ({
  // event, chat.message, experimental.chat.system.transform,
  // tool.execute.before, tool.execute.after, experimental.session.compacting, dispose
});

An isolated import of the generated file succeeds, but its only export is CavemanNative; typeof module.default is undefined. The failure occurs at plugin-definition validation, before native hooks or Caveman subprocesses run. Both Caveman executables exist, the CLI runs, and the separately configured Caveman MCP server connects successfully.

Expected

Generate a plugin compatible with the detected OpenCode major version, or report unsupported V2 explicitly instead of installing a plugin that cannot load.

V2 requires a default definition with a stable id and setup(ctx) or effect. Adding a default export alone is insufficient: V1 returned hooks must be ported to domain hook registrations, event subscriptions, and cleanup. A no-op setup would hide the load error without restoring functionality.

Official migration documentation: https://opencode.ai/v2/docs/build/plugins/migrate-v1

Reproduction

  1. Use OpenCode 2.0.5 and Caveman CLI 1.3.4.
  2. Run caveman enable opencode.
  3. OpenCode discovers ~/.config/opencode/plugins/caveman-native.js automatically.
  4. Inspect the server plugin status and matching server log entry.

Platform

  • Other: OpenCode 2.0.5 on macOS
  • Caveman CLI: 1.3.4, installed as @caveman-ai/cli in Bun's global packages
  • Caveman binary release: bin-v1.1.7
  • Installed OpenCode plugin packages: @opencode-ai/plugin and @opencode/plugin; their presence does not translate V1 plugin code

Suggested fix

Port the generator to the V2 API, preserving prompt/context/compaction hooks, before/after tool processing, event handling, and cleanup. Account for changed event payloads, structured system and tool content, and the bash to shell tool rename. Add a generated-plugin loading test and focused behavior tests against a supported OpenCode V2 release. If retaining V1 support, use separate implementations or the documented dual-version entrypoint.