Topic 4 of 5 · 5 min read
Making a design system agent-readable
Goal: Write the instruction file and component inventory a coding agent needs to build screens only from existing tokens and components.
A coding agent builds with what it can find. If your tokens, components and rules are easy to find and exact, it reuses them. If they are not, it invents its own.
Check yourself · 1 of 3
A coding agent keeps adding hard-coded colours to new screens. What is the most direct fix?
Tools such as Claude Code, Cursor, Copilot and Codex read your repository before they write. They do not know your design system exists unless the repository says so. Ask one for "a settings screen" with no guidance and you will often get new hard-coded colours, a new modal and a fourth button style.
Why it matters
Agents write fast, so drift grows fast. Ten screens in an afternoon can add ten small deviations. Fixing them later costs more than telling the agent the rules up front.
How to do it
- Keep tokens in a machine-readable file such as the W3C design-token JSON, built into CSS variables or a theme object. One source, generated outputs.
- Write a component inventory. A short list of every component: name, import path, one line on when to use it, and when not to. Link each to its docs page.
- Write the instruction file the agent reads. Claude Code reads
CLAUDE.md, Codex and others readAGENTS.md, Cursor reads its rules files. Say: build only from the tokens and components listed; never write raw colours, spacing or font sizes; if nothing fits, stop and ask rather than create a component. - Give it a check it can run. A lint rule or script that fails on raw hex values and unknown imports. Agents follow rules they can test.
- Put examples in the repo. One finished screen that uses the system correctly is worth more than a paragraph of rules.
Before and after
Before, the instruction file says: "Follow our design system." The agent does not know where it is.
After:
## UI rules
- Import components only from `@acme/ui`. The list is in `docs/components.md`.
- Use tokens from `tokens/tokens.json` (CSS vars `--color-*`, `--space-*`). No raw hex, no px values.
- Need something not listed? Stop and ask. Do not create a new component.
- Run `pnpm lint:ui` before finishing; it must pass.
What goes wrong
- A long rulebook. Agents drop details from long files; keep it short and testable.
- A stale inventory. The agent trusts the list. A deleted component still listed gets imported.
- Rules with no check. "Never use raw colours" without a lint rule is a hope.
Examples
A component inventory entry
### Dialog
Import: `import { Dialog } from "@acme/ui"`
Use for: confirmations and short forms that block the page.
Do not use for: errors (use `InlineAlert`) or long content (use a page).
Docs: `docs/components/dialog.md`
Four lines tell an agent what to import, when it applies and what to pick instead.
A rule that is checked
Rule: "No raw hex colours." Check: a lint script pnpm lint:ui that fails if a .tsx file contains a # followed by six hex characters outside the tokens folder. The agent runs it, sees the failure with a file and line, and fixes it.
Key points
- Agents only reuse what they can find: tokens, components and rules must be in the repository.
- Keep tokens in one machine-readable file and generate CSS or theme outputs from it.
- A component inventory lists name, import path, when to use and when not to use each component.
- Tell the agent to stop and ask when nothing fits, instead of creating a new component.
- Back each rule with a lint or script the agent can run, and keep the instruction file short.
Common mistakes
- Writing "follow the design system" in the instruction file with no tokens, inventory or paths.
- Leaving removed or renamed components in the inventory, so agents import things that no longer exist.
- Stating rules the repository cannot check, then reviewing violations by eye.
- Letting the agent create a new component when nothing fits, instead of telling it to stop and ask.
Check yourself · 2 of 3
What should an agent do when no listed component fits the screen it is building?
Check yourself · 3 of 3
Why is a component inventory with 'when not to use' notes useful to an agent?
Practice items, not counted towards your mastery.
Start here
- Design Tokens Format Module (W3C Design Tokens Community Group) (opens in a new tab)StandardFree
The draft format for tokens: $value, $type, groups and aliases, so tools and agents read the same file.
- Guide to variables in Figma (Figma Help) (opens in a new tab)DocsFree
How colour, number and string variables, collections and modes work in a design file.
- Design Systems 101 (NN/g) (opens in a new tab)ArticleFree
Plain definitions of a design system, its parts and why teams keep one.