Repository avatar
Other Tools
v0.3.4
active

figma-lupa

io.github.wjkba/figma-lupa

Read-only Figma for coding agents: exact layout, tokens mapped to your CSS, assets and a pixel diff.

Documentation

Lupa

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:

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 attrs). 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:

LupaOfficial Figma MCPFramelinkfigwright
Pixel mismatch vs Figma0.40%0.42%2.12% (0.41–3.86%)0.41%
Text layers within 1 px vertically100%100%66% (15–100%)100%
Design data read from Figma28k chars80k29k110k
Context added28k tokens63k30k82k
Agent turns10251024
  • 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:

LupaOfficial Figma MCPFramelink
Pixel mismatch, page / component2.09% / 3.02%2.67% / 12.86%1.95% / 3.02%
Text layers within 1 px vertically90%68%93%
Hard-coded colours left in new code1314
New SVG files2–3107
Context added59k tokens105k64k
Agent turns285727

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.

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.

Setup (once per machine)

Requirements: Node 20+ and the Figma desktop app (Figma runs imported plugins only there, not in the browser).

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. It is also listed in the MCP Registry and on Glama, where you can browse its tools.

Updating

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.

CommandWhat 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 DIRIcons 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 tokensVariables (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 statusConnected 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

License

GPL-3.0-or-later. See LICENSE.

NPM
figma-lupa
Install Command
npm install figma-lupa