.agents/skills/zod-to-form-cli/SKILL.md
This skill should be used when the user asks to generate a form from a Zod schema, use zodform CLI, codegen form component, generate tsx from zod, set up zod-to-form codegen, create a static form from schema, build-time form generation, zodform generate command, CLI form generator, zodform watch mode, zodform server action, or wants to generate static .tsx form components from Zod v4 schemas using the zodform generate CLI. Covers the generate command, component configuration, auto-save mode, server actions, watch mode, and the programmatic API.
npx skillsauth add pradeepmouli/zod-to-form zod-to-form-cliInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Set up build-time form generation using @zod-to-form/cli. This skill covers installation, the zodform generate command, generated output structure, component configuration, auto-save mode, server actions, watch mode, and the programmatic API.
Apply this skill when a project needs static, hand-readable .tsx form components generated from Zod v4 schemas at build time. Best suited for production forms, design system integration, and cases where the generated code should be inspected, customized, and committed — with zero runtime dependency on zod-to-form.
zod@^4.0.0) — Zod v3 is not supportedpnpm add -D @zod-to-form/cli zod
The CLI is a dev dependency — it runs at build time, not in production.
// src/schemas/user.ts
import { z } from 'zod';
export const userSchema = z.object({
name: z.string().min(2, 'Name must be at least 2 characters'),
email: z.string().email('Invalid email address'),
role: z.enum(['admin', 'editor', 'viewer']),
bio: z.string().optional(),
newsletter: z.boolean().default(false)
});
npx zodform generate \
--schema src/schemas/user.ts \
--export userSchema \
--out src/components/ \
--name UserForm
The generated src/components/UserForm.tsx imports only react-hook-form, @hookform/resolvers, and the schema — no @zod-to-form/* imports appear:
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { userSchema } from '../schemas/user';
type FormData = z.output<typeof userSchema>;
export function UserForm(props: { onSubmit: (data: FormData) => void }) {
const { register, handleSubmit } = useForm<FormData>({
resolver: zodResolver(userSchema)
});
return (
<form onSubmit={handleSubmit(props.onSubmit)}>
<div>
<label htmlFor="name">Name</label>
<input id="name" type="text" {...register('name')} />
</div>
<div>
<label htmlFor="email">Email</label>
<input id="email" type="email" {...register('email')} />
</div>
<div>
<label htmlFor="role">Role</label>
<select id="role" {...register('role')}>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
<option value="viewer">Viewer</option>
</select>
</div>
<button type="submit">Submit</button>
</form>
);
}
Required flags: --schema <path> and --export <name>. Common optional flags include --out, --name, --mode (submit | auto-save), --ui (shadcn | unstyled), --component-config, --force, --dry-run, --server-action, and --watch. See references/cli-reference.md for the complete flags table and naming conventions.
Generates handleSubmit + onSubmit prop pattern:
npx zodform generate --schema src/schemas/user.ts --export userSchema
Generates watch + useEffect pattern with onValueChange callback and no submit button:
npx zodform generate --schema src/schemas/user.ts --export userSchema --mode auto-save
Output uses mode: 'onChange' in useForm and fires onValueChange on every field update.
Map field types to custom components using a config file. This same format works with the runtime <ZodForm> — see references/shared-config.md.
// src/config/form-components.ts
import { defineComponentConfig } from '@zod-to-form/cli';
export default defineComponentConfig({
components: '@/components/ui',
fieldTypes: {
Input: { component: 'TextInput' },
Textarea: { component: 'TextareaInput' },
Select: { component: 'SelectInput' },
Checkbox: { component: 'CheckboxInput' }
},
fields: {
bio: { fieldType: 'Textarea', props: { rows: 6 } }
}
});
npx zodform generate \
--schema src/schemas/user.ts \
--export userSchema \
--component-config src/config/form-components.ts \
--out src/components/
The generated file will include static imports from the config's components path and apply per-field props:
import { TextInput, TextareaInput } from '@/components/ui';
// ...
<TextareaInput id="bio" {...register('bio')} rows={6} />;
Resolution priority: per-field override → field type mapping → default rendering. Use defineComponentConfig<TComponents, TValues>() for type-safe autocomplete. See references/shared-config.md for the full config shape, type-safe patterns, and resolution details.
Generate a paired Next.js server action alongside the form:
npx zodform generate \
--schema src/schemas/user.ts \
--export userSchema \
--server-action \
--out src/components/
Produces both UserForm.tsx and user-form-action.ts.
Regenerate automatically when the schema file changes:
npx zodform generate \
--schema src/schemas/user.ts \
--export userSchema \
--out src/components/ \
--watch
Combine with --force to overwrite on each regeneration.
Embed generation in scripts or build pipelines using runGenerate(options) (returns { outputPath, code, wroteFile, actionPath, actionCode }) or createProgram() for a Commander.js instance. See references/cli-reference.md for the full programmatic API, return types, and validateComponentConfig().
Add to a build script in package.json:
{
"scripts": {
"generate:forms": "zodform generate --schema src/schemas/user.ts --export userSchema --out src/components/ --force"
}
}
Or add as a pre-build step in CI pipelines to ensure generated forms stay in sync with schema changes.
The CLI codegen and runtime <ZodForm> share @zod-to-form/core — the same walker produces the same FormField[] tree. A component config file can drive both paths to produce functionally identical forms. See references/shared-config.md for details.
references/shared-config.md — Shared component config format for CLI + runtime parityreferences/cli-reference.md — Complete CLI flags and programmatic APItools
Use when working with zod-to-form (core, react, cli, codegen, vite).
tools
Vite plugin for zod-to-form — transforms ?z2f imports into generated form components and optionally replaces <ZodForm> JSX call sites with generated components at build time Use when: You want `import SignupForm from './signup.schema?z2f'` to Just Work in a.... Also: vite, vite-plugin, zod, zod-v4, codegen, forms, form-generation, schema-driven, react-hook-form, build-plugin, jsx-transform.
development
Runtime <ZodForm> renderer for Zod v4 schemas Use when: You need form rendering in storybook, playgrounds, or low-traffic admin UIs —.... Also: zod, zod-v4, react, forms, form-generation, react-hook-form, schema-driven, dynamic-forms, form-renderer, hookform-resolver, zod-form-renderer.
development
Schema walker and processor registry for Zod v4 form generation Use when: You want per-field validation instead of whole-form validation. Also: zod, zod-v4, forms, form-generation, schema, schema-walker, processor-registry, react-hook-form, schema-driven, form-schema, zod-registry.