figma-lupa
<p align="center"><img src="docs/lupa.svg" width="112" height="112" alt=""></p>
<h1 align="center">Lupa</h1>
Lupa lets a coding agent read a Figma design and rebuild it faithfully. It is a CLI (`lupa`) plus a small Figma plugin, with an optional MCP server. It is **read-only**: the plugin never edits the file.
One command gives the agent what it needs for a frame:
```bash
lupa design "<figma link>" -d src/assets --screenshot
```
- **A compact tree of the frame.** It holds the layout as flex/grid, exact sizes and CSS values, design tokens by name, and each repeated component once, with per-instance overrides.
- **The frame's icons and images**, written to `src/assets`, with each file named on its layer.
- **Your codebase's own names.** Run in your project, it puts the project's variable or class next to each colour, font and text style (`#ffffff → var(--color-bg)`, or `*-grey-200` and `text-sm font-medium` with Tailwind v4). It says where a component already exists and which props it takes (React `cva` variants, Phoenix `attr`s). Icons the project already has, as files or from Lucide or Heroicons, point at those instead of new copies.
- **A screenshot** for the agent to look at.
After building, `lupa compare` renders the page, diffs it against Figma and names the Figma layers where they differ.
## How good is it
In the benchmark an agent (Claude Opus 5.5) builds a Figma screen as HTML/CSS, reading the design with one tool. Mean of 3 runs per tool on a card-grid screen:
| | **Lupa** | Official Figma MCP | Framelink | figwright |
|---|---|---|---|---|
| Pixel mismatch vs Figma | **0.40%** | 0.42% | 2.12% (0.41–3.86%) | 0.41% |
| Text layers within 1 px vertically | **100%** | 100% | 66% (15–100%) | 100% |
| Design data read from Figma | **28k chars** | 80k | 29k | 110k |
| Context added | **28k tokens** | 63k | 30k | 82k |
| Agent turns | **10** | 25 | 10 | 24 |
- **Against the official Figma MCP:** the same quality with less than half the context and turns.
- **Against Framelink:** just as lean, without its layout drift. In 2 of 3 Framelink runs the grid rows ended up several pixels off.
- **Consistency:** all 6 runs of the current Lupa version rendered pixel-identically.
A second screen (a table page) gave the same picture.
**In an existing project**, the agent adds a page and a two-state component to a small HTML/CSS project that has its own tokens, components and icons. One run per tool, two for Lupa:
| | **Lupa** | Official Figma MCP | Framelink |
|---|---|---|---|
| Pixel mismatch, page / component | 2.09% / **3.02%** | 2.67% / 12.86% | **1.95%** / **3.02%** |
| Text layers within 1 px vertically | 90% | 68% | **93%** |
| Hard-coded colours left in new code | **1** | 3 | 14 |
| New SVG files | **2–3** | 10 | 7 |
| Context added | **59k tokens** | 105k | 64k |
| Agent turns | 28 | 57 | **27** |
Lupa names the project's variable for each design colour and points at the icons the project already has, so the agent writes almost no literal colours and few duplicate icons. For the method, the screens and how to re-run it, see [bench/README.md](bench/README.md).
## What the agent reads
`npm run demo`, shortened: a product card whose raw plugin JSON is 19.4k characters becomes about 870 tokens.
```
## tokens
colors:
$color/bg/surface = #ffffff var(--bg-surface)
$color/text/primary = #101828 var(--text-primary)
$color/brand/500 = #4f46e5 var(--brand-500)
typography (family weight size/line-height letter-spacing …):
$Heading/H3 = Inter 600 20/28 ls:-0.005em — Card titles
T1 = Inter 400 14/20
…
## components (instances below list only what differs)
Button{Variant=Primary} #7:1 120×40 hug; row; gap:8; justify:center; align:center; p:10,16; bg:$color/brand/500; radius:8
// props: Variant: Primary*|Secondary; Label: text="Button"; Has icon: bool=false
text "Label" #8:1 56×20 hug; font:T4; color:#ffffff; "Button"
// bound: text←Label
svg "Icon/Arrow right" #9:1 16×16 color:#ffffff; hidden
// bound: visible←Has icon
## design
frame "Product card" #13:1 360×640 h:hug; col; gap:16; p:24,24,24,$space/4; bg:$color/bg/surface; radius:16; shadow:$Elevation/2; clip
img "Hero" #14:1 312×180 w:fill; src:abc123def4 cover; radius:12
text "Title" #15:1 312×28 w:fill; h:hug; font:$Heading/H3; color:$color/text/primary; "Wireless headphones"
frame "Rating" #17:1 96×16 hug; row; gap:4
svg "Icon/Star" #34:1 16×16 color:#f5a524
+4 more like ↑: #35:1 #36:1 #37:1 #38:1
frame "Specs" #18:1 312×120 w:fill; h:hug; col; gap:8
frame "Row" #19:1 312×20 w:fill; h:hug; row; justify:between
text #20:1 60×20 hug; font:T1; color:#667085; "Battery"
text #21:1 40×20 hug; font:T3; color:#101828; "30 h"
+3 more like ↑, content:
#22:1 "Weight" "250 g"
#25:1 "Bluetooth" "5.3"
#28:1 "Colour" "Black"
frame "Actions" #31:1 312×40 w:fill; h:hug; row; gap:12
instance Button{Variant=Primary} #39:1 150×40 Label="Add to cart"; Has icon=true; w:fill; h:hug
```
The full format is in [docs/FORMAT.md](docs/FORMAT.md).
## Setup (once per machine)
Requirements: Node 20+ and the Figma desktop app (Figma runs imported plugins only there, not in the browser).
```bash
npm install -g figma-lupa
lupa setup
```
`lupa setup` does the rest and says what it did. You can run it again at any time.
1. **The skill:** it links Lupa's skill into `~/.claude/skills` (or `$CLAUDE_CONFIG_DIR/skills`). The skill teaches Claude the commands and the output format. It loads only for Figma work, so Lupa costs no context in other sessions.
2. **The plugin:** it prints the path of the plugin's manifest. Import it once: in any Figma file, *Plugins → Development → Import plugin from manifest…*.
3. **Browser for `compare --url`:** it checks for one. Lupa looks for `LUPA_BROWSER`, then Playwright's browsers, then Google Chrome. If you have none, run `npx playwright install chromium`.
**Optional MCP server**, for clients without a shell: `claude mcp add --scope user lupa -- lupa mcp`.
## Updating
```bash
lupa update
```
Then close the Lupa plugin in Figma and run it again. The skill and the plugin's manifest stay at the same paths, so there is nothing to copy or re-import. The next `lupa` command replaces the background hub with the new version.
Lupa asks npm for a newer version once a day, and a command mentions it when there is one. Set `LUPA_NO_UPDATE_CHECK=1` to turn this off.
## Daily use
1. Open the design in Figma, run *Plugins → Development → Lupa*, and keep its small window open.
2. Select a frame or copy its link.
3. Ask Claude, for example: "Implement the selected Figma frame in `src/components/ProductCard.tsx` with our Tailwind tokens."
Start Claude in your project's root folder. `lupa design` then reads the project's own colour and font variables, text style classes, components and icons, and points the design at them. Use `--project DIR` for another folder, or `--project none` to turn this off.
The first `lupa` command starts a background hub for the plugin to connect to. It exits after an hour without requests. Several Claude sessions and several open Figma files can share it.
## Commands
A target is a Figma URL (in quotes), node ids like `12:34`, or nothing for the current selection. Each command has an MCP tool of the same purpose. Run `lupa help` for every option.
| Command | What it does |
|---|---|
| `lupa design [target]` | The tree above, within a token budget (`--budget`, default 8000). Cut subtrees name the id to fetch next. `-d DIR` also writes the assets and puts their paths on the layers. `--screenshot` adds a PNG. `--project DIR` picks the codebase to point at (default: the current folder). |
| `lupa screenshot [target]` | PNG at up to 2×, sized for vision models and tiled when tall. |
| `lupa assets [target] -d DIR` | Icons as SVG and images as their original files, deduplicated. Use `--current-color` for monochrome icons. |
| `lupa compare [target] --url <page> --selector <css>` | Renders your page at the design's width and diffs it against Figma. Prints the mismatch and the differing regions by Figma layer, and writes a design / page / diff image. A `file://` page is served over local HTTP, so a static page needs no server. `--image <png>` compares a screenshot instead. |
| `lupa tokens` | Variables (all modes) and styles, as a list, CSS or JSON. |
| `lupa outline`, `lupa find <query>` | Pages and frames, and search by layer name (add `--text` to search text content). |
| `lupa css <target>` | Figma's own Dev Mode CSS, as a cross-check. |
| `lupa status` | Connected files and selections. |
## Troubleshooting
- **"No Figma file is connected":** run the plugin in the file and keep its window open. After updating Lupa, run the plugin again.
- **"the Lupa plugin … is version X":** Figma runs the old plugin code until you close the plugin and run it again. If it keeps the old version, Figma loads it from an old folder: run `lupa setup` and import the manifest it shows.
- **"used Figma's SVG export":** Figma stops rendering PNGs while its window is hidden or covered, so Lupa rendered the SVG export in Chromium instead. Layout and text match; blur, some newer effects and occasionally a stroke can be missing. For an exact render, bring Figma to the front and run the command again.
- **Port in use:** set `LUPA_PORT`, change the port in `plugin/src/ui.html` and `plugin/manifest.json`, and rebuild.
- **Logs:** the hub logs every request to `$TMPDIR/lupa/hub.log`. Set `LUPA_DEBUG=1` for bridge events.
## More
- [docs/internals.md](docs/internals.md): how the output stays faithful, the architecture, security, development.
- [docs/landscape.md](docs/landscape.md): other Figma tools and why Lupa is built this way.
- [bench/README.md](bench/README.md): the benchmark.
## License
GPL-3.0-or-later. See [LICENSE](LICENSE).
TDQS
Scored across 9 tools
Most tools target clearly different needs: navigation (status, get_outline, find_nodes), extraction (get_design, get_tokens), assets (export_assets), visuals (get_screenshot), and verification (compare_screenshot). The only genuinely fuzzable pair is get_css vs get_design, since both emit styling information for layers, but the descriptions explicitly frame get_css as a cross-check rather than a layout description. An agent can pick correctly with the descriptions in hand.
Nearly all names follow a verb_noun pattern (get_tokens, get_css, get_screenshot, get_outline, get_design, find_nodes, export_assets, compare_screenshot), and the verbs map sensibly to the action type. The lone deviation is the bare noun 'status', which breaks the pattern but remains unambiguous and readable.
Nine tools is well within the ideal band and each one covers a distinct stage of the design-to-code loop: discovery, extraction, asset export, visual inspection, and pixel comparison. There is no filler or redundant tool in the set.
Coverage of the read/inspect/verify lifecycle is strong: map the file, search layers, pull exact layout+tokens, export assets, view renders, and diff against an implementation. Minor gaps remain, such as no direct fetch-by-node-id (agents must go through get_outline/find_nodes first) and no inspection of prototypes/interactions or component-variant catalogs as a first-class surface. Writing back to Figma is absent, but that appears outside this server's stated purpose.