# Getting started

> Run your first example in the browser or build the package for your own project.

## Try it in the browser

Open [Change the priority of queued work](/guides/reprioritize/) and click **Run**. The queue moves the layout task to the front when its priority changes, then returns it first.

## Install from source

Knotkit is preparing its first npm release. To use it in your project today, build a package tarball from a checkout. You’ll need Bun to build it and npm to pack it.

```bash
git clone https://github.com/jkomyno/knotkit.git
cd knotkit
bun install --frozen-lockfile
bun run build
npm pack ./packages
```

In your project, install the tarball using its absolute path. Use the filename printed by `npm pack`.

```bash
npm install /path/to/knotkit/knotkit-0.1.0.tgz
```

Knotkit is ESM only. With TypeScript, use 5.x or later and set `moduleResolution` to `"bundler"` or `"nodenext"`.

* [Node.js](#tab-panel-0-0)
* [Bun](#tab-panel-0-1)
* [Browsers](#tab-panel-0-2)

Node.js 22.12 or later.

Supported, and tested in CI.

Browsers with ES2024 support. Import the same module in your browser bundle and on the server.

## Import one module

Import the capability you need directly from a subpath such as `knotkit/heap`, `knotkit/bitset`, or `knotkit/sampling`. Your bundler can start from that subpath and include its dependencies.

```ts
import { minBinaryHeap, numberOrder } from 'knotkit/heap'

const heap = minBinaryHeap(numberOrder, [30, 1, 50, 20])

heap.peek() // 1
heap.pop() // 1
heap.size // 3
```

`minBinaryHeap` creates a heap, and `numberOrder` tells it how to compare numbers. Orderings, random sources, and hash functions are inputs to the operations that need them, so you can replay a workload with the same inputs.

Not sure which module you need?

[Choose a module](/choosing/) lists every task the modules solve. Search it for what you are trying to do.

## Handle errors

Use the exported error class and its `code` to handle a specific failure. Calling `pop()` on an empty heap raises `HeapInvalidInputError` with the code `EMPTY`.

```ts
import { HeapInvalidInputError, minBinaryHeap, numberOrder } from 'knotkit/heap'

const empty = minBinaryHeap(numberOrder)

try {
  empty.pop()
} catch (error) {
  if (!(error instanceof HeapInvalidInputError) || error.code !== 'EMPTY') {
    throw error
  }
  // Handle the empty heap.
}
```

Each module page lists its error codes. [Conventions](/conventions/) covers errors, layouts, and seeding in one place.

## Set up your coding agent

Paste this into Claude Code, Cursor, Codex, or any agent that can run commands:

Prompt · set up KnotkitCopy prompt

```
Set up Knotkit in this project.

1. Follow https://knotkit.jkomyno.dev/getting-started.md#install-from-source to build and install the package. Use "bundler" or "nodenext" module resolution in TypeScript.
2. Run `npx skills add jkomyno/knotkit --skill knotkit-select` to install the skill that picks a module for a task.
3. Add this to AGENTS.md (or CLAUDE.md):

   Knotkit: pick a module from node_modules/knotkit/capabilities.json, then read node_modules/knotkit/<name>/README.md. Import from 'knotkit/<name>'; there is no root import. Create structures with the exported factory functions, branch on error.code, and pass seeds and orderings explicitly.

If something is unclear, read https://knotkit.jkomyno.dev/llms.txt.
```

## Where to go next

* [Choose a module](/choosing/) when you know the task and want to find the right data structure.
* [Run a guide](/guides/) for a small example you can adapt to your project.
* [Read the module reference](/modules/) for operation costs, layout choices, and API signatures.
