Skip to content
mentoor

Design tokens to code with an agent

For engineers

Take a token file from design to production with an IDE agent: check the tokens, scope and review the agent edit, and keep the result maintainable.

The one-sentence idea: a design system only reaches production when its tokens become code that an agent reuses, so you define the tokens in a standard format, give the IDE agent the context and rules to use them, review what it changed, and then check the result for duplicated, dead or off-convention code.

Why it matters

Design tokens are named design decisions: a colour, a spacing step, a type size. When a coding agent builds a screen without them, it invents values. It writes #0B5FFF in one file and #0c60ff in another, adds a second button component, and the system you designed starts to split. Agents are fast, so the split happens in hours, not months.

This scenario follows one team through the job. Harbor Pay has a React app with CSS Modules. The designer, Lena, has a token file. The developer, Omar, uses an IDE agent (Copilot agent mode, Cursor, Claude Code in the editor and Windsurf all work this way) to turn the tokens into CSS variables and swap them into the Button and Card components.

How to do it

  1. Define and check the tokens. Keep one source of truth in the W3C design-token format ($value, $type, aliases such as {color.brand}). Ask a model to draft or extend the set, then check it yourself: contrast ratios against WCAG 2.2 (4.5:1 for normal text), names that follow one pattern, and scales without gaps or odd steps.
  2. Make the system readable by the agent. Put the rules in the instruction file the tool loads at the start of every session (AGENTS.md, or the tool's own file). List the tokens file, the component inventory and the rule "use a token, never a hex value; extend Button, never add a new button component".
  3. Scope the task and attach context. Name the files: the tokens file, the two components, the styles entry point. State what is out of scope (no new dependencies, no unrelated formatting). Read the agent's plan before you approve it.
  4. Review the edit, not the summary. An agent's message says what it meant to do. The diff and a search of the repository say what it did. Check for partial edits, such as a renamed variable that one file still spells the old way, and revert unrelated files one by one.
  5. Check maintainability. Search for helpers the codebase already has, leftover scaffolding, abstractions built for needs nobody has, and comments that no longer match the code.
  6. Govern the change. A token or component change from an agent goes through the same review as one from a person. Near-duplicate tokens are rejected, and the docs are corrected to match the real props.

Before and after

Weak prompt: "Use our design tokens in the app."

Better prompt:

Convert tokens/tokens.json into src/styles/tokens.css as CSS custom
properties named --<group>-<name> (color.brand -> --color-brand).
Then replace hard-coded colours and spacing in Button.module.css and
Card.module.css with those variables. Follow AGENTS.md.
Out of scope: new dependencies, other components, formatting changes.
When done, run: grep -rnE "#[0-9a-fA-F]{3,8}" src --include=*.css
and paste the output.

The second prompt names inputs, an output format, a boundary and a check the agent must show.

What goes wrong

  • Overclaiming. The agent says "all colours replaced" while a search still finds hex values in two other files. Ask for evidence, then run the search yourself.
  • Silent breaks. A CSS variable with a misspelt name does not raise an error. The browser drops the declaration and the button turns transparent.
  • Quiet scope creep. The agent adds a library, loosens a lint rule or skips failing tests to turn the build green.
  • Parallel systems. The agent adds PrimaryButton or color.brand-blue-2 instead of reusing what exists, and nobody notices until the next redesign.

Each of these is cheap to catch in review and expensive to catch after release.

Steps

  1. Draft the tokens and check them

    Skill: design-systems

    Lena asks a model to extend the token file with a muted text colour and a spacing scale. Before it is merged she checks contrast with a checker, confirms the names follow one pattern, and confirms every spacing step is a multiple of 4. Brand colours are defined once; other tokens alias them.

    tokens/tokens.json

    tokens/tokens.json

    {  "color": {    "brand": { "$type": "color", "$value": "#0B5FFF" },    "text": {      "default": { "$type": "color", "$value": "#1A1A1A" },      "onBrand": { "$type": "color", "$value": "#FFFFFF" }    }  },  "space": {    "2": { "$type": "dimension", "$value": "8px" },    "4": { "$type": "dimension", "$value": "16px" }  }}
  2. Write the rules the agent reads

    Skill: design-systems

    Omar adds a short component inventory and the token rule to the instruction file. The agent now sees that Button already has variants, so it has no reason to invent a new one.

    AGENTS.md

    AGENTS.md

    ## Design system- Tokens: tokens/tokens.json. CSS variables: src/styles/tokens.css.- Never write a hex colour or a pixel spacing value in a component. Use var(--...).- Components: Button (primary, secondary, ghost), Card, Modal. Extend these; do not add  new button or card components.- New tokens need a design review. Do not add near-duplicates of existing tokens.
  3. Scope the agent-mode task and read its plan

    Skill: code-ide-agents

    Omar attaches the tokens file, the two components and AGENTS.md, then states what is out of scope. Before approving, he reads the agent plan and removes any step that is not in the request.

    Agent plan before approval

    Goal: Convert tokens to CSS variables and use them in Button and Card

    1. Read tokens/tokens.json and AGENTS.md
    2. Generate src/styles/tokens.css
    3. Replace hex and px values in Button.module.css and Card.module.css
    4. Run the stylelint check
    5. Report remaining hex values found by grep
  4. Review the diff and run the search yourself

    Skill: code-ide-agents

    The agent says it replaced every colour. Omar does not rely on that. He reads the diff, looks for variable names that differ from the generated file, and runs the grep himself. Unrelated formatting changes are reverted file by file in the editor.

    Agent report and search
    1. assistant

      All hard-coded colours now use tokens.

    2. tool

      $ grep -rnE "#[0-9a-fA-F]{3,8}" src --include=*.css
      src/components/Modal.module.css:7: background: #FFFFFF;
      src/components/Toast.module.css:3: color: #1a1a1a;

  5. Check the code for maintainability

    Skill: aicode-maintainability

    Before merging, the team searches for helpers that already exist, leftover scaffolding and comments that contradict the code. The agent had written its own colour helper, although the codebase already had one. The duplicate is deleted and the existing helper is imported.

    Search for an existing helper
    $ grep -rn "hexToRgb" srcsrc/lib/colors.ts:4:export function hexToRgb(hex: string) {src/utils/color.ts:2:export const hexToRgb = (h: string) => {
  6. Govern the change and fix the docs

    Skill: design-systems

    The pull request is reviewed like any other. A proposed near-duplicate token is rejected in favour of the existing one. The generated documentation is compared with the real props, and a statement about a variant that does not exist is removed.

Skills this scenario uses

Where to study