---
title: "Extension authoring overview"
description: "Create an extension on a branch, test each commit's version there, and release it by merging to main."
---

> Documentation Index
> Fetch the complete documentation index at: https://buildrforge.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Extension authoring overview

An extension's definition, schema, tag families, and source files live inside a repo's commit DAG. Every commit that changes an extension publishes it to the organization's registry: you develop on a branch, where each commit publishes a prerelease that only your repo runs, and merging a version bump to `main` publishes a release that other repos install.

Authoring takes actions that the default Editor policy doesn't grant: `create`, `update`, `delete`, and `publish` on the extension, the schema actions for its custom models, and `call` on its tools to try them. See [Actions](https://buildrforge.com/docs/permissions/actions/#extension-source). Org owners and the default Admin policy have them all. Anyone else gets `Forbidden` at the first step until an org policy allows them.

## The authoring lifecycle

Follow these steps to take an extension from creation to a release. Work on a branch: a commit on `main` that raises the version releases it to every repo in the org, so start on `main` only to change an extension that you mean to release with that commit.

1. **Create a branch, and the extension on it**: Create a branch from `main` with `POST /repos/:repo_id/branches` (`forge branches create-branch`), then call `POST /repos/:repo_id/branches/:branch/extensions` (`forge extensions create-extension`). A created extension starts at version `1.0.0` unless you pass an initial `version`, with a `package.json` that declares the stage's latest `@buildr/sdk`.
2. **Add schema, tag families, or source files**: Create extension-owned custom models and tag families, or upload TypeScript source files starting at `index.ts` with `POST /repos/:repo_id/branches/:branch/extensions/:name/files` (`forge extensions create-extension-file`). Edit the extension's `package.json` to add npm packages, and keep its `@buildr/sdk` entry, as [How `@buildr/sdk` is linked and upgraded](#how-buildrsdk-is-linked-and-upgraded) shows.
3. **Commit, then check the publication**: Save your working state with `forge commits create-commit`. The commit publishes the extension in the background: Forge validates its schema, compiles its source files, inspects its declared tools, schedules, triggers, webhooks, mailboxes, workflows, MCP UIs, and requirements in a sandbox, and only then records the version in the org's registry. List the commit's publications with `GET /repos/:repo_id/commits/:commit_id/extension-publications` (`forge extensions list-commit-extension-publications --commit "$COMMIT"`): each is `queued`, `published`, or `failed` with the refusal that says why, such as `ExtensionBuildFailed`. Then list and call the extension's tools on the branch with `GET` and `POST /repos/:repo_id/branches/:branch/extensions/:name/tools...` (`forge extensions list-extension-tools` and `forge extensions call-extension-tool`). Branch calls run the version that the branch's head commit publishes, never its uncommitted edits, so commit each edit before you try it. A call made while that version is still publishing answers `ExtensionPublicationPending`. Retry it shortly. An extension that no commit holds yet answers `ExtensionNotFound`.
4. **Test it**: Seed a scratch branch with the data its tools need, and call each tool, run each workflow, and open each page against it. See [Testing an extension](https://buildrforge.com/docs/extensions/testing/).
5. **Raise the version to release**: A commit that brings `main` a version higher than the extension's latest release publishes that release, which other repos install. Every other commit publishes a prerelease, `MAJOR.MINOR.PATCH-pre.<commit>`, that only your repo runs. While the extension's version is no higher than its latest release, a prerelease numbers the patch after that release, so once `1.0.0` is released, a branch whose extension still says `1.0.0` publishes `1.0.1-pre.<commit>`. To release a change to a released extension, update its version on the branch with `PATCH /repos/:repo_id/branches/:branch/extensions/:name` (`forge extensions update-extension --data '{"version":"1.1.0"}'`) and commit. An extension's first version on `main` is its first release.
6. **Merge to `main`**: Open and merge a change request into `main`. A change request merges only once every extension version at its head has published (`ExtensionPublicationGateFailed` otherwise). A version whose publication failed never publishes, so fix it with another commit on the branch before you merge. An extension the branch never changed is judged by `main`'s head instead, so a branch cut while `main`'s release had failed merges once `main` is fixed. The merge publishes the release, and deletes the branch it merged, so create a new branch from `main` for the next change.

A version whose publication fails is never recorded in the registry, on a branch or on `main`. On `main`, the next commit that changes the extension publishes the same version again, so `main` releases a version only once its publication succeeds.

## Walkthrough with the CLI

The following commands create a `directory` extension with an `index.ts` file on a branch, try its tool there, and merge it to `main`, which releases version `1.0.0`. They use the [`forge` CLI](https://buildrforge.com/docs/introduction/api-mcp-and-cli/#the-forge-cli), signed in, with the repo's ID in `$REPO`:

```sh
# 1. Create a branch from main, and declare the extension on it
MAIN=$(forge branches get-branch --repo "$REPO" --branch main | jq -r .id)
forge branches create-branch --repo "$REPO" --data '{"name":"directory","base_branch_id":"'"$MAIN"'"}'
forge extensions create-extension --repo "$REPO" --branch directory \
  --data '{"name":"directory","description":"Company lookup tools"}'

# 2. Write index.ts and upload it as an extension file
cat << 'EOF' > index.ts
import { array, defineExtension, object, string, tool } from "@buildr/sdk";

export default defineExtension(
  {},
  {
    tools: {
      companies: {
        search: tool(
          {
            description: "Finds companies whose name matches the query",
            input: object({ query: string() }),
            output: array(string()),
          },
          async (_ctx, { query }) =>
            ["Acme Cloud", "Beacon Analytics"].filter((name) =>
              name.toLowerCase().includes(query.toLowerCase()),
            ),
        ),
      },
    },
  },
);
EOF

jq -Rs '{path: "index.ts", content: .}' index.ts > index.json
forge extensions create-extension-file --repo "$REPO" --branch directory --name directory --data-file index.json

# 3. Commit the branch, which publishes a prerelease, and capture the commit ID
COMMIT=$(forge commits create-commit --repo "$REPO" --branch directory \
  --data '{"message":"Add directory extension"}' | jq -r .id)

# 4. Check the commit's publication. Once it's published, a few seconds later,
#    try the tool at the branch's head commit
forge extensions list-commit-extension-publications --repo "$REPO" --commit "$COMMIT"
forge extensions list-extension-tools --repo "$REPO" --branch directory --name directory
forge extensions call-extension-tool --repo "$REPO" --branch directory --name directory \
  --tool companies.search --data '{"query":"analytics"}'

# 5. Merge the branch to main, which releases 1.0.0
CR=$(forge change-requests create-change-request --repo "$REPO" \
  --data '{"branch":"directory","base_branch":"main","title":"Directory extension"}' | jq -r .number)
forge change-requests merge-change-request --repo "$REPO" --number "$CR" --data '{}'
```

A commit that leaves an extension as the commit before it held it publishes nothing, and runs the version that the earlier commit published.

## Extension file management

An extension's files are versioned records in the repo's DAG. Each file has a `path` relative to the extension root (such as `index.ts`, `lib/companies.ts`, `package.json`, or `ui/web/index.html`) and UTF-8 `content`:

- **Create a file**: `POST /repos/:repo_id/branches/:branch/extensions/:name/files` (`forge extensions create-extension-file`). Adding a second file at a path that another file on the branch already holds fails with `WriteRefused`.
- **Update or move a file**: `PATCH /repos/:repo_id/branches/:branch/extensions/:name/files/:file_id` (`forge extensions update-extension-file --file "$FILE_ID"`) accepts updated `content`, a different `path`, or both.
- **Delete a file**: `DELETE /repos/:repo_id/branches/:branch/extensions/:name/files/:file_id` (`forge extensions delete-extension-file --file "$FILE_ID"`).
- **Sync a folder of files**: `PUT /repos/:repo_id/branches/:branch/extensions/:name/files` (`forge extensions update-extension-files`, or the MCP server's `sync_extension_files`) takes `{"files": [{"path": "...", "content": "..."}], "delete": true}` (or `attachment_blob_id` in place of `content` for a binary file) and writes every file in one operation. With `"delete": true`, files omitted from `files` are deleted so the extension matches your local folder; without it, omitted files stay. One refused file refuses the whole write.
- **List files**: `GET /repos/:repo_id/branches/:branch/extensions/:name/files` or `GET /repos/:repo_id/commits/:commit_id/extensions/:name/files` (`forge extensions list-extension-files`) answers each file's `id`, `path`, and size in UTF-8 `bytes`, without its content.
- **Read a file**: `GET /repos/:repo_id/branches/:branch/extensions/:name/files/:file_id`, or the same under `/commits/:commit_id` (`forge extensions get-extension-file --file "$FILE_ID"`), answers one file with its `content`.
- **Read many files**: `POST /repos/:repo_id/branches/:branch/extensions/:name/files/search`, or the same under `/commits/:commit_id`, takes `{"ids": [...]}` and answers `{"data": [...], "next_cursor": ...}`: the files with their content, in id order, about 2 MiB of content a page. Send the same ids with `"cursor"` set to each page's `next_cursor` until it is null. `forge extensions read-files` reads every page, of every file unless `--file` names some.

Forge formats a TypeScript, JavaScript, or JSON file of up to 256 KiB with Prettier once a read first asks for its content, and later reads answer the result beside it as `formatted_content`, which the site shows. `content` stays exactly as you wrote it, and builds read only `content`, so edit and diff `content`. `formatted_content` is null until the file is formatted, while `formatting_pending` is true, and stays null when the file is already formatted, is larger or in another language, or doesn't parse.

## Agent instructions and skills

An extension can carry agent instructions and agent skills for the agents that work in its repo and in the repos that install it. They're data in the repo's DAG, owned by the extension the way its tag families are, not files:

- **Agent instructions**: `POST /repos/:repo_id/branches/:branch/extensions/:extension_name/agent-instructions` with `{"content": "..."}` (`forge agent-instructions create-extension-agent-instructions`) creates the extension's `AGENTS.md`. An extension holds one.
- **Agent skills**: `POST /repos/:repo_id/branches/:branch/extensions/:extension_name/agent-skills` with `{"name": "..."}` (`forge agent-skills create-extension-agent-skill`) creates a skill in the [Agent Skills](https://agentskills.io/specification) layout. Add each of its files with `POST /repos/:repo_id/branches/:branch/agent-skills/:skill_id/files` and `{"path": "...", "content": "..."}` (`forge agent-skills create-agent-skill-file`). Its `SKILL.md` starts with frontmatter that gives the skill's `name` and a `description` of when to use it. A `SKILL.md` without readable frontmatter fails with `InvalidAgentSkillFile`, and a commit fails with an `agent_skill` violation while a skill has no `SKILL.md` that gives its name.

Edit either one as you edit the repo's own, with `forge agent-instructions update-agent-instructions`, `forge agent-skills update-agent-skill`, and `forge agent-skills update-agent-skill-file`.

Installing or updating an extension copies the instructions and skills of the version the repo pins. The installing repo can edit its copies. An update that meets a skill that both the repo and the version changed reports a conflict, and the resolution keeps all of the repo's files or takes all of the version's. A repo's agents read every owner's instructions and skills with `GET /repos/:repo_id/branches/:branch/agent-instructions` (`forge agent-instructions list-agent-instructions`) and `GET /repos/:repo_id/branches/:branch/agent-skills` (`forge agent-skills list-agent-skills`): the repo's own, those of the extensions it defines, and the copies of the extensions it installs.

## How `@buildr/sdk` is linked and upgraded

Extension code imports `defineExtension`, `tool`, `workflow`, `cron`, `onBranchAdvance`, `branchAdvance`, `webhook`, `mailbox`, `room`, `mcpUi`, `defineProvider`, `secrets`, `oauth2`, `ForgeError`, and value types from `"@buildr/sdk"`. Server code can also import `"@buildr/sdk/mcp"`, a web UI imports `"@buildr/sdk/client"`, and an MCP UI imports `"@buildr/sdk/mcp-ui"`.

`@buildr/sdk` is an npm package with type declarations for each of its modules. Every Forge stage serves its own copy from the org's registry, and it isn't on public npm. A new extension's `package.json` declares a caret range on the stage's latest version, and you edit it like any other package's. `npm view @buildr/sdk version`, against the registry in your `.npmrc`, names the latest.

- **Keep it in every extension with code**: The build refuses code without a `package.json` that declares `@buildr/sdk`, with `SourceRefused`. Give a version or a range, which an installation checks against the SDK it links. A tag such as `latest` or an `npm:` alias is refused.
- **The lockfile pins it**: The build resolves `@buildr/sdk` from the stage's registry like any npm package, links the version that npm resolves, and records that version. Every run of the version loads that SDK, so a Forge deploy doesn't change how a published version builds or runs.
- **Upgrade by editing `package.json`**: To move an extension onto a later SDK, raise its range in `package.json` on a branch, raise the extension's version, and merge it to `main` to release it. Nothing else pins the SDK.
- **A peer runs with its dependent's SDK**: An installation links one SDK, the version that the installed extension's lockfile pins, and its peers' code runs with it. Installing an extension whose peer declares a range on `@buildr/sdk` that excludes that version fails with `ExtensionBuildFailed`.

### Developing in a local folder

The API serves `@buildr/sdk` to npm at `/npm/` (`https://api.onforge.com/npm/` in production), beside every org's released extensions, so you can edit an extension in a local folder and check it with `tsc` before pushing its files back:

1. **Pull the extension's files**: Run `forge extensions read-files --repo "$REPO" --branch "$BRANCH" --name "$EXT"` (which returns the branch's file records as JSON, including the `package.json` that creating the extension wrote). Write each text file's `content` to its `path` in the folder, and keep any binary file's `{ path, attachment_blob_id }` to include in step 4's sync payload.
2. **Create an npm token** with `POST /orgs/:org_id/npm-tokens` (`forge registry create-npm-token --org "$ORG"`, or the MCP server's `create_npm_token`, which returns `npmrc`), valid for 24 hours, and point both `@buildr` and `@buildr-custom` at the `registry` it returns in `.npmrc` (with `ignore-scripts=true`, matching Forge's compiler):

   ```ini
   ignore-scripts=true
   @buildr-custom:registry=https://api.onforge.com/npm/
   @buildr:registry=https://api.onforge.com/npm/
   //api.onforge.com/npm/:_authToken=<token>
   ```

3. **Install dependencies and configure TypeScript**: Run `npm install` and `npm install --save-dev typescript` (plus `@types/node` if your code imports `node:*` built-ins; `devDependencies` are ignored by the build), write a `tsconfig.json`, and check your code with `npx tsc`:

   ```json
   {
     "compilerOptions": {
       "target": "es2022",
       "lib": ["es2022", "dom"],
       "module": "preserve",
       "moduleResolution": "bundler",
       "jsx": "react-jsx",
       "strict": true,
       "noEmit": true,
       "allowImportingTsExtensions": true,
       "skipLibCheck": true
     },
     "exclude": ["node_modules"]
   }
   ```

4. **Sync and commit**: Push the folder (excluding `node_modules`, `package-lock.json`, and dotfiles such as `.npmrc`) to your branch with `forge extensions update-extension-files` or MCP's `sync_extension_files` (`"delete": true`), then commit with `forge commits create-commit`.

Source: https://buildrforge.com/docs/extensions/authoring-overview/index.mdx
