Skip to content

Tools

kerf build for static sites and server templates, Vite and Next.js for apps, and the checks in your editor as you type.

Commands

CommandDoes
kerf initwrites kerf.config.js (.mjs unless your package.json is "type": "module"), an AGENTS.md for AI coding agents if there isn't one, and, if src/ is missing, a starter page
kerf checkcompiles and checks without writing; exits 1 on errors
kerf buildchecks, then writes compiled pages, copied assets and the stylesheet to outDir; writes nothing if there are errors
kerf lspa language server for editors, over stdin and stdout (Editor)
OptionDoes
-w, --watchcheck or build again on every change (Ctrl+C to stop)
--jsoncheck, build: print the result as one JSON object, for CI and agents
--config <file>another config file
--hue <0-360>init: the brand hue (default 250)
--forceinit: overwrite an existing config
-v, --versionprint the version
-h, --helplist the commands and options

Watch mode

kerf build --watch rebuilds when the input folder or the config changes, and only rewrites files whose content changed. When a change has errors it prints them and keeps the last good build, so the site you're looking at doesn't break while you fix it. Outputs whose source you delete are removed.

[14:02:11] src/index.html changed
✗ src/index.html:12  pad 33 — not in space scale → nearest: 32 or 48

✗ 2 HTML files, 1 error — kept the last good build

AI coding agents

An agent writes better markup when the build tells it what's wrong. kerf init writes an AGENTS.md that tells coding agents to use s= and to run kerf check --json after every change, then fix what it reports. Each diagnostic has the file, line, rule and a suggestion to apply:

$ npx kerf check --json
{
  "ok": false,
  "command": "check",
  "errors": 1,
  "warnings": 0,
  "diagnostics": [
    {
      "file": "src/index.html",
      "line": 12,
      "rule": "syntax",
      "severity": "error",
      "message": "pad 13 — not in space scale",
      "suggestion": "nearest: 12 or 16"
    }
  ]
}

kerf build --json adds outDir, css and written. If the config can't be loaded, the object has "ok": false and an error message instead of diagnostics. Every rule is listed on Checks.

If your project already has an AGENTS.md, Kerf leaves it alone. A summary of Kerf for agents and chat assistants is at kerfcss.dev/llms.txt.

Vite

// vite.config.js
import { defineConfig } from "vite";
import kerf from "@kerfcss/kerf/vite";

export default defineConfig({
  plugins: [kerf()],
});

The plugin compiles s= in every HTML page and in JSX, TSX, Vue, Svelte and Astro components, and adds the stylesheet to each page. Your own .css files are checked too. In the dev server, problems show in the browser overlay and the stylesheet updates as you edit; in a build, errors fail it.

OptionDefaultWhat it does
configkerf.config.js or .mjsconfig file, relative to Vite's root
injecttrueadd the stylesheet link to pages; set false and import "virtual:kerf.css" yourself

Kerf runs before framework plugins on its own, so the order in plugins doesn't matter. Server templates (PHP, Blade, Twig) aren't served by Vite; build them with the CLI. Layouts and includes are a CLI feature too: in a Vite app, use your framework's components instead.

Next.js

In a Next.js app, npx kerf init writes a config whose input is your app folder, and a kerf-env.d.ts that adds the s attribute to React's types. Then wrap your Next config and put @kerf; where the stylesheet goes:

// next.config.ts
import type { NextConfig } from "next";
import withKerf from "@kerfcss/kerf/next";

const nextConfig: NextConfig = {};
export default withKerf(nextConfig);
/* app/globals.css */
@kerf;

It works with Turbopack and with webpack (next build --webpack), and needs no PostCSS config. s= compiles in server and client components alike. In next dev the stylesheet updates as you edit, and errors show in Next's overlay with the file, the line and the fix; in next build they stop the build. The rest of globals.css is your own CSS, checked like any other.

withKerf(nextConfig, { root, config }) takes the project folder and config file if they aren't where Next runs. npx kerf check checks the input folder, for CI: if your components live outside app, set input to a folder that holds them all, such as src. Only .jsx and .tsx files are compiled, so JSX in a .js file needs renaming.

Other tools: PostCSS

A tool that runs PostCSS but isn't Vite or Next.js can make the stylesheet with the PostCSS plugin and the same @kerf;. It reads s= in .html, .jsx and .tsx files under root (default: the folder it runs in) to know what's used, and checks each CSS file it processes. Rewriting s= to classes is still up to the CLI or a loader. Options: { root, config }.

// postcss.config.mjs
export default { plugins: { "@kerfcss/kerf/postcss": {} } };

Editor

The Kerf extension for VS Code shows the checks as you type, before you save or build:

  • Problems underlined where they are: off-scale values, contrast, tap targets, labels, names, and everything else kerf check reports. Unsaved changes are checked, and a partial is checked through the pages that include it.
  • One-click fixes: pad 13 to pad 12 or pad 16, a typo to the word it meant, a text colour that fails contrast to one that passes.
  • Completion in s=: words, scale values, colour roles with swatches, a component's variants and breakpoints, all from your config.
  • The CSS on hover: what an item becomes, exactly as a build writes it, and a role's light and dark colours.

Install Kerf from the Visual Studio Marketplace, or search for Kerf in the extensions view in VS Code. It runs your project's own Kerf (0.5.0 or later), so the editor reports exactly what your build does; after updating Kerf, run Kerf: Restart from the command palette.

In VS Code it covers HTML, PHP, JSX, Vue, Svelte, Astro and CSS, and Blade, Twig, Nunjucks, Liquid, ERB, EJS and Handlebars when an extension for that language is installed. Other editors: kerf lsp is a standard language server. Point any editor with LSP support (Neovim, Zed, Helix, Sublime Text) at npx kerf lsp for HTML, your template languages, JSX, Vue, Svelte, Astro and CSS.

-- Neovim 0.11+
vim.lsp.config("kerf", {
  cmd = { "npx", "kerf", "lsp" },
  filetypes = { "html", "php", "vue", "svelte", "astro", "javascriptreact", "typescriptreact", "css" },
  root_markers = { "kerf.config.js", "kerf.config.mjs" },
})
vim.lsp.enable("kerf")