aidenybai/cnfast

25× faster drop-in replacement for `cn`

TypeScript

1,179

132 commits

updated Sep 1, 2026

See the code

README

[!NOTE] Check out cn by shadcn for an even faster cn package. cnfast will no longer be maintained in favor of cn. I recommend you go use that package instead!

cnfast

version downloads

Fast drop-in replacement for tailwind-merge + clsx.

cnfast runs 25× faster than tailwind-merge + clsx across 58 real-world repositories, with byte-identical output. Same API, no code changes.

import { cn } from "cnfast";

cn("px-2 py-1", isActive && "px-4", { "text-red-500": hasError });
// "py-1 px-4 text-red-500"

Install

npm install cnfast

Migrate an existing clsx, classnames, or tailwind-merge project in one command:

npx cnfast migrate

On a shadcn/ui project, add or replace your cn utility through the registry. This rewrites lib/utils.ts to re-export cnfast and installs the package:

npx shadcn@latest add aidenybai/cnfast/cn

Usage

Swap the shadcn/ui cn helper for cnfast:

// before
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));

// after
export { cn } from "cnfast";

cnfast also exports clsx, twMerge, and twJoin.

Development

ni
nr build
nr test

License

MIT

clsx
cn
tailwindcss

aidenybai/cnfast

25× faster drop-in replacement for `cn`

TypeScript

1,179

132 commits

updated Sep 1, 2026

See the code

README

[!NOTE] Check out cn by shadcn for an even faster cn package. cnfast will no longer be maintained in favor of cn. I recommend you go use that package instead!

cnfast

version downloads

Fast drop-in replacement for tailwind-merge + clsx.

cnfast runs 25× faster than tailwind-merge + clsx across 58 real-world repositories, with byte-identical output. Same API, no code changes.

import { cn } from "cnfast";

cn("px-2 py-1", isActive && "px-4", { "text-red-500": hasError });
// "py-1 px-4 text-red-500"

Install

npm install cnfast

Migrate an existing clsx, classnames, or tailwind-merge project in one command:

npx cnfast migrate

On a shadcn/ui project, add or replace your cn utility through the registry. This rewrites lib/utils.ts to re-export cnfast and installs the package:

npx shadcn@latest add aidenybai/cnfast/cn

Usage

Swap the shadcn/ui cn helper for cnfast:

// before
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));

// after
export { cn } from "cnfast";

cnfast also exports clsx, twMerge, and twJoin.

Development

ni
nr build
nr test

License

MIT

clsx
cn
tailwindcss

Project health

Latest release

0.2.0 · Sep 1, 2026

Releases this year

9

Significant stargazers

(top 24 of 37)

Tommy D. Rossi

1,152 followers · starred Jun 2026

Karl Horky

973 followers · starred Jun 2026

Sora Morimoto

959 followers · starred Jun 2026

Andrey Okonetchnikov

1,089 followers · starred Jun 2026