
Zod
- 196 repo stars
- Updated July 25, 2026
- secondsky/claude-skills
Validate API requests/responses, form data, env vars, and configs with Zod; infer types and generate JSON Schema for OpenAPI/AI.
About
Zod is TypeScript-first schema validation with type inference for API requests/responses, form data, env vars, and configs, plus JSON Schema generation for OpenAPI or AI tools. Developers use it to add runtime validation and type-safe data handling while constructing an app.
- TypeScript-first schemas
- Runtime validation + type inference
- JSON Schema for OpenAPI/AI
- Zero deps, 2kb
Zod by the numbers
- Data as of Jul 28, 2026 (Skillselion catalog sync)
/plugin marketplace add secondsky/claude-skills/plugin install zod@claude-skillsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| repo stars | ★ 196 |
|---|---|
| Last updated | July 25, 2026 |
| Repository | secondsky/claude-skills ↗ |
What it does
Validate API requests/responses, form data, env vars, and configs with Zod; infer types and generate JSON Schema for OpenAPI/AI.
README.md
Zod - TypeScript-First Schema Validation
A comprehensive Claude Code skill for Zod, the TypeScript-first schema validation library with zero dependencies and powerful type inference.
🎯 When to Use This Skill
Claude will automatically suggest this skill when you're working with:
- Schema validation and runtime type checking
- API request/response validation and DTO validation
- Form validation with React Hook Form or other form libraries
- Environment variable validation and configuration validation
- Data transformation and refinement with custom logic
- JSON Schema generation for OpenAPI or AI structured outputs
- Type-safe parsing with
.parse(),.safeParse(),.parseAsync() - tRPC, Prisma, or other Zod ecosystem integrations
- Error handling and custom error messages
- TypeScript type inference from runtime schemas
🚀 What This Skill Provides
Comprehensive Coverage (v2.0.0 - Updated 2025-11-17)
- ✅ All primitive types: strings, numbers, booleans, dates, bigints
- ✅ Complex types: objects, arrays, tuples, enums, unions, intersections
- ✅ Advanced patterns: refinements, transformations, codecs, recursive types
- ✅ Error handling: parse vs safeParse, error formatting, custom messages
- ✅ Error customization: Three-level system (schema, per-parse, global)
- ✅ Error formatting: flattenError, treeifyError, prettifyError with detailed examples
- ✅ Type inference: z.infer, input/output types
- ✅ JSON Schema: conversion to JSON Schema for OpenAPI
- ✅ Metadata system: .meta(), .register(), registries, global registry
- ✅ Localization: Built-in support for 40+ locales (i18n)
- ✅ Migration guide: Comprehensive v3 to v4 upgrade documentation
- ✅ Codecs: Bidirectional transformations with practical examples
- ✅ Ecosystem: ESLint plugins, tRPC, Prisma, React Hook Form
- ✅ Best practices: performance tips, common patterns
- ✅ Known issues: documented solutions with examples
Code Examples
Every feature includes production-ready code examples:
- Basic validation patterns
- API request/response validation
- Form validation with error handling
- Environment variable validation
- Composable schema patterns
- Advanced refinements and transformations
- Bidirectional codecs for dates and other types
Error Prevention
This skill prevents 8+ common errors:
- Missing validation leading to runtime crashes
- Incorrect type inference
- Unhandled validation errors
- Improper error message formatting
- Using outdated patterns
- Inefficient schema composition
- Missing refinements for business logic
- Incorrect async validation setup
📦 Installation
bun add zod
# or
npm install zod
# or
pnpm add zod
# or
yarn add zod
Requirements:
- TypeScript v5.5+ with
"strict": trueintsconfig.json - Zod 4.x (4.1.12+)
⚠️ Important - Zod 4.x Only: This skill documents Zod 4.x features with comprehensive v4.1 enhancements. The following APIs require Zod 4 and are NOT available in Zod 3.x:
z.codec()- Bidirectional transformations (new in v4.1)z.iso.date(),z.iso.time(),z.iso.datetime(),z.iso.duration()- ISO format validatorsz.toJSONSchema()- JSON Schema generationz.treeifyError(),z.prettifyError(),z.flattenError()- New error formatting helpers.meta(),.register(),z.registry()- Enhanced metadata system- Unified
errorparameter - Replacesmessage,invalid_type_error,required_error,errorMap - Built-in localization support for 40+ languages
📖 Includes Migration Guide: Comprehensive v3 to v4 migration documentation with breaking changes, checklist, and upgrade strategies.
For Zod 3.x compatibility or migration guidance, see https://zod.dev
🔥 Quick Examples
Basic Schema
import { z } from "zod";
const UserSchema = z.object({
username: z.string().min(3).max(20),
email: z.string().email(),
age: z.number().int().positive(),
});
type User = z.infer<typeof UserSchema>;
// Validate (throws on error)
const user = UserSchema.parse(data);
// Validate (safe, no throw)
const result = UserSchema.safeParse(data);
if (result.success) {
console.log(result.data); // Typed!
}
API Validation
const CreatePostRequest = z.object({
title: z.string().min(1).max(200),
content: z.string(),
tags: z.array(z.string()).max(10),
published: z.boolean().default(false),
});
app.post("/posts", async (req, res) => {
const result = CreatePostRequest.safeParse(req.body);
if (!result.success) {
return res.status(400).json({
errors: z.flattenError(result.error).fieldErrors,
});
}
const post = await createPost(result.data);
res.json(post);
});
Environment Variables
const EnvSchema = z.object({
NODE_ENV: z.enum(["development", "production", "test"]),
DATABASE_URL: z.string().url(),
PORT: z.coerce.number().int().positive().default(3000),
API_KEY: z.string().min(32),
});
const env = EnvSchema.parse(process.env);
// Now use typed env.PORT, env.DATABASE_URL, etc.
Custom Validation
const PasswordSchema = z.string()
.min(8, "Too short")
.refine((val) => /[A-Z]/.test(val), "Must contain uppercase")
.refine((val) => /[0-9]/.test(val), "Must contain number")
.refine((val) => /[^A-Za-z0-9]/.test(val), "Must contain special char");
🧩 Ecosystem Integration
ESLint Plugins
- eslint-plugin-zod-x - Best practices enforcement
- eslint-plugin-import-zod - Namespace import enforcement
Popular Libraries
- tRPC (38,863⭐) - End-to-end typesafe APIs
- React Hook Form - Form validation with zodResolver
- Prisma - Generate Zod schemas from Prisma models
- NestJS - DTO validation and OpenAPI docs
📊 Performance & Quality
- Zero dependencies
- 2kb gzipped core bundle
- ~65% token savings vs. manual documentation lookup
- 8+ errors prevented through comprehensive guidance
- Production-tested patterns and examples
🏗️ Common Use Cases
1. Form Validation
const FormSchema = z.object({
email: z.string().email("Invalid email"),
password: z.string().min(8, "Password too short"),
agreeToTerms: z.literal(true, {
errorMap: () => ({ message: "Must accept terms" }),
}),
});
2. tRPC Integration
export const appRouter = t.router({
getUser: t.procedure
.input(z.object({ id: z.string().uuid() }))
.query(({ input }) => db.user.findUnique({ where: { id: input.id } })),
});
3. Discriminated Unions
const ResponseSchema = z.discriminatedUnion("status", [
z.object({ status: z.literal("success"), data: z.any() }),
z.object({ status: z.literal("error"), message: z.string() }),
]);
4. Codecs (Bidirectional)
const DateCodec = z.codec(
z.iso.datetime(),
z.date(),
{
decode: (str) => new Date(str),
encode: (date) => date.toISOString(),
}
);
5. JSON Schema Generation
const jsonSchema = z.toJSONSchema(UserSchema, {
target: "openapi-3.0",
metadata: true,
});
🎯 Auto-Trigger Keywords
Claude will suggest this skill when you mention:
Core Concepts: zod, schema, validation, runtime validation, type inference, z.infer
Types: z.object, z.string, z.number, z.array, z.enum, z.union, z.discriminatedUnion, z.tuple, z.record, z.codec
Methods: parse, safeParse, parseAsync, refine, transform, coerce, decode, encode
Use Cases: API validation, form validation, environment variables, DTO validation, request validation, response validation
Ecosystem: tRPC, Prisma, React Hook Form, NestJS, zodResolver
Errors: ZodError, validation error, error formatting, custom error messages, treeifyError, flattenError, prettifyError
Advanced: refinement, transformation, codec, JSON Schema, OpenAPI, metadata, registry, localization, i18n
Migration: v3 to v4, breaking changes, upgrade guide, migration checklist
📚 What's Included
SKILL.md Contents
- Overview & Installation - Getting started, requirements
- Migration Guide (v3 → v4) - Breaking changes, migration checklist, upgrade strategies
- Core Concepts - Parsing methods, basic patterns
- Primitive Types - Strings, numbers, dates with all validators
- Complex Types - Objects, arrays, tuples, enums, unions
- Advanced Patterns - Refinements, transforms, codecs, recursive types
- Error Handling - Parse methods, error formatting (flatten, treeify, prettify)
- Error Customization - Three-level system (schema, per-parse, global), localization
- Type Inference - z.infer, input/output types
- JSON Schema - Conversion to JSON Schema with metadata
- Metadata System - .meta(), .register(), registries, global registry
- Functions - Function validation and implementation
- Common Patterns - Env vars, APIs, forms, partial updates
- Ecosystem - ESLint, tRPC, Prisma, code generation
- Known Issues - 8 documented issues with solutions
- Performance Tips - Optimization strategies
- Best Practices - Production-ready recommendations
- Quick Reference - Comprehensive API cheat sheet
🔗 Resources
- Official Docs: https://zod.dev
- GitHub: https://github.com/colinhacks/zod
- Playground: https://zod-playground.vercel.app
- Ecosystem: https://zod.dev/ecosystem
🏆 Why Use This Skill?
Without This Skill
- 📄 Constantly referencing docs (12k+ tokens per lookup)
- 🐛 Trial-and-error with refinements and transforms
- ❌ Missing error handling patterns
- ⏰ Slow schema composition
- 🤔 Confusion between similar methods
With This Skill
- ⚡ Instant access to comprehensive patterns (~5k tokens)
- ✅ Production-tested code examples
- 🎯 Error prevention through best practices
- 🚀 65% faster schema development
- 🧠 Complete API reference at your fingertips
📦 Installation for Claude Code
This skill is part of the claude-skills repository.
Option 1: Install from Repository
# Clone the repository
git clone https://github.com/secondsky/claude-skills.git
cd claude-skills
# Install this skill
./scripts/install-skill.sh zod
# Verify installation
ls -la ~/.claude/skills/zod
Option 2: Manual Installation
# Create symlink
ln -s /path/to/claude-skills/skills/zod ~/.claude/skills/zod
# Verify
claude code # Start Claude Code and mention "zod validation"
🤝 Contributing
Found an issue or want to improve this skill? Contributions are welcome!
- Fork the repository
- Make your changes
- Test the skill
- Submit a pull request
📄 License
MIT License - see LICENSE for details.
🔄 Version History
2.0.0 (2025-11-17) - Major Update: v4.1 Enhancements
- ✨ Comprehensive v3 to v4 migration guide with breaking changes
- ✨ Enhanced error customization with three-level system
- ✨ Expanded metadata API with registry system documentation
- ✨ Improved error formatting with practical nested examples
- ✨ Built-in localization support for 40+ locales
- ✨ Detailed codec documentation with real-world patterns
- ✨ Performance improvements and architectural changes explained
- ✨ Updated all examples to reflect v4.1 best practices
1.0.0 (2025-11-11) - Initial release
- Comprehensive Zod 4.1.12+ coverage (Zod 4.x stable)
- All primitive and complex types
- Error handling patterns
- JSON Schema conversion
- Codecs documentation
- Ecosystem integration
- 8+ documented issues with solutions
- Production-tested examples
Skill Version: 2.0.0 Package Version: 4.1.12+ (Zod 4.x stable) Last Verified: 2025-11-17 Token Savings: ~65% Errors Prevented: 8+ Production Status: ✅ Tested
Made with ❤️ for the Claude Code community