Skip to content
furl
Esc
↑↓navigate↵open⌘Jpreview

Create your own

Write a resolver for the URLs you care about

A plugin is a folder with a TypeScript entrypoint that default-exports definePlugin:

import { definePlugin } from 'furl-cli/plugins'

export default definePlugin({
  name: 'x',
  match: { hostname: 'x.com', path: '/*/status/*' },
  async resolve(ctx) {
    // ...
  },
})

Then register it in order so it runs.

The manifest

name

How the plugin is identified everywhere else

This is the id you write in order (as plugin:<name>) and under plugins in config.json, and it is also the plugin’s folder name under ~/.config/furl/plugins/. furl refuses to load a folder whose manifest name differs from the folder name. It must match ^[a-z0-9][a-z0-9_-]*$, so it can’t be * or start with default:.

match

Which URLs this plugin claims

A declarative hostname plus an optional path pattern. furl reads it to skip the plugin for URLs it doesn’t match — without executing any plugin code. Precedence comes from the plugin’s position in order.

When the pattern can't express it

match only decides whether your plugin is a candidate. For URL variants the pattern can’t capture, let it match and then decline at runtime inside resolve.

resolve

Turn the URL into markdown

resolve(ctx) receives ctx.url (a URL), ctx.config (your args from config.json), and ctx.decline(). It can return three things:

Return Meaning
{ markdown } Success — furl prints it and stops
null or ctx.decline() Not mine — silently move to the next resolver
throw Mine, but it failed — the chain continues, and the cause is reported only if every resolver fails

config

Optional: fields for the furl plugins form

Each field takes a key (letters, digits, _ and -), a type (string, secret, boolean, number, or enum), an optional label and description, required, and options for enum (a non-empty list of strings). furl rejects a plugin whose config doesn’t fit this shape.

furl doesn't validate this

The list drives the CLI form, nothing more. A field too complex for a single prompt can be left off the manifest — users hand-edit config.plugins[<id>] instead, and furl passes the whole object through untouched. Validating it is your plugin’s job.

Worked example: X posts

This plugin routes x.com posts through either the page’s embedded metadata (keyless) or the official X API (needs a key). It declares a mode enum defaulting to metadata, and a secret field used only when mode is api:

import { definePlugin } from 'furl-cli/plugins'

export default definePlugin({
  name: 'x',
  match: { hostname: 'x.com', path: '/*/status/*' },
  config: [
    {
      key: 'mode',
      type: 'enum',
      label: 'Resolution mode',
      options: ['metadata', 'api'],
      required: false, // defaults to 'metadata'
    },
    {
      key: 'apiKey',
      type: 'secret',
      label: 'X API key',
      required: false, // only needed for mode: 'api'
    },
  ],
  async resolve(ctx) {
    const mode = ctx.config.mode ?? 'metadata'

    if (mode === 'metadata') {
      const html = await fetch(ctx.url).then((r) => r.text())
      const tweet = parseTweetMetadata(html) // reads og:description etc.
      if (tweet === null) return ctx.decline()
      return { markdown: renderTweet(tweet) }
    }

    if (ctx.config.apiKey === undefined) {
      throw new Error('mode "api" requires apiKey — run `furl plugins` to set it')
    }

    const tweet = await fetchTweetFromApi(ctx.url, ctx.config.apiKey)
    return { markdown: renderTweet(tweet) }
  },
})

With plugins.x set to { "apiKey": "secret:x-api-key", "mode": "api" }, ctx.config.apiKey arrives as the real key — furl resolves secrets from the keychain before calling resolve.

Further reading

About the furl-cli/plugins import

It’s a real subpath export of the furl-cli package, and also a Bun virtual module the CLI intercepts at runtime — so a cloned plugin folder resolves it without an npm install.

For types, install furl-cli as a dev dependency in your plugin. Nothing else is needed, and it works under npm and pnpm alike:

npm install -D furl-cli
pnpm add -D furl-cli
yarn add -D furl-cli
bun add -D furl-cli
nub add -D furl-cli
aube add -D furl-cli

definePlugin is an identity function, so a plugin still runs without any of this.

Was this page helpful?