# Frontend work

> Keeps an agent's UI work on one component library, theme and token source per repository, checks every frontend change before the turn ends, and pulls reference screens from Mobbin.
>
> Your agents stay on one component library and one token source.

This feature is the `sc-frontend` plugin. `sc-frontend` is opt-in: no workspace loads it until you add it. It needs no other plugin.

Once it is loaded, Claude Code uses it when the task calls for it, so you do not have to call it by name. To load it for one launch, or to leave it out of one launch once a manifest names it:

```sh
sc <project> <agent> --with sc-frontend
sc <project> <agent> --without sc-frontend
```

To keep it, add `"$SC_PLUGINS/sc-frontend"` to the `plugins` list in the agent's manifest (`.claude/superclaude.toml`), and delete that line to remove it. Or run `sc <project> <agent> --sc-agent "add sc-frontend to this agent"`.

| Without it | With it |
|---|---|
| The agent imports react-datepicker, which your charter retired. | The edit guard refuses the edit and names the library to use. |
| You say "too busy" and the agent guesses at a layout. | It looks up the pattern shipped apps share on Mobbin, then builds it. |
| You describe a UI problem in words and hope. | You click the element in the running app and the note reaches the session. |

sc-frontend adds a per-repository charter, `.claude/frontend.json`, that names the one component library and token source a web or iOS app builds on. It also adds hooks that hold every change to the charter, Mobbin reference lookups and a review bar for the running app.

## Using it

Ask in plain words. Before the first UI change in a repository, the agent derives the charter on its own: it scans the code and picks one library per job. Ask for it directly to see the result first:

> What is this app's frontend stack, and why does it have three date pickers?

Then ask for UI the way you would ask a designer:

> Build an onboarding flow for new team admins.

> The settings page feels cluttered. Make it easier to change which emails I get.

The agent reads the charter, pulls Mobbin references, reuses what the codebase has, builds on the charter's library with tokens for every value, and ends with a doctor check.

Sign in to Mobbin once. It needs a paid plan and opens your browser:

```sh
~/.superclaude/plugins/sc-frontend/bin/mobbin-auth login
```

To point at problems in the running app instead of describing them:

> Add the review bar to apps/web so I can mark what is wrong on screen.

**How it works**

### Why a charter

An agent that builds what was literally asked installs a new dependency, hardcodes the color you named, and writes another copy of a component that already exists. The predictable debt is several component libraries doing one job, several chart or date-picker widgets, color literals instead of tokens, and screens with too much text.

The charter is derived from counts, not from anyone's preference, and the checks make it binding at the moment of the edit, where the debt is added. The agent pulls Mobbin results and builds the pattern most of the apps share. The review bar sends the element you select, with its component, source line and a screenshot.

Its [prompt section](/prompts#p-sc-frontend-stance) has the agent read your UI suggestions as outcomes, not specifications. The agent owns consistency and size. When your idea and the references disagree, it builds the referenced version and says why in one line.

On web it covers React, Vue, Svelte, Angular and plain HTML and CSS. On iOS the defaults are SwiftUI, the app's own component module, asset-catalog colors, Dynamic Type, SF Symbols and vector image sets.

### The charter

The audit runs `sc-frontend inventory` over every tracked file. It reports the libraries per job and where several do one job, token adoption, icons and images, duplicate components and text-heavy screens. On a codebase of millions of lines the scan takes about a minute.

For each job with more than one library, the audit picks one winner in this order:

1. **Health is a gate.** A library that is deprecated, archived, or without a release in about 12 months cannot win. The audit checks the live registry, not memory.
2. **Coverage.** The library that natively covers more of the jobs the product renders wins, even when a thinner one has more imports. The others are retired into it, never bridged with a third.
3. **Theming through tokens**, then **accessibility built in**.
4. **Footprint** breaks ties between near-equals.

Widgets follow the component library: if the winner ships a chart, picker, grid or toast, that is the widget. The audit then finds or creates the one token source and wires it into the winner's theme. It does not migrate call sites; the checks stop new literals, and refactors replace old ones where work touches them.

The charter sits at the repository root, or at the root of one app in a monorepo. The nearest one above a file wins.

```json
{
  "version": 1,
  "web": {
    "components": "@mui/material",
    "tokens": "packages/theme/src/tokens.ts",
    "icons": "@mui/icons-material",
    "date-pickers": "@mui/x-date-pickers"
  },
  "retired": {
    "antd": "@mui/material",
    "react-icons": "@mui/icons-material",
    "react-datepicker": "@mui/x-date-pickers"
  },
  "why": {
    "web.components": "MUI: 1,240 files vs antd 310; it covers the data grid, pickers and autocomplete the product uses, and its theme reads our tokens"
  }
}
```

| Key | Value |
|---|---|
| `version` | `1` |
| `web`, `ios` | one entry per job; at least one platform |
| `retired` | a package, or a prefix ending in `*`, mapped to its replacement |
| `why` | `<platform>.<job>` mapped to one present-tense line with the numbers behind the choice |

Job names are the inventory's categories, such as `components`, `icons`, `charts`, `date-pickers`, `tables`, `forms` and `toasts` on web, and `ui-kits`, `layout`, `images` and `huds-toasts` on iOS. Matching names is how the doctor knows a change adds a second library for a job the charter already fills. Two keys are free-form: `tokens`, the path of the token source, and `illustrations`, where the vector art lives.

### The checks

A frontend file is a web or iOS source file (`.ts`, `.tsx`, `.js`, `.vue`, `.svelte`, `.astro`, `.css`, `.scss`, `.html`, `.swift`, `.m` and similar) or a dependency manifest (`package.json`, `Podfile`, `Package.swift`). Three checks watch them, and all three import one rules file, so they always agree.

**The edit guard** is a function hook on Edit and Write. It refuses an edit that would make a file start importing a retired library, names the replacement, and suggests `git mv` when the agent is only moving code. Everything else it reports to the agent as context, never as a block:

- comments over two lines, or comments that narrate history ("previously", "migrated from", a ticket number);
- growth inside a file that already sits on a retired library;
- the charter's summary, the first time the session touches a repository, or a pointer to the audit when there is none;
- Mobbin not signed in, or a UI change made before any Mobbin lookup.

**`sc-frontend doctor --changed`** gates a change: the working tree against a revision (default `HEAD`), plus untracked files. It fails on a retired import, a second library for a filled job, a hardcoded color outside the token source, and an over-long or history comment. A new raster image is a warning. Without `--changed`, the doctor reports the debt still standing instead: files per retired library, color literals and sprawl.

| Exit | Meaning |
|---|---|
| `0` | clean |
| `1` | findings |
| `2` | usage error |
| `3` | no charter, or an invalid one |
| `4` | Mobbin unavailable (`refs` only) |

**The Stop hook** reads the turn's transcript. If the turn edited frontend files and no doctor check ran after the last edit, it sends the agent back once to run the doctor check. It never blocks twice in a row.

The doctor check runs the charter check, then the touched package's own gates: typecheck, lint and tests, plus a build when config or routing changed. On iOS it builds the scheme for a simulator and runs `swiftlint` when the repository configures it. It fixes what they report and reruns until both pass. It never edits the charter to make a finding go away.

### Mobbin references

Mobbin lookups run in their own forked context on `sonnet`, so the screenshots stay out of the main conversation. It searches with `sc-frontend refs`, which is on the session's `PATH`. From your own shell, run it through node:

```sh
node ~/.superclaude/plugins/sc-frontend/bin/sc-frontend refs flows "change notification preferences" --platform=web
node ~/.superclaude/plugins/sc-frontend/bin/sc-frontend refs screens "empty inbox" --platform=ios --limit=10
node ~/.superclaude/plugins/sc-frontend/bin/sc-frontend refs sections "pricing table"
```

Flows suit a journey of several steps, screens suit one screen or state, and sections suit a marketing-site block. Platform is `web` or `ios`; Mobbin has no Android, so an Android ask searches `ios` and says so. `refs` saves every preview image to disk with a `refs.md` index, by default in a temp folder (`--out=<dir>` to choose). The lookup looks at the images, finds what the strongest apps share, and returns under 250 words: the layout to build, which words an icon or illustration can replace, three to six Mobbin links, and each of your prescriptions the references argue against.

`refs` reaches Mobbin through the plugin's own `mobbin` command, `bin/mobbin`. It is a short wrapper that runs Mobbin's remote MCP server through `mcpr`, using the server entry the plugin ships in `lib/mobbin.mcpr.toml` and a bearer token from `mobbin-auth`. You can call it directly, for example `mobbin search_flows '{"query":"onboarding","platform":"ios"}'`. A lookup can also use a Mobbin MCP tool already connected to the session. When the bundled `mobbin` command cannot run, `refs` exits `4` with `MOBBIN UNAVAILABLE`, and the agent builds on platform conventions (Apple's Human Interface Guidelines on iOS, the component library's own patterns on web) and tells you so.

`mobbin-auth status` shows whether you are signed in, without printing tokens, and exits `1` when you are not.

### Building and refactoring

New or changed UI goes through a fixed order. It reads the charter, restates your ask as the job the end user is doing, pulls references, and searches the codebase for what already exists before it writes a line. It builds on the charter's library with tokens for every value and covers the empty, loading and error states. It cuts copy in favour of icons and SVG illustrations, then reads its own diff and turns duplication into reuse. It then checks the result on screen: a dev-server screenshot on web, a simulator screenshot on iOS.

A refactor runs only when the work in hand needs it: the change sits on a retired library, would create a third copy of a component, or you asked. It migrates the smallest unit that makes the current work clean, merges duplicates, deletes what is left dead, and checks that deletions exceed insertions. A repository-wide migration runs as a Claude Code Workflow over the `sc-frontend sites <package>` work-list, in batches that share no files.

> Get rid of react-datepicker on the billing screens.

> How do the best iOS apps lay out checkout with a saved card?

### The review bar

Asking for the review bar wires it in. The plugin runs a local receiver, the `debugbar` MCP server, which also listens on `http://127.0.0.1:7337`. On web, one dev-only loader line in the app's entry file pulls the bar from the receiver, so nothing is copied into the repository. On iOS, the agent copies `SCDebugBar.swift`, which is entirely `#if DEBUG`, into the app target and calls `SCDebugBar.install()` at launch.

- **Web:** open the app with `?sc-debug=1` or press Alt+Shift+D, then press **Select** (Alt+Shift+S), click an element, write the note and press **Add**.
- **iOS:** shake the device, or press Control-Command-Z in the Simulator.

The bar records the element, its component and source location when the framework exposes them, and a screenshot with your pin drawn on it. **Send to Claude** posts the batch to the receiver. The plugin's hooks module polls the receiver every four seconds and starts a turn in the session when a batch lands. The agent reads the notes, fixes each one by the build rules, reports one line per change back to the bar, and ends with a doctor check. **Copy Markdown** gives you the same notes to paste, and the bar copies them automatically if the receiver cannot be reached.

The receiver accepts requests only with a loopback `Host` header, and refuses any browser origin that is not localhost or listed in `SC_FRONTEND_DEBUG_ORIGINS`. A website you visit cannot post notes into your session.

- If the app's dev Content-Security-Policy blocks the loader, add `http://127.0.0.1:7337` to its dev-only `script-src` and `connect-src`.
- The iOS bar reaches the receiver on `127.0.0.1` from the Simulator. The receiver listens on loopback only, so a physical device cannot reach it and the bar falls back to Copy Markdown.
- If App Transport Security refuses the plain-HTTP call to the receiver, add `NSAllowsLocalNetworking` to the Debug configuration's Info.plist only.

**What it needs**

| Needs | Required | What for |
|---|---|---|
| `node` 18+ and `git` | yes | the CLI, hooks and receiver |
| `python3` and `mcpr` | for Mobbin | sign-in and search |
| A paid Mobbin plan | recommended | reference screens |
| `CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1` | for the guard | loads the edit guard, the Mobbin checks and the review-bar wake; `sc` sets it on every launch except `-i` |
| a browser | for sign-in | `mobbin-auth login` opens it |
| Xcode (`xcodebuild`, `xcrun simctl`) | iOS only | building, running and screenshotting on a simulator |
| `mcpr` and `gaze` | no | a dev-server screenshot after a web build, and looking at saved Mobbin previews when image reads are refused |

`mcpr` ships with sc 0.2.2 and later (`sc system` installs it), and `gaze` ships alongside it with its own key. The plugin ships its own Mobbin server entry for `mcpr`, so you add nothing to `~/.config/mcpr/config.toml`. Without a Mobbin sign-in, the agent builds on platform conventions and says so.

**Configuration**

The charter is the configuration. Edit it like any other file; the guard rereads it.

### Load it in a manifest

sc-frontend is opt-in: no workspace loads it unless you add it. `sc <project> <agent> --with sc-frontend` loads it for one launch. To load it for good, name it in the [manifest](/docs/superclaude-toml) (`.claude/superclaude.toml`):

```toml
plugins = [
  "$SC_PLUGINS/sc-memory",
  "$SC_PLUGINS/sc-frontend",
]
```

The stance renders in every workspace that loads the plugin, so `system_prompt` need not name it. Naming `sc-frontend:stance` there only pins where it renders, and `sc doctor` then notes it as `redundant-plugin-prose`. The plugin is opt-in, so `sc doctor` does not expect every workspace to load it.

### The stance and the receiver

[`sc-frontend:stance`](/prompts#p-sc-frontend-stance) renders in the main agent's prompt of every workspace that loads the plugin. It covers the rules above: outcomes over prescriptions, Mobbin before opinion, one library per job, the least code, comments of at most two lines in the present tense, and a doctor check at the end of every frontend task.

The review-bar receiver reads two environment variables from the session:

| Variable | Default | Effect |
|---|---|---|
| `SC_FRONTEND_DEBUG_PORT` | `7337` | the loopback port the receiver listens on |
| `SC_FRONTEND_DEBUG_ORIGINS` | none | extra comma-separated origins allowed to post notes, such as a LAN address or a custom dev domain |

If another session already holds the port, the receiver still answers as an MCP server and reports that the port is taken. Mobbin tokens live in `~/.config/mcpr/mobbin-oauth.json`, mode 600, and `mobbin-auth token` refreshes the access token before it expires.

### Run the CLI from your own shell

While the plugin is loaded, `sc-frontend`, `mobbin` and `mobbin-auth` are on the session's `PATH`. From your own shell, point the CLI at a repository:

```sh
node ~/.superclaude/plugins/sc-frontend/bin/sc-frontend inventory ~/code/web-app
node ~/.superclaude/plugins/sc-frontend/bin/sc-frontend sites antd ~/code/web-app
node ~/.superclaude/plugins/sc-frontend/bin/sc-frontend doctor ~/code/web-app --changed=origin/main
```

| Command | What it prints |
|---|---|
| `inventory [dir] [--json]` | libraries per job and sprawl, token adoption, icons and images, duplicate components, text-heavy files |
| `sites <package> [dir] [--json]` | every file and line importing a package, or a prefix ending in `*`: the work-list for a migration |
| `refs <screens\|flows\|sections> "<query>"` | Mobbin results with their links and saved preview paths; takes `--platform`, `--limit` and `--out` |
| `doctor [dir] [--changed[=<rev>]] [--json]` | charter health and standing debt, or with `--changed`, the findings for one change |
