Describe the bug
When a plugin that depends on zod v4 is installed (e.g. oh-my-openagent), opencode crashes immediately with the following error when attempting to execute any tool:
TypeError: undefined is not an object (evaluating 'schema2._zod.def')
at process (/$bunfs/root/src/cli/cmd/tui/worker.js:80980:29)
at toJsoNschema (/$bunfs/root/src/cli/cmd/tui/worker.js:81668:15)
To Reproduce
- Install oh-my-openagent (depends on zod ^4.1.8)
- Add it to opencode.json: `"plugin": ["oh-my-openagent"]`
- Run `opencode`
- Type any instruction (e.g., "hello")
- Crash on first tool execution — any model, any plugin
Expected behavior
OpenCode should work normally with plugins that bundle zod v4.
Environment
- opencode version: 1.3.16
- OS: macOS 25.3.0
- Plugin: oh-my-openagent@3.15.2 (zod ^4.1.8)
Root Cause Analysis
The bundled worker.js in opencode's Bun runtime internally uses zod v3's private API `_zod.def` in the `toJsonSchema` function (worker.js:81668). When a plugin brings in zod v4, zod v4 schemas are passed to this function, but zod v4 does not expose the same `_zod.def` internal structure. This causes `schema2` to be undefined.
Reproduction
- `opencode --pure` (no plugins) → works perfectly
- `opencode` with oh-my-openagent → crash on first tool
Possible Fixes
- Migrate internal `toJsonSchema` to use public zod APIs or a version-agnostic schema extraction approach
- Pin opencode's bundled zod to v4 to match the plugin ecosystem
- Isolate plugins' zod v4 from the global Bun module scope (module bundling/pinning)
Describe the bug
When a plugin that depends on zod v4 is installed (e.g. oh-my-openagent), opencode crashes immediately with the following error when attempting to execute any tool:
To Reproduce
Expected behavior
OpenCode should work normally with plugins that bundle zod v4.
Environment
Root Cause Analysis
The bundled worker.js in opencode's Bun runtime internally uses zod v3's private API `_zod.def` in the `toJsonSchema` function (worker.js:81668). When a plugin brings in zod v4, zod v4 schemas are passed to this function, but zod v4 does not expose the same `_zod.def` internal structure. This causes `schema2` to be undefined.
Reproduction
Possible Fixes