# brandrail

Keep AI-generated UI on-brand. `brandrail` checks code and live pages against your design system
(Brand Kit), and writes your rules into the files AI coding tools read.

```bash
npx brandrail init            # brandrail.config.json, src/brandrail.tokens.css + AGENTS.md, CLAUDE.md, Cursor/Copilot/Windsurf/Gemini rules
npx brandrail check           # violations + brand score for this repo
npx brandrail scan <url>      # check a running page in a real browser
```

## With a Brandrail account

```bash
npx brandrail connect                     # sign in through the browser; sets up the Brand Kit, AI rule files,
                                          # the MCP server for Claude Code / Cursor / Copilot, and the UI kit
npx brandrail check --changed --upload    # only changed lines, results in the dashboard
```

`connect` makes an API key on your machine and saves it in `~/.config/brandrail/credentials.json` (mode 600);
Brandrail only ever receives its hash, and the files it writes into the repo hold no key. AI tools start
`npx brandrail mcp`, which checks code on your machine: code is never uploaded. In CI, set `BRANDRAIL_KEY` instead.

## Commands

| Command | |
| --- | --- |
| `check [paths]` | `--format pretty\|json\|markdown\|github`, `--fail-below 80`, `--changed [base]`, `--upload` |
| `scan <url>` | `--pages 3`, `--storage-state auth.json` (pages behind a login), `--wait 2000`, `--upload`. Needs `npm i -D playwright && npx playwright install chromium` |
| `init` | `--from-api`, `--mcp`, `--tokens-css <file>`, `--no-rules`, `--force`. Writes the Brand Kit as CSS variables; import that file once at your app entry |
| `import <tokens.json>` | DTCG, Tokens Studio or Figma variables JSON into the config. `--replace`, `--primitives` |
| `rules` | List the rules |
| `connect` | `--no-browser`, `--no-install`, `--remote` (hosted MCP server), `--framework`, `--force` (sign in again) |
| `mcp` | The MCP server over stdio, for AI tools. `--framework`, `--report` (send scores, never code) |
| `migrate [paths]` | What's left on the way to the design system: other UI libraries (Material, MUI, Bootstrap, Ant Design, Chakra, PrimeNG) per library and per file. `--json`, `--top 30`, `--upload` |
| `report` | A shareable HTML handover report (paths and counts, never code). `--out file.html` |
| `whoami`, `logout` | Show or remove the saved sign-in |

Nothing is uploaded unless you pass `--upload`, and code snippets are never uploaded.
