Skip to content

Derived documentation

Discover, preview, and install reusable source code with the Derived CLI.

Derived brings reusable source code into your project. Use the CLI yourself or let your coding agent inspect registries, preview changes, and install a starting point for your next feature.

A block is a registry item: source files, metadata, optional dependencies, and optional integration instructions. The installed code lives in your repository so you can customize it.

Quickstart

This self-contained example creates a local registry and installs a tiny TypeScript utility. It does not need an account, an external block catalog, or an existing app. You need Node.js and npm; run the commands in a terminal from a new working directory.

1. Create the source

mkdir derived-example
cd derived-example
mkdir registry

Create registry/greeting.ts:

export function greeting(name: string): string {
  return `Hello, ${name}!`;
}

Create registry.json in derived-example:

{
  "name": "local-example",
  "items": [
    {
      "name": "greeting",
      "type": "registry:file",
      "title": "Greeting utility",
      "description": "A small local example for learning the install workflow.",
      "files": [
        {
          "path": "registry/greeting.ts",
          "type": "registry:file",
          "target": "src/greeting.ts"
        }
      ]
    }
  ]
}

The item name greeting belongs to the local example you just created. It is not a pre-existing public block.

2. Inspect and preview

npx derived-cli@latest registry validate
npx derived-cli@latest view greeting
npx derived-cli@latest add greeting --diff

view inspects the item. add --diff shows the proposed file changes without writing to your project. You can also use --dry-run for an install plan or --view to preview generated file contents.

3. Install

npx derived-cli@latest add greeting

Review the confirmation in an interactive terminal. The CLI creates src/greeting.ts and records installation history in .derived/blocks.json. Open the generated file, change it, and commit it when you are ready.

This example has no package dependencies. Other blocks may install npm packages or declare additional setup steps. Inspect the plan before installing; custom setup commands require confirmation or --allow-setup-commands.

Explore registries

List and search the local registry from the example above.

npx derived-cli@latest list .
npx derived-cli@latest search --registry . --query greeting
npx derived-cli@latest view greeting

You can also use local manifests, hosted catalogs, built item JSON, and public GitHub source registries. The following addresses are placeholders—replace them with your own registry:

npx derived-cli@latest list owner/repository
npx derived-cli@latest view item-name --registry ./my-registry
npx derived-cli@latest add item-name --registry https://registry.example.com/registry.json --diff
npx derived-cli@latest add owner/repository/item-name#v1.2.0 --diff

Without an explicit --registry, local discovery walks upward from the working directory to find the nearest registry.json. Use --cwd to choose the destination project and --registry to make the source explicit.

Customize with template data

Derived uses Handlebars for templated registry files. An item with a data object renders expressions in file contents and target paths; ordinary files remain literal code. Files can explicitly set template: true or template: false.

For example, change the local greeting source to a file named registry/greeting.ts.hbs:

export function
{{camelCase functionName}}(name: string): string { return `Hello, ${name}!`; }

Update the item in registry.json to include "data": { "functionName": "greeting" }, and change its source path to registry/greeting.ts.hbs. Keep the target as src/greeting.ts.

Create data.json:

{
  "functionName": "welcomeCustomer"
}

Preview the customized source:

npx derived-cli@latest add greeting --data-file data.json --force --diff

--data-file replaces the default data object. --force lets you plan or reinstall an item already recorded locally; it does not itself authorize overwriting existing files. Review file conflicts when you install. Use --overwrite only when you intend to replace those files.

Templates can use helpers such as camelCase, kebabCase, and snakeCase, as well as Handlebars loops and conditionals. Registry items may also declare explicit modifications to existing files, so always inspect the plan.

Work with your coding agent

An agent that can run terminal commands can use Derived directly. Start by giving it an explicit registry and a reviewable task:

Search our registry for a suitable block. Inspect its files and dependencies, then show me the install plan. After installation, follow its integration instructions and run the relevant project checks.

For the local quickstart, the discovery and preview sequence is:

npx derived-cli@latest list . --json
npx derived-cli@latest view greeting --json
npx derived-cli@latest add greeting --dry-run --json

After reviewing the plan, an agent can run:

npx derived-cli@latest add greeting --yes --json

Use --json when parsing responses. Non-interactive execution also emits a structured JSON envelope. For other projects, set --cwd and --registry explicitly so the destination and source are unambiguous.

Blocks may provide aiInstructions: integration guidance returned after installation. The CLI displays these instructions; it does not execute them. Your agent handles the application-specific wiring and testing. Derived does not automatically prove a block is compatible, secure, or correct for your application.

Private registries

Configure a named registry in derived.json at your project root. This is a placeholder configuration for your own hosted registry:

{
  "registries": {
    "@team": {
      "url": "https://registry.example.com/r/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TEAM_REGISTRY_TOKEN}"
      }
    }
  }
}

Supply TEAM_REGISTRY_TOKEN through your shell or secret manager. Keep credential values out of committed files. Header values are resolved from the current process environment.

npx derived-cli@latest list @team
npx derived-cli@latest view @team/item-name
npx derived-cli@latest add @team/item-name --diff

The host must serve the appropriate catalog and item JSON. Authenticated URLs use HTTPS, except for localhost development. Hosted and public GitHub sources are fetched directly; a registry namespace is an address, not a guarantee of code quality.

Build and share a registry

Keep your manifest and source files together. Validate the registry, then build self-contained item JSON:

npx derived-cli@latest registry validate
npx derived-cli@latest registry build

The default build output is public/r. Host that directory to serve your registry. The build embeds source into item JSON, while the catalog lists items and their metadata.

Use registryDependencies to compose items and dependencies / devDependencies for npm packages. Complete project starters can use registry:base and be installed with init into an empty destination (an existing .git directory is allowed).

Command reference

CommandPurpose
registryConfigure, inspect, validate, and build registries
list <registries...>List items from explicit registry sources
searchSearch registry catalogs
view <item>Inspect an item before installation
add <items...>Plan and install one or more items
init <base>Initialize an empty project from a registry:base item

Useful add options:

OptionBehavior
--registry <source>Select a registry namespace, URL, directory, or manifest
--cwd <directory>Choose the destination project
--dry-runPreview the plan without writing project files
--diff [path]Preview before and after contents without writing
--view [path]Preview generated file contents without writing
--data-file <path>Replace template data with a JSON file
--jsonEmit a structured response for automation
--yesSkip the installation confirmation
--forceAllow reinstalling an item recorded locally
--overwriteAuthorize overwriting existing files
--allow-setup-commandsAllow declared setup commands to execute

Run npx derived-cli@latest --help or append --help to a command for the full options. Once the block is installed, review the diff in your repository and run your application's normal checks.

On this page