Design Systems for AI Coding Agents: How to Structure Tokens & Components

Why LLMs drift from your Figma library — and the repo-level specs that keep generated UI consistent

By Affan Bajwa · · 7 min read

Most design systems were built for human engineers reading Figma inspections and Storybook docs. When you hand that same product to an AI coding agent — whether Claude Code, Cursor, Codex, Antigravity IDE, or v0 — the interface starts drifting within a single afternoon. Slightly different grays appear in new cards, a third button variant gets invented for one modal, and dark mode breaks silently on every new table.

The agent is not ignoring your design system out of stubbornness. It is optimizing for whatever constraints are visible inside the repository right now. If your design rules live in Figma comments or a Notion wiki, they do not exist to the model.

After building modular design systems for complex FinTech and B2B products and shipping my own apps with AI-assisted workflows, I’ve found five structural habits that keep AI coding agents aligned with a design system without constant hand-holding.

The 4 Ways AI Coding Agents Silently Break a Design System

Before changing how you organize tokens or components, it helps to recognize the exact failure patterns that show up in code reviews:

Failure Pattern What the Agent Generates Root Cause Structural Fix
Hardcoded colour drift #1A202C on one screen, #181E29 on the next No single semantic token file referenced in repo rules Use role-based CSS variables and ban raw hex values in components
Duplicate primitives A brand-new ActionButton.tsx next to your existing Button.tsx Component library lacks a concise index of canonical imports Document the exact component inventory and import paths in one markdown file
Invented spacing & radii padding: 18px; border-radius: 10px; on a card in an 8px grid Tokens exist in Figma Variables but are not mirrored in CSS/Tailwind Export a small, closed spacing and radius scale directly into code
Missing non-happy states Blank white screen while loading or raw browser alert() on error Static Figma frames only showed the populated state Require empty, loading, error, and disabled patterns in component specs

1. Name Tokens by Semantic Role, Not Palette Shade

Primitive colour scales like slate-800 or blue-600 force the agent to guess which shade belongs on a card background, which shade belongs on a hover border, and which shade passes contrast on a dark surface. Every time the agent has to guess, inconsistency creeps in.

Role-based semantic tokens remove the guesswork. When a button or table cell asks for --bg-surface, --text-muted, or --signal-negative, the name itself tells the model where to use it — and automatically works across light and dark modes (the same token principle behind CapitalStake’s three dark modes).

/* tokens.css — semantic roles only inside components */
:root {
  --bg-canvas: #f7f8fc;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --border-subtle: #e5e8f0;
  --text-primary: #0d0e10;
  --text-muted: #5f6471;
  --accent-primary: #264ce0;
  --signal-positive: #15803d;
  --signal-negative: #b91c1c;
  --radius-card: 8px;
  --radius-control: 6px;
}

Keep the public token list intentionally short. A coding agent behaves far better with 18 well-named semantic tokens than with 240 overlapping utility variables.

2. Put a 1-Page DESIGN_RULES.md in the Repository

Long design-system wikis fail both humans and LLMs for the same reason: nobody reads forty pages before implementing a filter bar. Instead, commit a concise, plain-text DESIGN_RULES.md (or reference it from your repo’s agent instructions) that fits on a single screen and states hard boundaries.

# UI & Design System Rules

## 1. Tokens
- Always use CSS variables from `src/styles/tokens.css`.
- Never write raw hex colours or arbitrary Tailwind colour brackets (`bg-[#...]`) inside components.

## 2. Canonical Components (Import, Do Not Recreate)
- Buttons: `import { Button } from "@/components/ui/Button"` (`variant`: primary | secondary | ghost | danger)
- Inputs & Selects: `import { Field, Input, Select } from "@/components/ui/Form"`
- Data Tables: `import { DataTable } from "@/components/ui/DataTable"` (always uses tabular numerals)
- Modals & Drawers: `import { Dialog } from "@/components/ui/Dialog"`

## 3. Required States
- Every data view must handle: `loading` (skeleton), `empty` (clear next action), and `error` (recoverable retry).
- Every icon-only button requires an explicit `aria-label`.

## 4. Forbidden Patterns
- Do not install a second icon pack (use Lucide only).
- Do not invent new shadow levels in dark mode; use `--bg-surface` -> `--bg-elevated`.

That thirty-line file eliminates roughly 80% of UI drift across multi-file agent sessions because every prompt inherits the exact same guardrails.

3. Constrain Component APIs Instead of Allowing Freeform Styling

When a component accepts arbitrary layout and colour overrides on every call site, an agent will happily pass className="bg-blue-700 px-5 py-2.5 rounded-xl" to match a single screenshot — and immediately break visual consistency across the app.

Design component APIs like strict contracts:

This is also why building modular components first — before composing full pages — paid off so heavily in the CapitalStake Analytics redesign and when building Threshyr.

4. Document the Four Invisible States Alongside Every Figma Frame

Even with Figma MCP or direct frame exports, static artboards mostly show the happy path. In real B2B SaaS, FinTech, and regulated GovTech products, the interface lives or dies on edge cases. Before handing a flow to an AI agent, attach a four-line state note to your spec:

  1. Empty state: What appears on first visit or when a filter returns zero matches — including the button to reset filters or create the first record.
  2. Loading state: Skeleton rows matching the real table height so content does not jump when the API resolves.
  3. Recoverable error state: Inline field validation and banner copy that preserves what the user already typed (the same rule that drove completion gains in EasyBMV’s government forms).
  4. Density & overflow behavior: How long strings truncate, whether numeric columns stay right-aligned with tabular-nums, and how wide tables scroll on narrow viewports.

5. Enforce Token Discipline with Lightweight Automated Checks

Prompt instructions work most of the time, but automated checks catch the remaining 10% before anything merges. You do not need heavy infrastructure — two tiny scripts in package.json are enough:

When an agent runs your lint script and sees “Raw hex #22C55E disallowed — use var(--signal-positive)”, it fixes its own mistake on the spot without waiting for design review.

A 15-Minute Checklist to Make Your Design System Agent-Ready

Frequently Asked Questions

Why do AI coding agents ignore existing Figma design systems?

Coding agents default to whatever patterns are easiest to inspect directly in the repository. When tokens and component guidelines live only in Figma or an external wiki, the model falls back to hardcoded colours and ad-hoc wrappers.

What should go into a DESIGN_RULES.md file for AI coding agents?

Keep it to one page: the path to your semantic token file, canonical import paths for core components, required UI states (loading, empty, error, disabled), and a short list of forbidden patterns such as raw hex codes or duplicate icon libraries.

Do semantic tokens work better than primitive colour scales for LLMs?

Yes. Role-based names like --bg-surface, --text-muted, and --signal-negative remove ambiguity about where each colour belongs and keep light and dark themes automatically synchronized.

All posts

Read next

See all posts →
Figma to Code: Fullstack App in 10 Minutes From a Figma design to a deployed app with v0, Supabase, Vercel and AI coding agents Read article → Dark Mode for Data-Heavy Dashboards Surface elevation tokens, WCAG-verified chart palettes and QA checks for dark UI Read article → Designing and Building Threshyr The product and UX decisions behind an offline-first desktop time tracker Read article →

I’m open to Senior & Lead Product Design roles (remote) and select contract work.

Let’s talk