Repo-wide Tailwind CSS v4 canonical class converter.
The CLI uses Tailwind's design system and canonicalizeCandidates(...) as its
source of truth. It can report non-canonical classes or rewrite supported static
class literals across a repository.
- Node.js 22.12 or newer at runtime.
- A Tailwind CSS entrypoint. The bundled Tailwind engine is pinned to 4.3.3 and is upgraded deliberately with regression tests.
bun add --dev canonical-tailwindRun the local binary with bunx canonical-tailwind or invoke the installed
canonical-tailwind executable from your package scripts.
Start with check or a dry run before writing files:
canonical-tailwind check . --css resources/css/app.css
canonical-tailwind fix . --css resources/css/app.css --dry-run
canonical-tailwind fix . --css resources/css/app.cssIf --css is omitted, the CLI searches the working directory. Autodetection
succeeds only when exactly one uncommented Tailwind entrypoint is found. An
ambiguous result fails and lists the candidates instead of guessing.
Both commands accept:
--css <file>: select the Tailwind CSS entrypoint explicitly.--collapse: canonicalize the whole list and collapse compatible utilities.--rem <number>: set the root font size; defaults to16.--jobs <number>: use 1 to 8 analysis workers; defaults to1.--json: print structured results to stdout.--verbose: include literals that were intentionally skipped.
fix additionally accepts --dry-run, which reports the exact changes without
writing files.
More workers are not automatically faster. Each worker loads an independent Tailwind design system and cache. Keep the default unless a representative benchmark of your repository proves that a larger value helps.
check:0when no replacements are needed,1when replacements exist.fix:0after a successful run, including a dry run.- Operational and validation failures:
2. - Command-line syntax errors reported by Commander:
1.
Successful --json output is written only to stdout. Errors are written to
stderr.
The scanner includes .vue, .html, .jsx, .tsx, .js, .ts, .svelte,
and .astro files.
Supported forms include:
- quoted
classandclassNameattributes inside markup tags; - string literals inside JSX
classandclassNameexpressions; - string literals inside Vue
:class,v-bind:class,:ui, andv-bind:ui; - Astro
class:liststring literals; - string literals passed to statically imported
clsx,cn,cva,tv, andtwMergebindings, including imported aliases.
Dynamic template literals are skipped. Svelte class:name directives are also
left unchanged because the utility is part of syntax rather than a safely
replaceable string literal. A same-named local or global helper without an
import is left unchanged; the scanner uses import evidence but does not perform
full semantic binding analysis.
Outside --collapse, existing whitespace between class tokens is preserved.
Collapse mode may reorder, combine, or normalize the whole class list.
- Built-in ignores cover Git metadata, dependencies, vendor files, generated builds, coverage, distributions, storage, and lockfiles.
- Rules from the working directory's root
.gitignoreare applied during directory scans; an explicitly selected file remains explicit. - Supported dot-directories such as
.storybookare scanned unless ignored. - Directory symlinks are not followed, and a symlink cannot be used as the target path.
fix analyzes every file successfully before it starts writing. Changed files
are prepared as temporary siblings and renamed into place, which prevents a
partial individual file and preserves its permission mode. A filesystem failure
during the final multi-file rename phase cannot be globally transactional, so
run the command in a clean version-controlled worktree.
bun install
bun run ts:check
bun test
bun run buildprepack rebuilds dist, so a package created from a clean checkout contains
the CLI, declarations, and source maps with embedded TypeScript sources.