zod4

Migrate Zod 3 schemas to Zod 4 and produce a migration report.

9|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/klh/speedy-claude --skill zod4-klh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zod4
Source: https://github.com/klh/speedy-claude/tree/main/skills/zod4
Command: npx skills add https://github.com/klh/speedy-claude --skill zod4-klh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migration and compatibility gaps when upgrading from Zod 3 to Zod 4 cause TypeScript type errors, runtime validation regressions, and confusing API differences that break validation logic across a codebase. This guide consolidates breaking changes, migration patterns, and troubleshooting steps to reduce manual edits and test failures during the upgrade.

Core Features & Use Cases

  • Breaking Changes Reference: Clear, prioritized explanations for high-impact changes such as the new z.record signature, removed .strict()/.passthrough(), and .default() behavior changes.
  • Migration Checklist & Patterns: Step-by-step fixes for common code patterns including record schemas, strict vs loose object shapes, error formatting updates, and transform/default interactions.
  • Codemod & Automation Guidance: Advice on running a community codemod, search-and-replace patterns, and verifying TypeScript and runtime behavior after changes.
  • Feature Adoption & Optimization: Introduces Zod 4 new features (z.file, z.templateLiteral, .meta, z.globalRegistry) and the lighter zod/mini import for bundle-size improvements.
  • Troubleshooting & Testing: Practical checks for TypeScript version requirements, test strategies, and runtime error resolution examples.

Quick Start

Convert all single-argument z.record calls to the two-argument form, replace .strict() and .passthrough() with z.strictObject and z.looseObject respectively, update error handling to use z.treeifyError, run the zod-v3-to-v4 codemod where helpful, and execute the test suite to validate changes.

Frequently Asked Questions about zod4

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate Zod 3 schemas to Zod 4 without breaking runtime validation?

To migrate Zod 3 schemas to Zod 4, update incompatible validation patterns by converting single-argument z.record calls to accept key and value schemas, replacing removed .strict() and .passthrough() with z.strictObject and z.looseObject, and updating error handling using z.treeifyError.

Why does z.record fail after upgrading to Zod 4?

The z.record signature changed in Zod 4, requiring both a key schema and a value schema as arguments. You must update all single-argument z.record calls to the new two-argument form to resolve TypeScript type errors and runtime validation regressions.

What TypeScript version is required for Zod 4 schema migration?

Zod 4 schema migration requires TypeScript 4.5 or higher compatibility. Ensure your TypeScript codebase meets this prerequisite before updating validation patterns, running the zod-v3-to-v4 codemod, or executing your test suite to verify runtime behavior.

How do I handle removed .strict() and .passthrough() object methods in Zod 4?

In Zod 4, replace the removed .strict() and .passthrough() object methods with z.strictObject and z.looseObject respectively. This maintains your desired object shape strictness and prevents validation regressions when upgrading your TypeScript codebase.

How do I update error handling for Zod 4 schema validation?

Update Zod 4 error handling by replacing deprecated error formatting methods with z.treeifyError or prefault where needed. This resolves confusing API differences and ensures your runtime validation errors are correctly structured after the migration.

What new features can I adopt after migrating to Zod 4?

After migrating to Zod 4, adopt new features like z.file, z.templateLiteral, .meta, and z.globalRegistry to enhance schemas. You can also use the lighter zod/mini import for bundle-size improvements in your TypeScript application.