You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError: undefined is not an object (evaluating 'schema2._zod.def') - zod v3/v4 conflict when plugins bundle zod v4 #21155
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.
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)
Reacted by Pierre Teyssedre, Omar Abdelmegid, Kenneth Luján Rosas, bulga138, Pável Kalmykov Razgovórov, rvpv, adrian-pattz, Vasily Pelikh and Bada
The same crash fires from the claude-mem OpenCode plugin (thedotmack/claude-mem). v12.3.2 (shipped 2026-04-20) still declares claude_mem_search's args as a plain JS object ({query: {type: "string", description: "..."}}) instead of a Zod schema, so it hits this exact toJsonSchema(schema._zod.def) path.
Repro:
npx claude-mem install --ide opencode
launch opencode, submit any prompt
crash at #maybeClose → #handleOnExit in child_process with TypeError: undefined is not an object (evaluating 'n._zod.def')
Upstream tracks it: thedotmack/claude-mem#1947 is open (reopened by the maintainer after an accidental backlog cleanup), and their PR #2063 tried a fix but closed unmerged.
For now: delete ~/.config/opencode/plugins/claude-mem.js, or run opencode --pure.
If OpenCode crashes right after first prompt with an error like:
TypeError: undefined is not an object (evaluating 'n._zod.def')
it may be caused by a third-party plugin (in my case: claude-mem), not the model itself.
What worked
Run OpenCode in pure mode to confirm plugin issue: opencode --pure
Disable plugin by moving it out of plugins folder: mkdir -p ~/.config/opencode/plugins.disabled mv ~/.config/opencode/plugins/claude-mem.js ~/.config/opencode/plugins.disabled/claude-mem.js.disabled
3.Verify no plugins are loaded: opencode debug info
Activity
github-actions commentedon Apr 6, 2026
This issue might be a duplicate of an existing issue. Please check:
zodToJsonSchemabroken with Zod v4), which shares the same root cause — zod v3 APIs being used internally while zod v4 is present.pavel-kalmykov commentedon Apr 20, 2026
The same crash fires from the claude-mem OpenCode plugin (thedotmack/claude-mem). v12.3.2 (shipped 2026-04-20) still declares
claude_mem_search'sargsas a plain JS object ({query: {type: "string", description: "..."}}) instead of a Zod schema, so it hits this exacttoJsonSchema(schema._zod.def)path.Repro:
npx claude-mem install --ide opencodeopencode, submit any prompt#maybeClose→#handleOnExitinchild_processwithTypeError: undefined is not an object (evaluating 'n._zod.def')Upstream tracks it: thedotmack/claude-mem#1947 is open (reopened by the maintainer after an accidental backlog cleanup), and their PR #2063 tried a fix but closed unmerged.
For now: delete
~/.config/opencode/plugins/claude-mem.js, or runopencode --pure.rpiwnicki commentedon Apr 21, 2026
I have same problem with
n._zod.def.OpenCode crashes on every prompt after install claude-mem.
abnersajr commentedon Apr 22, 2026
Same issue here. A screenshot of the error. As soon I send any message on opencode it triggers the error.
NulisKode commentedon Apr 23, 2026
how to fixxx, Same issue here :(
obiwancenobi commentedon Apr 23, 2026
@NulisKode as mentioned above: For now: delete ~/.config/opencode/plugins/claude-mem.js, or run opencode --pure.
mendax-iitm commentedon Apr 23, 2026
Same issue

xuxusheng commentedon Apr 29, 2026
same +1
Hamza-Bik commentedon May 5, 2026
If OpenCode crashes right after first prompt with an error like:
TypeError: undefined is not an object (evaluating 'n._zod.def')
it may be caused by a third-party plugin (in my case: claude-mem), not the model itself.
What worked
Run OpenCode in pure mode to confirm plugin issue:
opencode --pureDisable plugin by moving it out of plugins folder:
mkdir -p ~/.config/opencode/plugins.disabled mv ~/.config/opencode/plugins/claude-mem.js ~/.config/opencode/plugins.disabled/claude-mem.js.disabled3.Verify no plugins are loaded:
opencode debug infoExpected output includes:
plugins:
none
rekram1-node commentedon May 5, 2026
oc uses zod v4, maybe ur on older oc version
github-actions commentedon Jul 5, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.