Skip to content

TypeError: undefined is not an object (evaluating 'schema2._zod.def') - zod v3/v4 conflict when plugins bundle zod v4 #21155

Closed as not planned

Description

@hrygo

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

  1. Install oh-my-openagent (depends on zod ^4.1.8)
  2. Add it to opencode.json: `"plugin": ["oh-my-openagent"]`
  3. Run `opencode`
  4. Type any instruction (e.g., "hello")
  5. Crash on first tool execution — any model, any plugin

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

  • `opencode --pure` (no plugins) → works perfectly
  • `opencode` with oh-my-openagent → crash on first tool

Possible Fixes

  1. Migrate internal `toJsonSchema` to use public zod APIs or a version-agnostic schema extraction approach
  2. Pin opencode's bundled zod to v4 to match the plugin ecosystem
  3. Isolate plugins' zod v4 from the global Bun module scope (module bundling/pinning)

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 6, 2026
  2. github-actions commented on Apr 6, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

  3. pavel-kalmykov commented on Apr 20, 2026

    @pavel-kalmykov

    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:

    1. npx claude-mem install --ide opencode
    2. launch opencode, submit any prompt
    3. 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.

  4. rpiwnicki commented on Apr 21, 2026

    @rpiwnicki

    I have same problem with n._zod.def.
    OpenCode crashes on every prompt after install claude-mem.

  5. abnersajr commented on Apr 22, 2026

    @abnersajr

    Same issue here. A screenshot of the error. As soon I send any message on opencode it triggers the error.

    Image
  6. NulisKode commented on Apr 23, 2026

    @NulisKode

    how to fixxx, Same issue here :(

  7. obiwancenobi commented on Apr 23, 2026

    @obiwancenobi

    how to fixxx, Same issue here :(

    @NulisKode as mentioned above: For now: delete ~/.config/opencode/plugins/claude-mem.js, or run opencode --pure.

  8. mendax-iitm commented on Apr 23, 2026

    @mendax-iitm

    Same issue
    Image

  9. xuxusheng commented on Apr 29, 2026

    @xuxusheng

    same +1

  10. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  11. Hamza-Bik commented on May 5, 2026

    @Hamza-Bik

    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

    1. Run OpenCode in pure mode to confirm plugin issue:
      opencode --pure

    2. 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

    Expected output includes:
    plugins:
    none

  12. rekram1-node commented on May 5, 2026

    @rekram1-node
    Collaborator

    oc uses zod v4, maybe ur on older oc version

  13. github-actions commented on Jul 5, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions