Skip to content

@kiln-js/cli

@kiln-js/cli provides the kiln command. It creates projects, runs the development server, builds for production, serves the build, lists routes, generates files, type-checks, diagnoses problems, and renders every page to find errors.

bash
bun add -d @kiln-js/cli

The CLI is the only package you run from the terminal. The project's package.json scripts usually call it, so you run bun run dev, bun run build, and so on.


Commands

CommandPurpose
kiln create [name]Scaffold a new app.
kiln dev [--port <port>]Start the development server with SSR and hot reload.
kiln build [--target <target>]Build client and server bundles.
kiln start [--port <port>]Serve the production build.
kiln routesPrint the route table.
kiln generate [kind] [name] (alias g)Generate a page, API route, or layout.
kiln typecheckRun TypeScript over the project.
kiln doctorCheck the project and its environment.
kiln test [...paths]Render every page and report errors.
kiln --help, kiln --versionShow help or the version.

Commands that print a banner show it before the command runs, unless the first argument starts with -.

Errors are printed with the failing command as context and the process exits with status 1.


kiln create [name]

Scaffolds a project. Questions are asked interactively:

  • Project name. The default is name if you passed one, otherwise my-kiln-app. Letters, numbers, -, and _ are allowed.
  • Template. minimal, starter (the default), or blog.
  • Rendering mode for the home page. universal (the default), server, or client.
  • Example API route. Creates app/api/health.ts when confirmed.
  • Extras. .env and custom entries.
  • Inside the Kiln monorepo? When confirmed, workspace packages are linked instead of installed from npm.
  • Install dependencies now? When confirmed, runs bun install in the new folder.

If the target folder already exists, you are asked before anything is overwritten.


kiln dev [--port <port>]

Starts the development server. The default port is 3000.

  • Pages render on the server for every request.
  • Client code is hot-reloaded in the browser.
  • Server changes trigger a reload of the error page or the page, because they cannot be applied in place.
  • Adding or removing a route file reloads the page.
  • An error in a page shows an overlay with the file, a code frame, and the stack.

Before starting, the command checks that every Kiln package in the project matches the CLI version. A mismatch stops the command with an error that lists the problem packages and suggests kiln doctor.

The command also checks that every package the app imports is installed. It loads .env, .env.local, .env.development, and .env.development.local.

The dev server shows a dashboard with request counts, route timings, and scan cache statistics.


kiln build [--target <target>]

Builds production bundles.

TargetMeaning
none (default)Client and server bundles only.
vercelAlso produces .vercel/output with the Vercel adapter.

Any other target fails with Unknown target.

The build runs three steps, each shown with timing:

  1. Client bundle. Vite builds the client entry into dist/client, with a manifest.
  2. Server bundle. Vite builds the server entry into dist/server/server.js.
  3. Vercel output. Only with --target vercel.

It loads .env, .env.local, .env.production, and .env.production.local. Then it prints the sizes of each output and the engine it used (bun … · Bun.build or node … · esbuild).


kiln start [--port <port>]

Serves the built output. The default port is 3000.

The server loads dist/server/server.js and the manifest from dist/client. Static files from dist/client are served directly, with compression when the client accepts it. Pages are rendered by the server bundle.

Run kiln build first. If the manifest is missing, the command fails with No manifest entry … Run "kiln build" first.


kiln routes

Prints the route table, one line per route, with the pattern, render mode, and file. Use it to check how a file name maps to a URL.


kiln generate [kind] [name]

Creates a file from a template. Alias: g.

bash
kiln generate page blog/[slug]
kiln generate api users/[id] --methods GET,PATCH
kiln generate layout (marketing)

Arguments and prompts:

  • kind: page, api, or layout. Prompted when omitted.
  • name: the route path, such as blog/[slug] or (marketing)/pricing. Prompted when omitted. Letters, -, _, [], (), and / are allowed.

Options:

OptionApplies toMeaning
--mode <mode>pageuniversal, server, or client. Prompted for pages when omitted.
--loaderpageAdd a loader export.
--methods <methods>apiComma-separated HTTP methods, such as GET,POST.

A page is written to app/pages/<name>.tsx, with the mode suffix added for server and client. An API route is written to app/api/<name>.ts with one function per method. A layout is written to app/pages/<name>/_layout.tsx.

The command refuses to overwrite an existing file.


kiln typecheck

Runs tsc with the project's tsconfig.json. Exits with the compiler's status code. The command needs a tsconfig.json; kiln doctor reports when one is missing.


kiln doctor

Runs a set of checks and prints them in sections:

  • Runtime. Bun version (1.1 or later recommended) or Node version (18 or later required). The CLI version.
  • Project. package.json, node_modules, tsconfig.json, and whether the routes can be read.
  • Packages. Each Kiln package: installed or optional, and whether its version matches the CLI.
  • Configuration. DATABASE_URL: when the app source uses it, the check passes only if a .env or .env.local file defines it. The Markdown plugin, which the check expects when the app imports @kiln-js/md. Whether React is installed once.

Warnings do not stop the command. Failures set the exit status to 1, so you can use it in CI.


kiln test [...paths]

Renders pages through a Vite server, without a browser, and reports problems.

  • Every page route is requested with a sample path. Dynamic segments are replaced with example, and catch-all segments with a/b.
  • Each response is checked for status, and the render is checked for errors.
  • Optional paths arguments filter which routes run. A route runs when its sample URL starts with one of the given prefixes, such as kiln test /blog.

It prints a line per route with status, time, and any problems or warnings, then a summary. The exit status equals the number of failing pages, so it is non-zero when any page fails and works in CI.


Environment files

The CLI loads environment files with Vite's loader. For each command, the files are read in this order, and a real environment variable always wins over a file value:

CommandFiles
dev, test.env, .env.local, .env.development, .env.development.local
build, start.env, .env.local, .env.production, .env.production.local

Exit status

StatusMeaning
0Success.
1An error, or a failing check in doctor.
Nkiln test exits with the number of failing pages.