Tokens · Two layers in code · Brands and checks · Rules · A third layer · The last checks · Tools
Loading article
A rebrand should cost one file. In a product where every screen holds its own copy of the blue, it costs a search for every copy. This part builds the layers that make it one. Primitive tokens hold the values, semantic tokens say what each value is for, and a third layer appears only where one brand restyles one component. Every step is a prompt for a coding agent, and by the end eight checks fail with a plain sentence the moment one of their rules breaks.
The starter is a public A project folder whose every change Git records, kept on GitHub so others can read and review it. holding the system this series builds, with a tag at the end of each part, a name pinned to the A saved change to a repository, with a note saying what changed and who made it. where that part finishes. Every prompt is printed in full, and under each one that builds part of the system a replay of the agent's work plays beside what it made, taken from the matching commit in the starter.
None of the prompts asks for a pull request or an explanation, because the A Markdown file at the root of a repository that coding agents read before working in it, such as AGENTS.md. from part two already does. In your repository each one ends with a A request to bring a branch into the main line of a repository, where the change can be read, discussed and checked first. to read, check and merge. The starter has one commit for each prompt that changes the repository, plus two that write the prompts down, so your history can be compared with mine under Commits on its GitHub page.
This part needs Node 24 or later. The demo page it builds runs on Vite, which needs Node 22.12 or later, and the series uses 24 from here on. If node --version prints less than 24, install Node 24 or later from nodejs.org, then open a new terminal so it takes effect and start your agent again.
Starting with this part? You need Git, the GitHub CLI and a coding agent too, set up as part two shows. Download the starter at part-2-setup as a ZIP file and unzip it. Move the folder it makes, design-system-starter-part-2-setup, into your home folder and rename it design-system-starter, so it sits where part two's route puts it. On Windows, Extract All wraps it in a second folder of the same name, so move the inner one. A new terminal opens in your home folder, so the commands start by moving into it.
cd design-system-startergit init -b mainnpm installgit add -Agit commit -m "Start from part-2-setup"
cd moves into the folder. The download has no history, so git init -b main makes it a repository whose main line is called main. npm install downloads the tools the build uses, and the last two save every file as the first commit. If Git stops to ask who you are, run the two git config --global lines it prints, with your own name and email, and commit again.
Start your agent in the same folder and give it this prompt.
PromptCreate the repository and push
Create a public GitHub repository called design-system-starter with the GitHub CLI, connect this folder to it, and push the main branch. This first push to main is the one exception to the rule in AGENTS.md. Explain each command in one sentence before you run it. If I'm not signed in to the GitHub CLI, tell me the one command to sign in and stop.
Last, set up the ruleset so a failing check blocks a merge.
Tokens hold the decisions, in two layers
A A design decision with a name, such as a colour, a size or a font, stored once so design and code read the same value. is one decision with a name. color.blue.600 is a particular blue, and size.200 is 8 pixels. Tokens are stored as data, so one decision can become a A named value in CSS, written --name and read with var(--name). Often called a CSS variable. for the web, a constant for an iOS app and a variable in a design tool.
Tokens work best in layers. The first layer holds raw values and names them for what they are. These are A raw value named for what it is, such as color.blue.600. Nothing on screen reads it directly., the palette of every blue, grey and size the product may use. Nothing on screen reads a primitive directly.
The second layer names jobs. color.fill.brand is the fill of whatever should be pressed first, and it points at one of the primitives instead of holding a value of its own. These are A name for a job, such as color.fill.brand, that points at a primitive. Screens read these., and they are what screens and components read. Point color.fill.brand at a green and every button turns green without anyone touching a button. The starter has two brands to try this on, Harbor in blue and Grove in green.
A third layer, A name for one part of one component, such as button.radius, that points at a semantic token., names one part of one component, such as button.radius. This part starts with two layers and adds the third only when one brand restyles one component on its own.
A building in three parts. The foundation is primitives, raw stone being hauled in. Two floors on it are semantics, with doors lettered fill, text, border, surface, radius and space. On the roof one room is built and labelled button, and the other rooms are only pegged out, with the words only when a client asks lettered across them.
filltextbordersurfaceradiusspacePrimitivesSemanticsComponent tokensbuttononly when a client asks
Primitives
Raw values at the foundation, which nothing on screen reads directly.
Semantics
The floors, with a door per job for fill, text, border, surface, radius and space.
Component tokens
The rooms, with one built for button and the rest pegged out until someone asks.
Three layers of tokens, drawn as a building. This part builds the first two and one room of the third.
A product you already have holds the first draft of its primitives
Most teams start from a product that already has colours in it. Before the first token, open your agent in that product's folder and ask it to count what the product uses. The prompt only reads, so it makes no commit.
PromptCount what a product already uses
This folder holds a product that already exists. Before we add any tokens, read its styles and list every colour, font size, font weight, spacing value and corner radius they use, with how many times each one appears. Put colours that are nearly the same next to each other, and mark anything used fewer than three times. Don't create or change any files.
Near-duplicates sit side by side on the list, which makes the drift easy to see, and a value used once or twice is a candidate to merge into its neighbour. The primitives this part builds keep each hue as a ramp, ten steps from 50, the lightest, to 900, the darkest, with white and a darker 950 added to grey, and merging moves each colour on the list to its nearest step. A product that lives only in design files can be counted in Figma instead, a screen at a time, starting from the Selection colors panel.
Blue ramp
Blue ramp50100200300400500600700800900
Sign inContinue
Sign in, #2f72d64.67:1 with white
CheckoutPay now
Checkout, #1f62bd5.93:1 with white
SettingsSave changes
Settings, #3b80e33.90:1 with whiteUnder 4.5:1
TeamSend invite
Team, #2a5fae6.28:1 with white
BillingUpgrade
Billing, #3470c94.88:1 with white
As found, each screen has a blue of its own.
Five button blues made up for part one, one per screen, each matched to the nearest step of the starter's blue ramp. Three land on blue 600.
Moving a colour onto the ramp keeps about the lightness it had, and with it the contrast. The Settings blue was too light for white text before the move, and the nearest step, blue 500, still is. Which step the main button gets is the semantic layer's decision.
If you made the list, copy it out of the agent's answer, because the agent in your design system's folder will not see it. Paste it at the end of the primitives prompt below, followed by these two sentences.
PromptBuild on the list
Build the ramps and scales around the values in this list, and keep the gray, blue, green and red ramps the later prompts use. Tell me which values you merged.
If you are starting from nothing, skip this step.
Primitives hold values and nothing else
The first prompt that changes the repository fills the bottom layer, and its one design decision is in the line about colour. Every hue has the same lightness at each step, so blue 600 is as light as green 600.
Token files are JSON, plain text in the format the W3C The W3C Design Tokens Community Group, which publishes the JSON format for token files that Style Dictionary, Terrazzo and Tokens Studio read. published as its first stable version in October 2025. Each token is an object with a $value, the value itself, and a $type saying what kind of value it is, such as a colour or a size, written on the token or once on the group around it. A colour can be written in A way of writing a colour as lightness, chroma and hue, where the first number is how light the colour looks., where the first number is lightness, so the same lightness in every hue is the same first number. npm run build hands the files to An open-source tool that turns token files into code: CSS variables, JavaScript, iOS and Android values., the tool the starter's build runs on, which writes them out as CSS.
PromptAdd the primitives
Add primitive tokens in tokens/primitives/. A primitive is a raw value named for what it is, never for where it's used.- color.json: ramps for gray, blue, green and red, steps 50 to 900. Gray also gets 0 (white) and 950. Make the steps even in perceived lightness, so 600 is equally dark in every hue. Write colours in the format's OKLCH form, with a hex fallback.- size.json: one scale for spacing and corners, in px: 0, 2, 4, 6, 8, 12, 16, 24, 32, and full (9999px).- font.json: one sans-serif family, sizes 14, 16, 20 and 24, weights 400, 500 and 600.Every token needs a $value and a $type. Run the build and show me part of the CSS.
A colour's value names its colour space, lists its three numbers and carries a hex fallback. Style Dictionary turns each colour into hex for the CSS, and uses the fallback only for a colour outside sRGB, the range of colours every screen can show. It writes every token as a CSS variable in dist/tokens.css, with dashes where the name has dots, so color.blue.600 comes out as --color-blue-600: #226ec5;. A style reads a variable back with var(), as in var(--color-fill-brand) once the semantics exist, so a screen holds the name and the build supplies the value.
White text measures 5.1:1 on blue 600 and 4.7:1 on green 600, both above the 4.5:1 that WCAG asks of body text, so a brand that swaps one hue for another keeps close to the contrast it had. Part four adds a check that measures every pair.
In Figma, a variable collection called Primitives
A Primitives collection with one mode, where color/blue/600 holds #226EC5 and size/200 holds 8.
Name
Value
color/blue/500
#3D87E0
color/blue/600
#226EC5
color/blue/700
#21589A
color/green/600
#1E8441
size/200
8
size/full
9999
The primitives file is one collection with a single mode and a variable per value. Figma separates the names with slashes where the code uses dots. Select every variable in it, choose Edit variables, untick Show in all supported properties and tick Hide from publishing, so designers pick from the semantics the way screens do in the code.
Every job starts from merged work, and a bad one can be thrown away
Open the pull request the agent links to. Files changed shows every line it wrote, and the check runs near the bottom of the Conversation tab. When both look right, choose Squash and merge from the button's menu, so the job lands as one commit like the starter's, and confirm. Then tell the agent you merged it, because each job should start a new A line of changes in a repository, kept apart from the main one until it is ready. from the merged main and carry everything before it.
PromptStart the next job from main
I merged the pull request. Switch to main and pull the merged work. I'll give you the next job, and it goes on a new branch from there.
The rules file counts a change to the build or check script as a job of its own. Some prompts in this part change a script beside other files, and one asks for two jobs at once, so if the agent stops to ask before the second job, say yes, since the prompt asked for both.
When the check fails, a red cross appears beside it. The Details link next to the cross opens the log of the run, and the failing step prints the same lines npm run check prints on your computer, naming the file and the rule. Paste them to the agent and ask for a fix on the same branch, and the check runs again once the fix is pushed.
A session that goes wrong can be thrown away before it reaches a pull request.
PromptThrow away the last job
Throw away everything you changed for this job, committed or not, switch back to main, and tell me what you discarded.
A pull request you decide against can be closed without merging. One that was merged and turns out wrong has a Revert button on GitHub, which opens a new pull request that undoes it, checked like any other.
Semantic names say what a value is for, so they survive a rebrand
Name a colour by what it looks like, blue-600, and the name holds only until the brand changes. Name it by its job, fill.brand, and it stays true whatever colour the brand paints it. Rebrand the two cards below and watch which names start to lie.
Rebrand to
Named for the colour
StudioMost popular
$24per seat, per month
Unlimited projects and reviewers
A shared component library
Start a 14-day trialCompare plans
Button--blue-600
Tag--blue-50
Title--gray-900
Named for the job
StudioMost popular
$24per seat, per month
Unlimited projects and reviewers
A shared component library
Start a 14-day trialCompare plans
Button--color-fill-brand
Tag--color-fill-brand-subtle
Title--color-text-default
Under Harbor both cards are blue, and every name on both sides is true.
The same card twice, one wired to colour names and one to job names.
The starter names semantic colours role first, then intent, then an optional state, as in color.fill.brand, color.fill.brand-hover, color.text.on-fill and color.border.focus. Four roles cover most interfaces. Surface is what things sit on, fill is the colour inside a button or a tag, and text and border are what they sound like. The intent says which job within the role, such as brand or link, and the state says when it applies, such as hover. Focus in color.border.focus is the focus ring's job, so it is an intent, and -subtle at the end marks a quieter version of the same job, as in color.fill.brand-subtle.
The naming rule
A primitive is named for what it is. A semantic is named for what it does.
This part ends with a check that rejects a semantic colour named after a colour, and part seven extends the pattern into a grammar for every layer.
PromptAdd the semantics
Add semantic tokens in tokens/semantics/. A semantic token names a job, like "the fill of the main button", and points at a primitive. It never holds a raw value.Name colours color.<role>.<intent>, with an optional state at the end: color.fill.brand, color.fill.brand-hover, color.text.on-fill, color.border.focus. The roles are surface, fill, text and border.Cover what a simple product card needs: page and card surfaces, body and secondary text, a main button with a hover state, a subtle brand tint for tags, a link, a border and a focus ring. Add radius, spacing and type roles too.Point the brand roles at gray for now. Give every token a one-line $description saying where it's used.
What it made
Surface
surface.page→ gray.50
surface.default→ gray.0
Fill
fill.brand→ gray.900
fill.brand-hover→ gray.950
fill.brand-subtle→ gray.100
Text
text.default→ gray.900
text.subtle→ gray.600
text.on-fill→ gray.0
text.brand→ gray.900
text.link→ gray.900
Border
border.default→ gray.200
border.focus→ gray.900
Plus radius, space and type roles, each pointing at a size or font primitive.
The card, before any brand
StudioMost popular
$24per seat, per month
Unlimited projects and reviewers
A shared component library
Start a 14-day trialCompare plans
Appears when the session is done.
A replay of the session behind the starter commit “Add semantic tokens”, with its excerpts trimmed.A semantic points at a primitivetokens/semantics/color.json
"color": { "$type": "color", "fill": { "brand": { "$value": "{color.gray.900}", "$description": "The main button: the one thing to press first." }, "brand-hover": { "$value": "{color.gray.950}", "$description": "The main button under the pointer." } }}
The braces make a A token whose value is another token's name in braces, such as {color.gray.900}, so it follows that token when it changes.. {color.gray.900} means whatever value that primitive holds, so the semantic has no value of its own to go stale.
Shapes get roles the same way. radius.control rounds buttons, inputs and tags, radius.surface rounds cards and panels, and radius.pill rounds a shape's ends fully.
Every semantic that will carry a brand points at grey for now, so the card reads as ink on white until a brand claims it. That suits a white-label product, one sold to several clients under their own brands. The $description on each token is for the next person, or the next agent, deciding whether a new screen should use it.
In Figma, a variable collection called Semantics
A Semantics collection where every variable is an alias, color/fill/brand pointing at color/gray/900.
Name
Value
color/fill/brand
color/gray/900
color/fill/brand-subtle
color/gray/100
color/text/default
color/gray/900
color/text/on-fill
color/gray/0
color/border/default
color/gray/200
A second collection whose variables are aliases of the primitives, never raw colours. Screens and components get their colours from this one. Give each variable a code syntax for the web, var(--color-fill-brand), and on a paid plan Dev Mode shows developers the name the code uses.
A build that copies values breaks the day one token reads another
Run the build at this point and Style Dictionary writes each semantic as a copy of its value, so --color-fill-brand comes out as #2d2e30, the same hex as --color-gray-900, with nothing left to say the two are related.
With two layers nothing breaks yet, because a brand re-points semantics and screens read semantics directly. The trouble starts the day one token reads another that a brand has changed, and every component token does that. Both systems I built asked their build for references and still shipped copies, because the hand-written code that produced their CSS wrote each token's final value whatever the setting said. In one of them, a second brand turned the brand fill orange and every main button stayed ink, because the button's own token was a copy of the old fill.
Style Dictionary's outputReferences option writes var(--color-gray-900) where it would copy the hex. A page picks a brand with an attribute, so data-brand="grove" on a card makes that card and everything inside it Grove. In CSS, :root is the element that holds the whole page, and [data-brand] matches any element that carries the attribute. A CSS variable is declared where the file gives it a value, inside a block headed by the elements it applies to, so :root { --color-fill-brand: var(--color-gray-900); } declares the brand fill for the whole page.
A CSS variable that reads another is worked out on the element where it is declared, and the elements inside inherit the result. Declared only on :root, a token that reads another is worked out once, for the page. A card that names a different brand still gets new values for the tokens its brand file sets, but every token that only reads them keeps the page's result. The button's own background, later in this part, is one of those. Declared on [data-brand] as well, those tokens are worked out again on the card. In the other system I built, the shadows were declared on the page alone, so each brand folder repeated the same nine shadow tokens word for word only to have them worked out again with its colour.
References off, which is Style Dictionary's default. Every token is written as its value, so --button-background holds the hex of the neutral fill.
✖ Every semantic and component token in dist/tokens.css is a var() reference
--button-background is baked to #2d2e30 under :root, [data-brand]. A brand that re-points what it reads will not reach it.
One of the 43 tokens it finds. It prints the first five and counts the rest, this one among them.
The same token files built three ways, on a Harbor page with a Grove card inside. Only one build gets the Grove button right.
The next prompt asks for both.
PromptKeep references
Change the build so semantic tokens stay references in the CSS: --color-fill-brand should come out as var(--color-gray-900), not as a hex value.Put primitives on :root. Put semantics on :root and also on [data-brand], so a brand set on any element re-resolves them there.Show me a few lines of dist/tokens.css before and after.
What it made
Before, a copy
--color-gray-900#2d2e30
--color-fill-brand#2d2e30Copied
Same hex, no link. Change the grey and the brand fill never hears.
After, a reference
--color-fill-brandvar(--color-gray-900)
--color-gray-900#2d2e30
Declared on :root, [data-brand], so a brand on any element works it out again there.
Appears when the session is done.
A replay of the session behind the starter commit “Build CSS that keeps references”, with its excerpts trimmed.
Decision
Keep every reference in the built CSS
Chose
Every semantic and component token is built as var() pointing one layer down, and declared on :root and on [data-brand].
Trade-off
The CSS is longer, and the browser's inspector shows a chain of names before it shows a colour.
In Figma, a variable collection called Semantics
Two Semantics variables, one an alias of color/gray/900 and one holding the pasted hex #2D2E30.
Name
Value
color/fill/brand
color/gray/900
color/fill/brand-pasted
#2D2E30
This is the difference between setting a variable to another variable and pasting its hex. Both look the same today, and only the alias follows when the primitive changes.
A new brand is one file of re-pointed semantics
With references kept, a brand is a file that re-points the few semantics that carry the brand. It adds no new tokens and copies none of the semantics it leaves alone.
PromptAdd two brands
Add two brands, Harbor (blue) and Grove (green), as one file each in tokens/brands/. A brand file only re-points existing semantic tokens at different primitives. It adds nothing new.The build should find brands by reading that folder, so adding a brand never means editing code. Write each brand as a [data-brand="name"] block after the semantics.
What it made
tokens/brands/harbor.jsonHarbor
fill.brand→blue.600
fill.brand-hover→blue.700
fill.brand-subtle→blue.50
text.brand→blue.700
text.link→blue.600
border.focus→blue.600
tokens/brands/grove.jsonGrove
fill.brand→green.600
fill.brand-hover→green.700
fill.brand-subtle→green.50
text.brand→green.700
text.link→green.600
border.focus→green.600
Six re-pointed semantics each, from the neutral grey to the brand's ramp. Nothing else in either file.
Appears when the session is done.
A replay of the session behind the starter commit “Add brands as one file each”, with its excerpts trimmed.A whole brandtokens/brands/harbor.json
The brand blocks come last because [data-brand] and [data-brand="grove"] weigh the same in CSS, so whichever comes later wins. The check the next prompt adds fails if a brand block ever moves above the semantics.
The build finds brands by reading the folder, and an agency, which adds clients as it goes, needs that most. In both systems I built, the list of brands was typed out by hand in at least seven files, from the build config and the package's exports to the theme switcher and the documentation. With the folder as the only list, a new client is a new file and a pull request anyone can review.
Harbor
Six semantics point at the blue ramp.
Grove
The same six, re-pointed at green. The foundation is untouched.
A rebrand repaints one floor.
In Figma, a variable collection called Semantics
The Semantics collection with a Harbor mode and a Grove mode. color/fill/brand is color/blue/600 in Harbor and color/green/600 in Grove, and color/text/default is color/gray/900 in both.
Name
Harbor
Grove
color/fill/brand
color/blue/600
color/green/600
color/fill/brand-subtle
color/blue/50
color/green/50
color/text/link
color/blue/600
color/green/600
color/text/default
color/gray/900
color/gray/900
A brand file is a mode. Rename the Value mode to Harbor, add a Grove column, point the brand rows at each ramp, and leave every other row aliased as it was. Modes need a Professional, Organization or Enterprise plan, or Figma's Education plan, with up to 10 per collection on Professional and 20 on Organization.
A demo page and six checks catch a broken rule before a screen shows it
The next prompt puts a brand inside a brand on a demo page, and adds a script that fails when one of six rules breaks.
PromptAdd a demo and a check
Add demo/index.html with the same pricing card three times, side by side: Harbor, Grove, and a Grove card inside a Harbor panel. The card shows a plan name with a "Most popular" tag, a short description, a price, three features with check marks, a main button and a link to compare plans. Its CSS reads semantic tokens only. Add npm run demo to build and open it.Then write scripts/check.js for npm run check. It should print a plain message and fail when:1. a colour value appears anywhere outside tokens/primitives2. a semantic or brand token points at anything but a primitive3. the demo CSS reads a primitive4. a brand file sets a token that doesn't exist (suggest the closest name)5. a semantic in dist/tokens.css is a raw value instead of var()6. a semantic is declared without the [data-brand] scope
This is the prompt with two jobs, because the check needs the demo to have something to read.
What it made
localhost/demo/
Harbor
StudioMost popular
$24per seat, per month
Unlimited projects and reviewers
A shared component library
Start a 14-day trialCompare plans
Grove
StudioMost popular
$24per seat, per month
Unlimited projects and reviewers
A shared component library
Start a 14-day trialCompare plans
Grove inside Harbor
A Harbor link, for comparison
StudioMost popular
$24per seat, per month
Unlimited projects and reviewers
A shared component library
Start a 14-day trialCompare plans
Colour values appear only in tokens/primitives
Semantic and brand tokens point at primitives only
Demo CSS reads no primitives
Brand files only set semantic tokens that exist
Every semantic in dist/tokens.css is a var() reference
Semantics are declared on :root and [data-brand], before the brands
Appears when the session is done.
A replay of the session behind the starter commit “Add a side-by-side demo and a check script”, with its excerpts trimmed.
npm run demo builds the tokens and opens the page through Vite, a small development server the agent added for it. Run it yourself in a second terminal window, so the agent keeps the first. Cmd+N opens one in Terminal on a Mac, and Ctrl+Shift+N in Windows Terminal.
cd design-system-starternpm run demo
The page shows the card three times. Harbor's is blue and Grove's is green, and the third comes out green too, button and link included, inside a panel whose own link stays Harbor blue. The server runs until you press Ctrl+C in that window. Vite keeps serving the token file it read first, so after the agent rebuilds the tokens, press Ctrl+C and run npm run demo again. If the agent starts the demo itself, its session waits on the server, so stop it and tell the agent you will run the demo.
Break a rule and the check says which one, and where. Misspell a token in a brand file and, at this step, it answers with tokens/brands/grove.json: color.fill.brand-hovr is not a semantic token. Did you mean color.fill.brand-hover?Checks 5 and 6 read the built CSS instead of the token files, so a build that ignores its own setting still fails.
The rules file holds the decisions an agent cannot guess
Every section above is a decision, and an agent that has not been told a decision will make a different one next week. Part two started the rules file, AGENTS.md, with how to work in the repository. The decisions about tokens go under those rules.
PromptAdd the token rules
Add the token rules to AGENTS.md, after the ones on how to work. Keep them short:- the layers, and what each one may point at- the naming pattern for semantic colours- raw values live only in primitives- a brand is one file in tokens/brands, and its name appears nowhere elseSay which of these the check enforces.
What it made
How to work, and the token rulesAGENTS.md
Layers, and what each may point at
npm run check enforces everything from here down.More than the check does
1Primitivesraw values, pointing at nothing
2Semanticsa job each, pointing at one primitive
3Brandsone file each, pointing at primitives, for semantics they re-point
Name the job, not the colour. color.fill.brand, never color.fill.blue.
What the check covers so far
Colour values only in primitives
Every layer points at the one below it
The naming patternno check yet
A brand's name appears nowhere but its fileno check yet
Appears when the session is done.
A replay put together from the starter commit “Add the token rules”, with its excerpts trimmed.
In the starter, the file claims more than the check does. A line at the top of the token rules says npm run check enforces “everything from here down”, which takes in the naming pattern and the brand rule, and nothing checks those yet. Only two rules have a check behind them, colour values only in primitives and every layer pointing at the one below. Read AGENTS.md under Files changed as well as the agent's summary, because the next session reads only the file. If yours makes the same claim, merge it as it is and stay in step with the starter. The last prompt in this part gives both rules a check and corrects the line, and until then only your reading of each pull request catches a name like color.fill.blue.
A third layer pays off only when a brand restyles one component
Adding component tokens such as button.background for every component from day one is common advice, and what it costs is the number of tokens. In one library I built, the button alone had 116 tokens, and the library had more than twelve hundred across 42 components, each of which had to be named, documented and kept true. More than a third of them pointed straight at a primitive, past the layer meant to carry the brand, and no check stopped it. Terrazzo, a tool that builds tokens like Style Dictionary, advises against component tokens altogether in its style guide for design systems, and keeps to primitives and semantics.
Grove wants pill-shaped buttons, and its inputs and tags should keep their corners. With two layers the only lever is radius.control, which buttons, inputs and tags share, so pulling it rounds all of them. Answer the questions for your own project.
Will more than one brand or client use these components?
Two layers.
One product, one look. Primitives and semantics cover it.
tokens/primitives/ raw values
tokens/semantics/ jobs, pointing at primitives
tokens/components/ empty, no component restyled on its own
tokens/brands/ empty, one brand
Three questions that decide whether a project needs a component layer, and the folders each answer leaves.PromptA component layer for Button
Grove wants pill-shaped buttons. Cards, tags and inputs stay as they are.Add a component layer for Button only, in tokens/components/button.json: background, background on hover, label colour and radius, each pointing at a semantic token. Make the demo button read these tokens. Then set Grove's button radius to the pill radius in tokens/brands/grove.json.Update the check so component tokens may only point at semantics, and add the component layer to AGENTS.md.
What it made
Harbor
StudioMost popular
$24per seat, per month
Unlimited projects and reviewers
A shared component library
Start a 14-day trialCompare plans
Grove
StudioMost popular
$24per seat, per month
Unlimited projects and reviewers
A shared component library
Start a 14-day trialCompare plans
tokens/components/button.json
button.background→ fill.brand
button.background-hover→ fill.brand-hover
button.label→ text.on-fill
button.radius→ radius.control
tokens/brands/grove.json adds one line
button.radius→ radius.pill
Appears when the session is done.
The first tab replays the session behind the starter commit “Add a component layer for Button”. The second replays the same steps against a build with references turned off.
Besides the component layer, the first tab creates vite.config.js, which the prompt never asked for. It moves Vite's own build out of dist/, so a token rebuild reaches the open demo without a restart, and your agent can add the same file if you ask for it. The second tab is the failure the references section warned about, and check 5 catches it.
The resolver below opens with two layers, as the starter stood before the component layer. Pick the button's corners, switch to Grove, then turn the component layer on, and the corners pass through button.radius to the pill while the tag keeps the corners it had.
Brand
Component layer
Pick a part of the card, or a row, to follow it down.
StudioMost popular
For small teams that ship every week.
$24per seat, per month
Unlimited projects and reviewers
A shared component library
Review links with comments
Start a 14-day trialCompare plans
PartComponent, not builtSemanticPrimitiveValue
Button fill reads color.fill.brand, which points at color.blue.600 under Harbor, so it paints #226ec5.
Each part of the pricing card, followed from the token it reads down to its value.
Decision
Two layers by default
Chose
Primitives and semantics for everything, and component tokens only for a component a brand restyles on its own, Button here.
Trade-off
When a second component needs tokens of its own, someone has to notice and add its file.
In Figma, a variable collection called Button
A Button collection with Harbor and Grove modes, aliased to the semantics. button/radius is radius/control in Harbor and radius/pill in Grove.
Name
Harbor
Grove
button/background
color/fill/brand
color/fill/brand
button/label
color/text/on-fill
color/text/on-fill
button/radius
radius/control
radius/pill
A component layer is a small collection of its own, aliased to the semantics. Grove's mode changes one row, and only the button component is bound to these variables. A Grove frame picks Grove in both the Semantics and the Button collection.
A rule without a check holds only while someone reads every change
Two rules in the file still have no check, the naming pattern and the rule that no script names a brand, so the last prompt gives each of them one.
PromptCheck the naming pattern and brand names
Two rules in AGENTS.md have no check yet. Add a check for each to scripts/check.js, failing with a plain message like the others:1. a semantic colour is named color.<role>.<intent>, with an optional -state at the end. The role is surface, fill, text or border, the intent can be any name for a job, and no word in the name is a colour ramp, such as blue or green. Read the ramps from tokens/primitives/color.json, so a new one is covered too, and treat grey and gray as the same word.2. no file in scripts/ or .github/, and no config file at the root such as package.json or vite.config.js, contains a brand name as a whole word. Read the brand names from the files in tokens/brands/, and never write one into the check itself.Number the new checks 7 and 8, and leave the six that are there as they are, numbers included. Then change AGENTS.md so it says exactly which rules the check enforces. Break each rule once to show me its message, with a semantic colour named color.text.blue and a brand name in scripts/build.js, then put both back.
Beyond the two checks, the prompt asks the agent to break each rule once, because a check you have never seen fail could be passing everything. It keeps brand names out of the check itself, since scripts/check.js sits inside scripts/ and would fail on its own words. And it counts grey and gray as one word, so a British spelling cannot slip a colour into a name.
What it made
What npm run check enforcesAGENTS.md
Colour values only in primitives
Every layer points at the one below it
The naming patternNew, check 7
No script or config names a brandNew, check 8
The file lists all eight checks under their numbers in scripts/check.js, and names what is still kept by hand.
Each new rule, broken once
A semantic colour named color.text.blue
tokens/semantics/color.json: color.text.blue names the colour blue. Name the job it does instead, as in color.fill.brand.
A brand name added to scripts/build.js
scripts/build.js:52 names the brand Harbor. Brands are the files in tokens/brands/, so read them from there instead.
Both put back, and all eight checks pass.
Appears when the session is done.
A replay of the session behind the starter commit “Check the naming pattern and brand names”, with its excerpts trimmed.
The prompt left three choices open, such as whether Harbor with a capital counts as a brand name, and the agent makes each one and asks you to confirm it. The starter kept all three as the agent made them, so a yes keeps your repository in step with it. AGENTS.md now lists the eight checks under their numbers in scripts/check.js, and closes with what nothing checks, such as a raw size in the demo CSS, since check 1 only catches colours. Those stay with whoever reviews the pull request.
With the component layer and all eight checks in place, every message names what the check found and where.
The check
The mistake it catches
What it prints
1. Colour values appear only in tokens/primitives
A hex pasted into a semantic, a brand file or the demo CSS
tokens/brands/grove.json: color.fill.brand holds a colour value. Point it at a primitive instead.
2. Every token points one layer down
A semantic that points at another semantic, or a component token that skips to a primitive
tokens/components/button.json: button.background points at {color.blue.600}, which is not a semantic token.
3. Demo CSS reads no primitives
A page that asks for a blue by name
demo/demo.css reads --color-blue-600, a primitive. Use the semantic token for that job.
4. Brand files only set tokens that exist
A typo, or a brand adding a token of its own
tokens/brands/grove.json: color.fill.brand-hovr is not a semantic or component token. Did you mean color.fill.brand-hover?
5. Every semantic and component token in dist/tokens.css is a var() reference
A build that copies values
--color-fill-brand is baked to #2d2e30 under :root, [data-brand]. A brand that re-points what it reads will not reach it.
6. Semantic and component tokens are declared on :root and [data-brand], before the brands
Tokens worked out once for the page, or a brand block that comes too early
--color-fill-brand is declared under ":root" only. Anything that reads it inside a data-brand would keep the page's value.
7. Semantic colours are named color.<role>.<intent> after a job, not a colour
A colour in the name, a fifth role, or a name of the wrong shape
tokens/semantics/color.json: color.text.blue names the colour blue. Name the job it does instead, as in color.fill.brand.
8. No script, workflow or root config file names a brand
A list of brands typed into the build, the workflow or a config file
scripts/build.js:52 names the brand Harbor. Brands are the files in tokens/brands/, so read them from there instead.
The starter then moved .nvmrc to 24 in a commit of its own, so the check on GitHub runs the Node this part asked you to install. Make the same change in yours.
PromptRun the check on Node 24
Change .nvmrc to 24, so the check on GitHub runs Node 24 like this computer.
Several tools build the same tokens, but they should be edited in one place
The starter uses Style Dictionary. Other tools build the same CSS, and the right one depends on where a team edits its tokens.
Tool
Reads
Writes
Fits when
Style Dictionary
W3C token JSON
CSS, JavaScript, iOS, Android and more
One build should feed every platform.
Terrazzo
W3C token JSON
CSS, Sass, JavaScript, Swift, Tailwind and more
You want a tool built around the W3C format from the start.
Tokens Studio
Its own panel inside Figma
Token JSON, synced to a Git repository, as a folder of files on a paid plan
Designers edit tokens in Figma and own every change.
Figma
Variable collections, and W3C token JSON on import
JSON, one mode or a whole collection
Designers edit in Figma and someone exports after each change.
Plain CSS
Nothing
CSS variables, by hand
One brand, a small project, no build step.
Pick one place where tokens get edited, because two copies that both get edited drift apart. When the repository holds them, the design tool is updated from it after each change. When a design tool holds them, an export writes the JSON. Figma imports token files in the W3C format as variables, and exports a collection's modes as JSON when you right-click the collection and choose Export modes. Its import takes colours in sRGB or HSL, sizes in pixels and one font name rather than a stack, and its Variables REST API, the route to a scripted sync, needs an Enterprise plan. Part thirteen builds a copy of the starter's tokens in the shape the import takes. Until then, make the collections by hand, as the panels in this part show.
At part-3-tokens the starter holds the layers, two brands, a component layer for Button and eight checks.
The repository at part-3-tokensdesign-system-starter
tokens/ primitives/ raw values: colour ramps, sizes, fonts semantics/ jobs (color.fill.brand), each pointing at a primitive components/ button.json only: one brand restyles buttons on their own brands/ one file per brand, re-pointing semantics modes/ empty until part four locales/ empty until part fivescripts/ build.js Style Dictionary 5, keeping every reference as var() check.js eight checks that fail with a plain message.github/ workflows/ check.yml runs the build and the check on every pull requestdemo/ the same card for Harbor, Grove, and Grove inside Harborprompts/ the prompt behind each commit, in the starter onlyAGENTS.md how to work here, and the rules for tokensvite.config.js moves Vite's own build out of dist/, so a rebuild reaches the open demo
Part four gives every brand a dark mode from one more file, adds a contrast check that runs on every brand in light and dark, and turns a brand file into a template the next client can fill in.