---
title: "Write a plugin"
description: "Add a hook that tags browser crawl records."
canonical_url: "https://kitsune.carsxe.com/docs/concepts/plugins"
markdown_url: "https://kitsune.carsxe.com/docs/concepts/plugins.md"
last_updated: "2026-11-24"
x_farming_labs_generated_preamble: true
---

# Write a plugin
URL: /docs/concepts/plugins
LLM index: /llms.txt
Description: Add a hook that tags browser crawl records.

# Write a plugin

Plugins extend a session with named hooks. This example uses a `record` hook to tag the output for downstream processing.

## Writing one

Create `packages/kitsune/stamp.ts`:

```ts
import { definePlugin } from './src/index.ts'

export default definePlugin({
  name: 'example:stamp',
  record: (record) => ({
    ...record,
    meta: { ...record.meta, source: 'example' },
  }),
})
```

From the repository root:

```bash
bun run kitsune crawl https://example.com --selector a --plugin ./stamp.ts --json
```

Look for `"source":"example"` in the record’s `meta`. The CLI resolves `./stamp.ts` from `packages/kitsune`. The example uses `--selector` to open Chrome because `record` hooks run on browser and site plugin results.

## Loading one

Pass plugins to `Kitsune.launch({ plugins: [plugin] })` from TypeScript. With the CLI, repeat `--plugin` for each module or set `KITSUNE_PLUGINS` to a comma-separated list. Each module default-exports a plugin or a factory.

## Choose a hook

- Use `setup` and `close` for session resources.
- Use `response` to observe browser attempts and `record` to change the final browser or site plugin result.
- Use `site` when matching URLs need a custom crawl flow.

The [Plugin API](/docs/reference/plugin-api) lists each callback, its inputs, and when it runs.

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
