Feature flags for an app (Settings → App → Feature flags)

Ship two versions of a thing side by side and keep each viewer on the same side. The app declares its flags in flags.json at the root of its repository (the app template has an empty one):

{ "flags": { "new-header": { "why": "the shorter header", "default": false } } }

A repository's admin sets each flag's value on Settings → App → Feature flags (page: src/web/pages/app_flags.ts), or in the terminal on the repository's Feature flags screen (src/tui/screens/appflags.ts: o on, f off, c clear; percentages and named viewers are set on the page), through the API (PUT /api/v1/repos/<owner>/<name>/flags/<flag> with forge, users, roles, percent; every field empty clears) or the MCP app_flags tool (list, set): all four go through setAppFlag (src/actions/app_flags.ts). The page lists each flag with its value; a row opens that flag's form. A value is the forge's own shape: everyone on or off, listed viewer ids, roles, and a percentage. A listed viewer or role is on, then the percentage, then everyone, then the default. A percentage is a hash of the flag and the viewer's id, so a viewer stays on one side as it grows.

The running app is told FORGE_FLAGS_URL (/api/v1/repos/<owner>/<name>/flags), which answers { flags: [{ name, why, default, value }] } to whoever may read the repository, and sends the app's FORGE_TOKEN along. The URL is the forge's own origin, which a cell always reaches (origins in src/apps/egress.ts), so the app's forge.json egress stays []. A viewer's ids a flag lists are shown only to the repository's admin; everyone else gets the percent, roles and forge fields, and a private repository answers 404 to a viewer who cannot read it. The declarations are parsed once per flags.json blob, not per request. The template's src/flags.ts is the whole client: no dependencies, createFlags().flag("new-header", { id: viewerId }) answers at once from the last list fetched (refetched in the background every 30 seconds, the last good list kept when the forge is unreachable; off until the first fetch). Copy that one file into any other app.

Not yet: the 7 and 30 day read-out the forge's own flags show. The app's reads happen in the app, so counting them needs the client to report back.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs