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
Create registry/greeting.ts:
Create registry.json in derived-example:
The item name greeting belongs to the local example you just created. It is not a pre-existing public block.
2. Inspect and preview
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
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.
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:
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:
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:
Preview the customized source:
--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:
After reviewing the plan, an agent can run:
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:
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.
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:
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
| Command | Purpose |
|---|---|
registry | Configure, inspect, validate, and build registries |
list <registries...> | List items from explicit registry sources |
search | Search 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:
| Option | Behavior |
|---|---|
--registry <source> | Select a registry namespace, URL, directory, or manifest |
--cwd <directory> | Choose the destination project |
--dry-run | Preview 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 |
--json | Emit a structured response for automation |
--yes | Skip the installation confirmation |
--force | Allow reinstalling an item recorded locally |
--overwrite | Authorize overwriting existing files |
--allow-setup-commands | Allow 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.