Skip to content
Commands

kubb init

The init command bootstraps a fresh Kubb project with an interactive wizard.

Run kubb init for an interactive setup wizard. Kubb looks at your project first, asks a few questions, shows the config for review, then installs your chosen plugins, writes kubb.config.ts, and runs the first generation.

Usage

Run the command in the directory where your Kubb project lives:

Terminal
npx kubb init

Before the first question, Kubb detects:

  • The package manager (bun, pnpm, npm, or yarn).
  • OpenAPI and Swagger files in the repo, such as openapi.yaml or api/swagger.json, up to three folders deep. It skips node_modules, dist, build, and hidden folders, and shows the version and operation count of the first one.

The wizard then asks for three things:

  • Which spec to read: a file it found, a URL, or another file.
  • Which plugins to add. The list comes from the Kubb registry, with plugin-ts selected by default. Choose the plugins you need; the CLI does not infer them from your framework or installed libraries. Plugin manifests declare which dependencies a selection requires.
  • The output folder, ./src/gen by default.

Kubb then shows the full kubb.config.ts and the packages it installs. Pick Change a choice to answer the questions again.

After you confirm, Kubb installs the packages, writes kubb.config.ts, and adds "generate": "kubb generate" to the package.json scripts when there is no generate script yet. It never changes an existing one. Then it runs the first generation. When that run fails, Kubb shows the error, keeps the setup, and exits with code 1.

Kubb installs kubb at the exact version of the CLI you ran. Each plugin is added the way kubb add adds it: at the version the registry pins, and only when it supports the running Kubb and Node.js versions.

Before it installs anything, Kubb checks the manifest of each chosen plugin. If a plugin's dependencies are not all chosen, or a plugin with role: "consumer" (such as plugin-react-query) has no client plugin next to it, kubb init names what is missing and stops.

Options

OptionDefaultDescription
--yes, -yfalseSkip all prompts and the review. Uses the first spec found (or ./openapi.yaml), plugin-ts, and ./src/gen, and prints one line per step.
--input, -iPath to the OpenAPI specification (local file or URL). Bypasses the spec path prompt.
--output, -oOutput directory for generated files. Bypasses the output directory prompt.
--pluginsComma-separated registry ids of the plugins to add, the same ids kubb add takes, such as plugin-ts,plugin-zod, or short names such as ts,zod. Bypasses the plugin selection prompt. An id that is not in the registry stops kubb init.
--dry-runfalsePreview the wizard without installing packages, writing files, or running the first generation.

Each flag skips only its own prompt and combines with --yes. Pass all three value flags to skip the choice prompts and review. If kubb.config.ts already exists, Kubb still asks before overwriting it unless you pass --yes.

Examples

Run with the defaults and no prompts:

Terminal
npx kubb init --yes

Run with no prompts and a specific spec, output directory, and plugins:

Terminal
npx kubb init --yes --input ./openapi.yaml --plugins ts,zod --output src/api
Output
✓ Installed kubb @kubb/plugin-ts @kubb/plugin-zod with npm
✓ Wrote kubb.config.ts
✓ Generated 84 files in src/api
Kubb is set up. Run npm run generate after changing the spec.

Add --dry-run to preview what the wizard would install and write.