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
Bug: Zod TypeError when loading custom tools from .opencode directory #12336
OpenCode v1.1.51 crashes with TypeError when loading custom tools from .opencode directory
Version
OpenCode: 1.1.51
OS: Windows 11
Zod: 4.1.8
Error Message
at process (../../node_modules/.bun/zod@4.1.8/node_modules/zod/v4/core/to-json-schema.js:15:28)
at resolveTools (src/session/prompt.ts:704:62)```
## Root Cause
Zod 4.1.8 toJSONSchema function lacks defensive checks before accessing schema._zod.def
## Suggested Fix
Add defensive checks in toJSONSchema before accessing schema._zod.def
## Workaround
Remove or rename .opencode directory
---
Reported by: Claude (AI Assistant)
Date: 2026-02-06
Error: TypeError: undefined is not an object (evaluating 'command3.agent')
Root cause: command3.agent is undefined (null checking issue)
Different: This is about command handling, not Zod schema validation
Conclusion
This is a separate bug that needs its own fix. The commonality is that all three are TypeError issues in the same file, but they have different root causes and occur at different locations.
Activity
github-actions commentedon Feb 5, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
wlioi commentedon Feb 5, 2026
@github-actions[bot] This is not a duplicate of the mentioned issues.
Comparison with suggested issues
Our issue (#12336)
src/session/prompt.ts:704:62TypeError: undefined is not an object (evaluating 'schema._zod.def')toJSONSchemafunction lacks defensive checks when processing tool parameter schemas.opencodedirectory#12269
ToolRegistry.state()when importing tools with unresolvable dependencies#9733
src/session/prompt.ts:1597TypeError: undefined is not an object (evaluating 'command3.agent')command3.agentis undefined (null checking issue)Conclusion
This is a separate bug that needs its own fix. The commonality is that all three are TypeError issues in the same file, but they have different root causes and occur at different locations.
Please reopen this issue.
rekram1-node commentedon Feb 5, 2026
can u send ur custom tools?
wlioi commentedon Feb 5, 2026
@wlioi Yes! The minimal reproduction is:
This triggers the Zod TypeError in toJSONSchema when processing the nested ZodString.
wlioi commentedon Feb 5, 2026
@rekram1-node Apologies for the confusion! Here's the actual minimal reproduction code that triggers the bug:
Minimal Reproduction
The bug occurs when your custom tool returns a plain object instead of a Zod schema in the args field. Here's what triggers it:
Why This Fails
safeArgs._zod.defreturns a plain object like{ shape: { name: ZodString } }toJSONSchema()expects a Zod schema with_zodpropertyschema._zod.def,schema._zodis undefinedTypeError: undefined is not an object (evaluating 'schema._zod.def')The fix should be in OpenCode's to-json-schema.ts to handle cases where
schema._zodis undefined.github-actions commentedon Apr 7, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.