/brookmd:brookmdfrom brookmd
Renders streaming markdown from LLM token streams using a Rust→WASM core in a Web Worker. Supports React, Vue, Svelte, Solid, Web Components, Vercel AI SDK, SSE, SSR, math, syntax highlighting, and virtualized lists.
Ships in brookmd. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Streaming markdown for the browser. One Rust core (CommonMark 0.31 + GFM, byte-exact) compiled to WASM, run in a pooled Web Worker per stream, emitting patches over a versioned JSON wire. Parsing is off the main thread and re-parses only the active tail, so committed blocks never re-reconcile.
Zero runtime dependencies. react / vue / svelte / solid-js are optional
peers — you only need the one whose binding you import.
npm i brookmd
import "brookmd/styles.css"; // optional theme; skip it to bring your own CSS
Vite — one required line. Pre-bundling hoists the wasm-bindgen glue into
.vite/deps/, which breaks the relative WASM lookup (404 / "magic word"):
// vite.config.ts
export default defineConfig({ optimizeDeps: { exclude: ["brookmd"] } });
Next.js App Router needs no transpilePackages and no loader config, but the
component must be 'use client' (it uses hooks and spawns a Worker), and the
stream must be created in client code (a Response/ReadableStream is not
serializable across the RSC boundary).
From a stream — the component owns the client, pipes the stream, supersedes it if it changes, and cleans up on unmount:
import { BrookMarkdown } from "brookmd/react";
// stream: AsyncIterable<string> | ReadableStream<Uint8Array> | Response
<BrookMarkdown stream={stream} />;
From a growing string — the shape most React chat UIs already have:
import { BrookMarkdown, useBrookMarkdownString } from "brookmd/react";
const client = useBrookMarkdownString(text, { streaming });
<BrookMarkdown client={client} />;
setContent diffing is done for you: a prefix-extension appends only the delta,
a divergence resets and reparses.
Pass
streaming: falseonce the content is final. Omitted ortrueleaves the stream OPEN, so the last block never commits — a finished code fence never highlights and never shows its Copy button. brookmd deliberately refuses to infer "done" from an absent flag: doing so would re-finalize on every token for callers who grow the string without it, an O(n²) reparse trap.
These four parser flags default off but are what a chat app almost always wants, plus two client-side habits:
const CONFIG: ParserConfig = {
softBreaks: true, // a single \n becomes <br> — the chat convention models emit for
dirAuto: true, // per-block bidi, so an Arabic paragraph sits correctly beside an English one
a11y: true, // <label>-wrapped task checkboxes, scope="col" on table headers
blockData: true, // typed table/heading/code/math data → toolbars without an HTML re-parse
gfmMath: true, // $…$ / $$…$$ → KaTeX-ready markup (off by default so `$` in prose stays literal)
};
// 1. HOIST the components map (and decorators / urlTransform / sanitize) to module
// scope. A fresh identity each render busts the per-block memo, so every
// committed block re-renders on every patch.
const COMPONENTS: Components = { /* … */ };
// 2. Warm the pool on route entry so WASM init is off the first-token path.
useEffect(() => { getDefaultPool().warm(); }, []);
<BrookMarkdown> props| Prop | Type | Default | Meaning |
|---|---|---|---|
client / stream | BrookClient / AsyncIterable<string> | ReadableStream<Uint8Array> | Response | — | Exactly one is required; client wins. |
streamConfig | ParserConfig | — | Config for the internally created client (stream mode). |
components | Components | — | Overrides. Two prop contracts — see below. |
sanitize | (html: string) => string | — | Runs before every injection including the open tail. |
decorators | Decorator[] | — | Inline TEXT-node matcher. Output is trusted. |
urlTransform | UrlTransform | — | Rewrites href/src/poster; output is re-sanitized. |
onLinkClick | (event, { href, text, element }) => void | — | Since 0.30.0. One delegated listener on the root; preventDefault() cancels. |
virtualize | boolean | false | content-visibility: auto on closed blocks. |
stickToBottom | boolean | false | Emits a snap sentinel; you add scroll-snap-type: y proximity. |
streamingHighlight | boolean | "wavefront" | "eager" | "wavefront" | Highlight an open fence. |
className, id, role, aria-live, aria-atomic | — | Land on the .brook-md root. | |
onBlockError | (error, info) => void | — | Per-block error boundary hook. |
onStreamError | (err) => void | — | Pipe errors; worker fatals carry err.fatal. |
onRenderMetrics | RenderMetricsHook | — | Fires per ACTUAL block render. |
childMemo, deferTail | boolean | false | Open-block child reuse / useDeferredValue routing. |
ParserConfig — real defaults| Field | Default | Field | Default | |
|---|---|---|---|---|
gfmAutolinks | true | unsafeHtml | false | |
gfmAlerts | true | componentTags | off | |
gfmTagfilter | false | inlineComponentTags | off | |
gfmFootnotes | false | htmlAllowlist | unset = off | |
gfmMath | false | dropHtmlTags | unset = off | |
dirAuto | false | blockHtml | false | |
lenientLists | false | allowSchemes | [] | |
softBreaks | false | blockData | false | |
a11y | false | retainCommittedHtml | false (worker path) |
Config is applied once when the stream's parser is created and is immutable
for that stream's lifetime — reset() keeps it; use a new client for different
flags. streamingHighlight is a renderer option, not part of ParserConfig.
import { BrookMarkdown } from "brookmd/react"; // <BrookMarkdown stream={s} />
import { mountBrookMarkdown } from "brookmd/dom"; // mountBrookMarkdown(client, el, opts)
import { defineBrookMarkdown } from "brookmd/element"; // <brook-markdown src="…" gfm-math>
import { BrookMarkdown } from "brookmd/vue"; // <BrookMarkdown :client="client" />
import { brookMarkdown } from "brookmd/svelte"; // <div use:brookMarkdown={{ client }} />
import { BrookMarkdown } from "brookmd/solid"; // <BrookMarkdown client={client} />
import { renderToString } from "brookmd/server"; // sync, worker-free, React-free
import { BrookMarkdownStatic } from "brookmd/server/react"; // hookless, RSC-safe
On React Native use the brookmd-react-native package instead — the same
Rust core over JSI, no Web Worker.
components has two prop contracts. A capitalized block-kind key gets
BlockComponentProps (with block); a lowercase tag key gets the element's
attributes and children only — no block prop. A name reachable from
both must guard: block ? … : …. Reading props.block unconditionally
yields can't access property "kind", block is undefined.components,
decorators, urlTransform, sanitize, onBlockError — a fresh identity
re-renders every committed block on every patch. (onLinkClick is exempt: it
is delegated to the root.)done() — it is finalize(). And beginResume is private.brook-md (hyphenated); className is appended to it.stickToBottom is CSS-only — you must add scroll-snap-type: y proximity
to your scroll container..brook-md with no console output = the worker never booted (often
a stale hashed URL after a deploy). Watch client.failed / onError;
recovery (default true) heals the first death invisibly, the second is fatal.brookmd/styles.css was not imported..brook-open / .brook-streaming,
or props.open) — a half-typed formula or diagram throws on every patch.optimizeDeps.exclude; nothing else does.'use client', and build the stream client-side.getDefaultPool() is browser-only and a per-page singleton; don't rely
on it in SSR/RSC.BrookMarkdownStatic and hydrate with BrookMarkdown — use
the same component on both sides.<BrookMarkdown> prop, BrookClient methods and options, full ParserConfig,
the components two-contract rules, BlockComponentProps and the per-kind
blockData shapes, the server API.useBrookStream), Vue, Svelte, Solid, the Web Component's attributes and
properties, vanilla mountBrookMarkdown + MountHandle, brookmd/server,
Next.js, Vite, webpack/Rollup/Parcel, plain ESM, React Native, CSP.styles.css, the --brook-*
variables, dark mode, the brook-block / brook-open / brook-speculative /
brook-streaming class contract, the opt-in caret, code-block chrome, Tailwind
(and why prose users should skip the theme import).allowSchemes, raw-HTML tiers, the sanitize hook,
trusted surfaces, onLinkClick interstitials.useChat,
KaTeX, Mermaid, Shiki, registerLanguage, a CSV table toolbar off blockData,
interactive checkboxes, lazy images, accessible chat, persist/hydrate,
getMetrics().basic-stream.tsx,
ai-sdk-chat.tsx, full-featured.tsx, vanilla-dom.ts, web-component.html,
server-render.ts, nextjs-app-router.tsx. All typechecked.assets/examples/ai-sdk-chat.tsx (opens in a new tab)assets/examples/basic-stream.tsx (opens in a new tab)assets/examples/full-featured.tsx (opens in a new tab)assets/examples/nextjs-app-router.tsx (opens in a new tab)assets/examples/server-render.ts (opens in a new tab)assets/examples/shims.d.ts (opens in a new tab)assets/examples/tsconfig.json (opens in a new tab)assets/examples/vanilla-dom.ts (opens in a new tab)assets/examples/web-component.html (opens in a new tab)references/api.md (opens in a new tab)references/frameworks.md (opens in a new tab)references/recipes.md (opens in a new tab)references/security.md (opens in a new tab)references/styling.md (opens in a new tab)references/troubleshooting.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub siinghd/brookmd --plugin brookmdOther plugins' skills for the same job