An extension can include a browser application alongside its schema and tools. When an extension contains ui/web/index.html, its UI can be served at a dedicated, isolated web origin outside the main Forge dashboard: from the version that a branch of the repo that defines it publishes, or from the release a repo installs on main.
File layout for an extension UI
An extension with a UI still requires an index.ts at the root of the extension (even if it exports defineExtension({}, { tools: {} })), plus ui/web/index.html:
index.ts # Sandbox entrypoint (defineExtension)
package.json # Optional npm dependencies for both sandbox and UI
shared/
format.ts # Pure helper modules shared by sandbox and UI
ui/
web/
index.html # Single HTML document for the UI
main.tsx # Browser module entrypoint(s), TypeScript or React JSX, which may import Elm
styles.css # Stylesheets bundled for the browser
public/
logo.svg # Static files served verbatim at the UI root (/logo.svg)ui/ holds every UI surface an extension has: the browser UI is ui/web/, and the MCP UIs that agents show in chat are under ui/mcp/. A file under ui/ but outside ui/web/ is not part of the browser UI: the page can’t load it, and the UI never serves it. In particular, an extension whose only page is ui/index.html has no UI.
How ui/web/index.html is compiled
During the compile stage, the compiler parses ui/web/index.html and builds every local script and stylesheet for the browser using esbuild:
- Module scripts (
ui/web/*): Every<script type="module" src="./main.tsx"></script>that points to a file insideui/web/(outsideui/web/public/) is bundled for the browser withtarget: "es2022",minify: true, and React automatic JSX (.tsxand.jsx). esbuild strips TypeScript’s types without checking them, so a type error still builds. The compiled JavaScript holds at most 2 MiB. The build keeps a source map of each script beside it, which Forge reads to place a branch page’s errors in your files and never serves. Any CSS imported by a script (such asimport "./cards.css") is also bundled and linked into the HTML page automatically. - Stylesheets (
ui/web/*): Every<link rel="stylesheet" href="./styles.css">pointing insideui/web/is bundled and rewritten to its content-hashed path under/assets/<name>-<hash>.css. - Static public files (
ui/web/public/*): Files placed underui/web/public/are served unmodified from the root of the UI origin (for example,ui/web/public/favicon.svgis served at/favicon.svg). No file underui/web/public/may be placed underui/web/public/assets/, which is reserved for compiled bundles. Every public file’s name needs a dot, such asLICENSE.txtrather thanLICENSE: the UI serves its page at any path whose last segment has none (see client-side routing below), so it could never serve the file, and the build fails withCompileFailed. Aui/web/public/index.htmlfails the build withCompileFailed, becauseui/web/index.htmltakes that path. - Binary files: Images, fonts, and WebAssembly modules are binary files. Upload the bytes with
createRepoAttachmentBlob, then create the file with itsattachment_blob_idin place ofcontent. A script can import a binary file (import wasmUrl from "./app.wasm") to get the URL of its content-hashed copy under/assets/, and a binary file underui/web/public/is served unmodified like any other public file. Pages may compile WebAssembly, soWebAssembly.instantiateStreaming(fetch(wasmUrl))works. - Favicon: A UI shows the icon that its page links with
<link rel="icon" href="/logo.svg">, or elseui/web/public/favicon.ico. A UI with neither shows Forge’s icon. - Client-side routing: At runtime, Forge serves any path whose last segment contains a dot (
.) as a static/compiled file, and servesindex.htmlfor every other path so that single-page app routers work at any route. Paths under/__forge/are reserved for Forge’s own routes, such as its sign-in callback, and never serve a UI file or the page.
Elm in a UI
A UI script can import an Elm module. The compiler builds it with Elm’s own compiler, Elm 0.19.3, and the import gives the script the program’s Elm object:
ui/web/
index.html # Loads ./main.ts as a module script
main.ts # Imports ./src/Main.elm and starts the program
elm.json # The Elm application the module belongs to
src/
Main.elmimport { Elm } from "./src/Main.elm";
Elm.Main.init({ node: document.querySelector("#app") });A module compiles as part of the Elm application that the nearest elm.json above it describes. That elm.json must be an application’s: it needs "type": "application", "source-directories", "elm-version": "0.19.3", and "dependencies" and "test-dependencies", each with "direct" and "indirect". As with elm make, it pins every package, indirect ones included:
{
"type": "application",
"source-directories": ["src"],
"elm-version": "0.19.3",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.4",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3"
}
},
"test-dependencies": { "direct": {}, "indirect": {} }
}- Packages: The build downloads each package that
elm.jsonpins from package.elm-lang.org, test dependencies included, because Elm verifies them too. A package that can’t be downloaded fails the build withDependencyFailed, naming the package. Forge keeps each package once it’s compiled, so a later build that pins the same version neither downloads nor compiles it again. - Errors: Elm’s errors fail the build with
CompileFailed, each at its module’s line and column, such asui/web/src/Cards.elm:6:5. A branch address shows them in place of the page, like any other build error. - Where Elm runs: Only UI scripts can import Elm modules. The extension’s
index.tsand the modules it imports can’t.
Build and Content Security Policy rules
Every response from an extension UI origin carries a strict Content Security Policy (default-src 'self', script-src 'self' 'wasm-unsafe-eval', style-src 'self' 'unsafe-inline', img-src 'self' data: blob:, font-src 'self' data:, connect-src 'self', frame-ancestors 'none', base-uri 'none', form-action 'self'). connect-src and img-src also allow Forge’s attachment storage, so a page can upload and show files. Because of form-action 'self', a form can submit only to the UI’s own origin. Responses also carry x-content-type-options: nosniff and referrer-policy: same-origin. See File uploads and downloads in a UI.
To catch authoring mistakes that the browser blocks at runtime, the compiler enforces these rules at build time and fails with CompileFailed if any rule is violated:
- No inline scripts:
<script>tags inui/web/index.htmlcannot contain inline JavaScript (unless the tag hastype="application/json"ortype="application/ld+json"). Move all executable code into a module file inui/web/and reference it with<script type="module" src="...">. - No classic scripts for compiled files: Any
<script src="...">referencing a file inui/web/(outsideui/web/public/) must includetype="module". - No external scripts, stylesheets, or CSS assets: A
<script src>or<link rel="stylesheet" href>inui/web/index.html, and aurl(...)or@importin CSS, cannot point at an external URL (such ashttps://cdn.example.com/...or the protocol-relative//cdn.example.com/...). Install libraries viapackage.jsonor include the files in the extension.data:URLs in CSS are allowed, but a<script src>or<link rel="stylesheet" href>inui/web/index.htmlcan’t be one: move its content to a file. The compiler doesn’t check other elements, such as<img src>, but the Content Security Policy blocks their external URLs in the browser. - Strict separation from sandbox modules: Browser UI code never runs in the extension sandbox and cannot import
index.ts,@buildr/sdk, or Node built-in modules (node:*). If both your tools and your UI need the same pure helper logic, put that logic in a separate module (such asshared/format.ts) and import it from both places.
UI addresses
An extension’s UI is served at a dedicated address. As with tools, there are two releases a UI can serve, and each has its own address:
| Release | Serves | Who may open it | Request | CLI |
|---|---|---|---|---|
| Branch | The extension at the head commit of a branch of the repo that defines it, main included, never its uncommitted edits |
Members with read on that repo |
PUT /repos/:repo_id/branches/:branch/extensions/:name/ui-address |
forge extensions upsert-extension-ui-address --branch |
| Installation | The version that a repo’s installation pins at main’s head commit |
Members with read on that repo |
PUT /repos/:repo_id/extension-installations/:name/ui-address |
forge extensions upsert-extension-installation-ui-address |
forge extensions upsert-extension-ui-address --repo "$DIRECTORY" --branch main --name directory
forge extensions upsert-extension-installation-ui-address --repo "$JOB" --name integrations.directoryThe first call for a release assigns a permanent slug, which is the extension’s name and a short random suffix, and returns { "address": "https://<slug>.onforgeapps.com" } on production (or a preview’s UI host). Later calls return the same address. If the release has no ui/web/index.html, the request returns ExtensionUiNotFound.
An address keeps serving the same release as it changes: a branch address serves the branch’s current head commit, rebuilt after each commit, even if the branch or the extension is renamed. An installation address serves whichever version main’s head commit pins. A branch whose UI code doesn’t build shows the compiler’s message instead of the page. On a branch address, Forge also loads a small script before the page’s own: when the page throws an uncaught error, rejects a promise that nothing handles, or loads something the Content Security Policy blocks, a dialog lists the errors, with each stack frame placed in your own files under ui/web/, and copies a prompt you can paste into your agent to fix them. Forge also keeps each error, so your agent can read them itself: GET /repos/:repo_id/branches/:branch/extensions/:name/ui-errors (forge extensions list-extension-ui-errors) lists them, the error seen most recently first, and DELETE on the same path (forge extensions delete-extension-ui-errors) clears them once they’re fixed. An error that repeats is one entry with a count, and each kept stack holds its first 4 KB. Each UI keeps its 50 errors seen most recently, and the repo keeps its 200 across every branch and extension. Installation addresses serve the page as it was built.
Neither address serves uncommitted edits: commit a change to see it.
The page reads which branch it works with from context.branch in @buildr/sdk/client: the branch that a branch address serves, or "main" for an installation. Calls the page makes to Forge are not scoped automatically, so a branch’s page should read and write that branch’s data explicitly.
The page’s context
context holds where the page runs and who opened it:
| Field | Holds |
|---|---|
org.id |
The org of the repo whose data the page shows. |
repo.id |
The repo whose data the page shows: the defining repo on a branch address, or the installing repo. |
extension.name |
The extension’s qualified name, <repo slug>.<name>, such as integrations.directory. |
extension.sourceRepoId |
The ID of the repo that defines the extension. |
branch |
The branch whose data and tools the page works with, "main" for an installation. |
user |
The signed-in user: id, displayName, email, and createdAt. |
context carries no role. The org’s policies decide what the user may do, and the API refuses a call they may not make, so a tool needs no check of its own for that.
A page calls its own extension’s tools through the operation that matches its address. On a branch address, context.repo.id is context.extension.sourceRepoId, and the page calls forge.extensions.callRepoExtensionTool({ repo_id, branch, name, tool, body }) with the extension’s name alone, the part of context.extension.name after the repo slug. On an installation address the two differ, and it calls forge.extensions.callRepoExtensionInstallationTool({ repo_id, name, tool, body }) with the qualified name:
import { forge, context } from "@buildr/sdk/client";
export function requestQuote(item: string, quantity: number) {
const qualifiedName = context.extension.name;
const where = { repo_id: context.repo.id, tool: "quote", body: { item, quantity } };
return context.repo.id === context.extension.sourceRepoId
? forge.extensions.callRepoExtensionTool({
...where,
branch: context.branch,
name: qualifiedName.slice(qualifiedName.indexOf(".") + 1),
})
: forge.extensions.callRepoExtensionInstallationTool({ ...where, name: qualifiedName });
}When a user navigates to an address in a browser:
- Forge checks whether the user is signed in to that UI’s origin.
- If not, Forge redirects the browser through its OAuth authorization server with PKCE, and the user signs in with their Forge account. That sign-in happens in a browser, so an agent working through the CLI or MCP can’t open a branch or installation address itself. It asks its person to open the address.
- The API verifies that the signed-in user may open the release, and that the release still exists and has a UI, then serves its compiled assets. Users who may not read the repo receive
403 Forbidden. A deleted branch or extension, a removed installation, or a version without a UI receives404 Not Found.
Public shares
A member can share the UI of main’s installation publicly, so that people without a Forge account can open it. Each share has an address of its own, at a long random name that nobody can guess:
forge extensions create-extension-installation-ui-share --repo "$JOB" --name integrations.directory
forge extensions list-extension-installation-ui-shares --repo "$JOB" --name integrations.directory
forge extensions delete-extension-installation-ui-share --repo "$JOB" --name integrations.directory --share-slug "$SHARE"POST /repos/:repo_id/extension-installations/:name/ui-shares answers { "slug", "address", "created_by", "created_at" }. Each call makes a new share. Sharing, listing, and revoking shares take the share action on the installation, which the org’s owners and the Admin policy have and the default Editor policy doesn’t; an owner grants it with a policy such as allow({ actions: ["share"], resource: installation("integrations.directory") }). Only a person’s own request shares a UI or lists its shares; extension code that asks is refused with Forbidden.
Anyone who opens a share’s address sees the page without signing in, as a guest who acts as the extension itself:
context.userisnull. The rest ofcontextnames the installing repo, as on the installation’s own address.- The page may call only
forge.extensions.callRepoExtensionInstallationToolfor its own installation’s tools. Any other operation answers403with{"_tag":"Forbidden"}. - A guest calls none of the extension’s tools until an org policy lets the extension’s guests call them. The tool then sees
ctx.principal.kindas"guest", and itsctx.forgecalls act as the extension. A workflow that such a tool starts doesn’t run as the guest: its steps run as the extension on its own, with the built-in access that a guest lacks, as Who a run acts as says. Open only tools that return what you mean to publish:
import { orgPolicy, allow, extension, tool } from "@forge/policies";
export const guestsQuote = orgPolicy({
name: "Guests quote",
principals: [extension("integrations.directory")],
statements: [
allow({
actions: ["call"],
resource: tool("integrations.directory/quote"),
when: ({ request }) => request.principal === "guest",
}),
],
});- A guest joins the installation’s rooms only once an org policy lets the extension’s guests
jointhem. A share has no stream and no error reports. - Each guest’s calls count against a rate limit of their own for the share.
A share ends when someone revokes it with DELETE /repos/:repo_id/extension-installations/:name/ui-shares/:share_slug, or when the installation is removed from main. While main installs a version without a UI, the share answers 404, and it serves again once main installs a version with one. Its maker leaving doesn’t end it. A share that ended answers 404.
Keeping a UI current
A page doesn’t poll to hear about changes. It opens a stream of the repo’s events, or joins a room that the extension declares to work with the others on the page. See Streams and rooms.
Linking to a repo’s other UIs
A page can link to the other UIs of its repo, as a nav bar does, with forge.extensions.listRepoExtensionUis({ repo_id }). It answers each UI served on main that members with read on the repo can open, with its address: first each installation whose version at main’s head commit has a UI, then each extension the repo defines whose version at main’s head has published with one. Each entry is { name, kind, address, version, description }, where kind is "installation" or "extension", and version is the version the UI serves, whose description it carries. Listing assigns an address to a UI that has none yet, so every entry can be opened at once, and later listings and upserts answer the same address.
import { forge, context } from "@buildr/sdk/client";
type Ui = {
name: string;
kind: "installation" | "extension";
address: string;
version: string;
description: string;
};
export async function navLinks() {
const uis = (await forge.extensions.listRepoExtensionUis({ repo_id: context.repo.id })) as Ui[];
return uis.map((ui) => ({
label: ui.name,
href: ui.address,
current: ui.address === location.origin,
}));
}Each UI signs in on its own address, so the first time a member follows a link to another UI, the browser passes through Forge’s sign-in without a prompt. A tool reads the same list with ctx.forge.extensions.listRepoExtensionUis, and the CLI with forge extensions list-extension-uis.
Branches, changes, and merge checks in a UI
@buildr/sdk/client also exports helpers for the branch work a page often needs, such as a branch picker or a commit button. Each one calls forge operations in context.repo. A helper’s branch defaults to context.branch, except changes.commit, which must name its branch:
| Helper | What it does | Operation |
|---|---|---|
branches.list() |
Lists live branches, main first |
branches.listRepoBranches |
branches.get(name) |
Reads one branch | branches.getRepoBranch |
branches.create(name, { from }) |
Starts a branch at the head of from |
branches.createRepoBranch |
branches.delete(name) |
Deletes a branch | branches.deleteRepoBranch |
changes.status({ branch, cursor, limit }) |
Answers a page of the diff from the branch’s head commit to its working state, so an empty data means nothing is uncommitted. Pass next_cursor back as cursor for the next page |
diffs.getRepoDiff |
changes.commit(message, { branch }) |
Commits the named branch’s working state. Without branch, it rejects with a TypeError |
commits.createRepoCommit |
changes.discard({ branch }) |
Discards the branch’s uncommitted work | commits.discardRepoWorkingState |
mergeCheck(source, { into }) |
Reports the conflicts and violations of merging source into into, without merging |
branches.checkRepoBranchMerge |
import { branches, changes, mergeCheck } from "@buildr/sdk/client";
const all = await branches.list();
await branches.create("estimate-v2");
const status = (await changes.status({ branch: "estimate-v2" })) as { data: unknown[] };
if (status.data.length > 0) await changes.commit("Update estimates", { branch: "estimate-v2" });
const check = await mergeCheck("estimate-v2");A helper answers what its operation answers and rejects with the same ForgeError, such as EmptyCommit or BranchExists. Picking a branch changes only the data that the page reads and writes. The address keeps serving the code of its own branch. An installation’s page works on main, so it commits to main only by passing { branch: "main" }.
File uploads and downloads in a UI
A page uploads a file the way any client does, as File attachments describes: it creates the blob through forge, sends the bytes straight to the URLs that the API signs, then names the blob in a record. The page’s Content Security Policy allows those URLs, so fetch reaches them from the page:
import { forge, context } from "@buildr/sdk/client";
type Upload = {
attachment_blob: { id: string };
parts: Array<{ url: string; offset: number; length: number; headers: Record<string, string> }>;
};
export async function attachFile(file: File) {
const upload = (await forge.attachmentBlobs.createRepoAttachmentBlob({
repo_id: context.repo.id,
body: { filename: file.name, content_type: file.type || "application/octet-stream", size: file.size },
})) as Upload;
for (const part of upload.parts) {
const response = await fetch(part.url, {
method: "PUT",
headers: part.headers,
body: file.slice(part.offset, part.offset + part.length),
});
if (!response.ok) throw new Error(`Upload failed with HTTP ${response.status}`);
}
return forge.customRecords.createRepoCustomRecord({
repo_id: context.repo.id,
branch: context.branch,
model_api_name: "uploads__file",
body: { fields: { name: file.name, file: { id: upload.attachment_blob.id } } },
});
}To show or download a file, call forge.attachmentBlobs.getRepoAttachmentBlobDownload({ repo_id, attachment_blob_id }) and use the url that it answers, as an <img src>, a link, or a fetch. The URL lasts five minutes, so request it when the page needs it. The page can’t use the /content redirect, because its own origin doesn’t serve the API.