@kubb/cli
v5.33.0
Published
Official CLI for Kubb. Run kubb generate, kubb init, kubb validate, and kubb studio to manage the full code generation lifecycle.
Maintainers
Readme
@kubb/cli
The command-line interface for Kubb
Official CLI for Kubb. Run kubb generate to produce TypeScript types, API clients, hooks, validators, and mocks.
Includes interactive project setup (kubb init), spec validation, watch mode, and plain-text output for CI and AI agents.
Installation
bun add -D @kubb/cli
# or
pnpm add -D @kubb/cli
# or
npm install -D @kubb/cliCommands
kubb init: scaffold a new projectkubb generate: run code generationkubb studio: connect this project to Kubb Studiokubb validate: validate an OpenAPI speckubb add: install an extension from the registrykubb update: update installed extensionskubb remove: remove an extensionkubb list: show the installed extensions
The command reference on kubb.dev has every flag of every command.
kubb init
Scaffold a kubb.config.ts and install plugins for code generation from an OpenAPI spec. Run without flags for an interactive setup wizard, or pass flags to skip the prompts.
npx kubb initOptions
| Flag | Short | Type | Default | Description |
| ------------------ | ----- | ------- | ---------------- | ------------------------------------------ |
| --yes | -y | boolean | false | Skip all prompts and use defaults |
| --input <path> | -i | string | ./openapi.yaml | Path to the OpenAPI specification |
| --output <path> | -o | string | ./src/gen | Output directory for generated files |
| --plugins <list> | | string | | Comma-separated list of plugins to install |
Available plugin values for --plugins: plugin-ts, plugin-axios, plugin-fetch, plugin-react-query, plugin-vue-query, plugin-zod, plugin-faker, plugin-msw, plugin-cypress, plugin-mcp, plugin-redoc.
Examples
# Interactive wizard
npx kubb init
# Accept all defaults
npx kubb init --yes
# Fully non-interactive
npx kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod
# Select specific plugins only
npx kubb init --plugins plugin-ts,plugin-axios,plugin-react-queryThe wizard will:
- Detect or create a
package.jsonif one does not exist - Prompt for your OpenAPI specification path (default:
./openapi.yaml) - Ask for the output directory (default:
./src/gen) - Let you choose which plugins to install
- Install the selected packages using your package manager (npm, pnpm, yarn, or bun)
- Generate a
kubb.config.tswith your chosen configuration
kubb generate
Generate TypeScript types, API clients, React Query hooks, Zod schemas, and more from an OpenAPI specification. Reads kubb.config.ts by default. Pass an OpenAPI file path as the first argument to override the input without editing the config.
npx kubb generateOptions
| Flag | Short | Type | Default | Description |
| --------------------- | ----- | ------- | ------- | ----------------------------------------------------------------------------------------------------------- |
| [input] | | string | | OpenAPI file path or URL that overrides input in the config |
| --config <path> | -c | string | | Path to the Kubb config file |
| --log-level <level> | -l | string | info | Log level: silent, info, or verbose |
| --watch | -w | boolean | false | Re-generate whenever the input file changes |
| --dry-run | | boolean | false | Preview the run without writing files |
| --check | | boolean | false | Compare the output with the files on disk and write nothing. Exits 1 when a file is out of date |
| --diff | | boolean | false | Print a diff for each out-of-date file. Turns --check on |
| --force | | boolean | false | Generate even when kubb-lock.json says the output is up to date |
| --no-lockfile | | boolean | | Generate without reading or writing kubb-lock.json |
| --verbose | | boolean | false | Override log level to verbose |
| --silent | -s | boolean | false | Override log level to silent |
| --reporter <names> | | string | cli | Reporters that render the run, comma-separated: cli, json, file, html. Overrides config.reporters |
Examples
# Use kubb.config.ts in the current directory
npx kubb generate
# Override the input spec without editing the config
npx kubb generate ./openapi.yaml
# Point to a custom config file
npx kubb generate --config ./configs/kubb.config.ts
# Watch for changes and regenerate automatically
npx kubb generate --watch
# Verbose output
npx kubb generate --verbose
# Fail when the generated files on disk are out of date, and print what would change
npx kubb generate --check --diff
# Write a JSON run report alongside the CLI output
npx kubb generate --reporter cli,json
# Write an HTML run report
npx kubb generate --reporter htmlkubb studio
Connect this project to Kubb Studio and generate from the browser. Kubb runs on your machine, reads your config and spec from disk, and streams progress and files back to Studio over a WebSocket.
npx kubb studioThe first run pairs the project. The CLI prints a short code, and you approve it in Studio. The
CLI then stores the token per project, under ~/.kubb/projects/. The project is the folder that
holds kubb.config.ts, found by walking up from the current folder, or the current folder when
there is none. Later runs reuse the token. The pairing key goes to the system keychain when one
is available, and into the same file otherwise. Set KUBB_HOME to store the credential files
somewhere other than ~/.kubb.
Each permission is off by default. On the first connect to a project, the CLI shows one checklist
of the permissions that no flag grants. It saves your answers for that project. Each --allow-*
flag grants its permission and skips it in the checklist. Outside an interactive terminal, such as
in CI, the CLI shows no checklist, so pass the --allow-* flags the run needs. Run
kubb studio permissions to change the saved answers.
Arguments
| Argument | Required | Description |
| ---------- | -------- | ----------------------------------------------------------------------------------------------- |
| [action] | No | connect (default), start, stop, login, logout, status, permissions, or snapshot |
Options
| Flag | Short | Type | Default | Description |
| --------------------- | ----- | ------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| --config <path> | -c | string | | Path to the Kubb config file |
| --url <url> | | string | https://kubb.studio | Base URL of the Kubb Studio instance. Defaults to the one this project paired with |
| --allow-read | | boolean | false | Read the source of generated files. Asked for once per project when omitted |
| --allow-read-ast | | boolean | false | Read the parsed spec (the Kubb AST). Asked for once per project when omitted |
| --allow-write | | boolean | false | Write generated files to disk. Asked for once per project when omitted |
| --allow-config-edit | | boolean | false | Edit plugin options in kubb.config.ts. Asked for once per project when omitted |
| --allow-install | | boolean | false | Let Studio install extensions with kubb add. Needs --allow-config-edit too. Asked once |
| --allow-update | | boolean | false | Let Studio update installed extensions with kubb update. Asked once |
| --allow-remove | | boolean | false | Let Studio remove extensions with kubb remove. Needs --allow-config-edit too. Asked once |
| --allow-save-input | | boolean | false | Let Studio save the spec it sends as input. Needs --allow-config-edit too. Asked once |
| --allow-file-refs | | boolean | false | Let a $ref read a local file outside the project, or a URL on a host that is not public. Asked for once per project when omitted |
| --allow-exec | | boolean | false | Run the formatter, the linter, and output.postGenerate. Asked once per project when omitted |
| --no-open | | boolean | | Do not open the approval page in a browser while pairing |
| --log-level <level> | -l | string | info | Log level: silent, info, or verbose |
The old camelCase spelling of a flag (--allowWrite, --logLevel, --dryRun) still works and
prints a deprecation warning on stderr. Support for it will be removed in a future major version.
Examples
# Pair on first run, then connect read-only
npx kubb studio
# Let Studio write generated files to disk
npx kubb studio --allow-write
# Pair without connecting
npx kubb studio login
# Show which machine is paired, and with which Studio
npx kubb studio status
# Forget the stored token
npx kubb studio logout
# Point at a self-hosted Studio
npx kubb studio --url http://localhost:3000kubb validate
Parse and validate an OpenAPI/Swagger file for structural correctness. Reports schema errors, missing required fields, and malformed references. Use this before running generate to catch spec issues early.
npx kubb validate <path-or-url>Arguments
| Argument | Required | Description |
| --------- | -------- | --------------------------------------------------- |
| <input> | ✅ | Path or URL to the OpenAPI/Swagger file to validate |
Examples
# Validate a local file
npx kubb validate ./openapi.yaml
# Validate a remote spec
npx kubb validate https://petstore3.swagger.io/api/v3/openapi.jsonSupporting Kubb
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
