From Figma to AI: How Design Systems Become Code Generators
Your Figma design system is full of decisions: colors,...
From Figma to AI: How Design Systems Become Code Generators
The Figma-to-code gap
Your design system lives in Figma. Your code lives in a repository. Between them is a gap filled with manual interpretation.
A designer creates a button component in Figma with a specific color, border radius, font size, and padding. A developer looks at the Figma file and writes CSS that approximates those values. An AI coding assistant generates a component and guesses at the values because it cannot see Figma.
The result: the Figma source of truth, the code implementation, and the AI-generated output are three slightly different versions of the same thing. The button is almost right. The color is close. The spacing is off by 2 pixels. Multiply this by every component on every page, and you have a design system that exists in theory but drifts in practice.
The fix is design tokens: named values extracted from Figma that become the single source of truth for design decisions. When tokens exist as files in the repo, both human developers and AI agents reference the same values. No interpretation. No approximation. No drift.
What design tokens are
Design tokens are the smallest decisions in your design system, expressed as named key-value pairs. They are not components. They are the values that components are built from.
/* tokens.css */
:root {
/* Colors */
--color-primary: #2563EB;
--color-secondary: #64748B;
--color-accent: #F59E0B;
--color-bg: #FFFFFF;
--color-surface: #F8FAFC;
--color-text: #0F172A;
--color-text-muted: #64748B;
/* Typography */
--font-display: 'Inter', sans-serif;
--font-body: 'Inter', sans-serif;
--font-mono: 'JetBrains Mono', monospace;
--font-size-xs: 0.75rem;
--font-size-sm: 0.875rem;
--font-size-base: 1rem;
--font-size-lg: 1.125rem;
--font-size-xl: 1.25rem;
--font-size-2xl: 1.5rem;
--font-size-3xl: 2rem;
/* Spacing */
--spacing-1: 0.25rem;
--spacing-2: 0.5rem;
--spacing-3: 0.75rem;
--spacing-4: 1rem;
--spacing-6: 1.5rem;
--spacing-8: 2rem;
--spacing-12: 3rem;
--spacing-16: 4rem;
/* Borders */
--radius-sm: 0.25rem;
--radius-md: 0.5rem;
--radius-lg: 0.75rem;
--radius-full: 9999px;
--border-default: 1px solid #E2E8F0;
}
Every value has a name. Every name has a purpose. When a developer or an AI agent needs to know "what color is the primary button?", the answer is var(--color-primary), not "check Figma" or "I think it is some shade of blue."
For a deeper explanation of why tokens matter for AI tools, see our design tokens guide.
Extracting tokens from Figma
Figma stores design decisions in styles and variables. The extraction process turns those Figma constructs into token files your code can consume.
Step 1: Audit your Figma styles.
Open your design system file in Figma. Check:
- Color styles: are they named consistently? (primary, secondary, accent, not "Blue 500," "Color 3")
- Text styles: do they cover all your type scales? (heading-1 through body-small)
- Effect styles: shadows, blurs
- Variables: Figma's native variables (if you use them) are the closest to tokens
Inconsistent naming in Figma produces inconsistent tokens. Fix the naming first.
Step 2: Export using Figma's API or a plugin.
Several approaches work:
Figma Variables API (recommended for modern Figma files):
// Using Figma's REST API to extract variables
const response = await fetch(
'https://api.figma.com/v1/files/FILE_KEY/variables/local',
{ headers: { 'X-Figma-Token': FIGMA_TOKEN } }
);
const { meta } = await response.json();
// Transform Figma variables to CSS custom properties
const tokens = meta.variables.map(v => ({
name: \`--\${v.name.replace(/\//g, '-').toLowerCase()}\`,
value: resolveValue(v)
}));
Token Studio plugin (visual approach):
- Install the Token Studio plugin in Figma
- Define tokens in the plugin UI (it reads your styles automatically)
- Export as JSON, CSS, or Tailwind config
- Commit the output to your repo
Manual extraction (smallest design systems):
- Open your Figma styles panel
- Document each style as a CSS custom property
- This takes 30 minutes for a small system, hours for a large one
Step 3: Choose your output format.
Tokens can be expressed in multiple formats. Choose based on your stack:
CSS Custom Properties (universal):
:root { --color-primary: #2563EB; }
Tailwind Config (if you use Tailwind):
module.exports = {
theme: {
extend: {
colors: {
primary: '#2563EB',
secondary: '#64748B',
},
fontFamily: {
display: ['Inter', 'sans-serif'],
},
borderRadius: {
DEFAULT: '0.5rem',
}
}
}
}
JSON (platform-agnostic, good for multi-platform):
{
"color": {
"primary": { "value": "#2563EB", "type": "color" },
"secondary": { "value": "#64748B", "type": "color" }
},
"font": {
"display": { "value": "Inter", "type": "fontFamily" }
}
}
Use multiple formats if needed. A build step can generate CSS, Tailwind, and JSON from a single source.
Making tokens AI-readable
Tokens in a CSS file are already useful to AI agents. But they can be more useful with context.
Add usage comments:
:root {
/* Primary brand color. Use for: CTA buttons, key links, hero accents.
Do NOT use for: body text, backgrounds, borders */
--color-primary: #2563EB;
/* Surface color. Use for: card backgrounds, modal backgrounds.
Do NOT use for: text, buttons, borders */
--color-surface: #F8FAFC;
}
When Claude or Cursor reads this file, the comments tell it not just what the value is, but where to use it. Without the comments, an agent might use the primary color for body text because it technically has the value available.
Reference tokens in CLAUDE.md:
## Visual system
Design tokens are in tokens.css. Always use CSS custom properties, never hardcoded values.
- Primary (#2563EB): CTAs, hero elements, key links only
- Secondary (#64748B): body text, captions, secondary elements
- Surface (#F8FAFC): card and modal backgrounds
- All spacing uses the spacing scale (--spacing-1 through --spacing-16)
- Border radius: --radius-md (0.5rem) for most elements, --radius-lg for cards
The CLAUDE.md provides the narrative context. The tokens.css provides the values. Together, the agent knows both what to use and why.
The pipeline: Figma to agent-generated code
The complete pipeline looks like this:
Figma Design System
|
v
Token Extraction (API / plugin / manual)
|
v
Token Files (tokens.css, tailwind.config.js, tokens.json)
|
v
CLAUDE.md (references tokens, adds usage context)
|
v
.cursorrules (references tokens, adds code conventions)
|
v
AI Agent (reads all files, generates on-brand components)
Each step is automated or automatable. The designer changes a color in Figma. The token extraction updates the CSS file. The AI agent reads the new value and generates components with the new color. No manual copy-paste. No interpretation errors.
Tailwind integration
If your stack uses Tailwind CSS, tokens integrate directly into the Tailwind config. The agent generates Tailwind classes instead of raw CSS, and the classes resolve to your token values.
# In .cursorrules
## Tailwind usage
- Use Tailwind utility classes for all styling
- Colors: bg-primary, text-primary, border-primary (from theme)
- Spacing: p-4, m-6, gap-3 (from spacing scale)
- Typography: text-sm, text-base, text-lg, font-display, font-body
- Border radius: rounded-md (default), rounded-lg (cards)
- Never use arbitrary values like bg-[#2563EB]. Always use theme tokens
This rule in .cursorrules ensures that Cursor generates Tailwind classes that reference your design system, not arbitrary values that happen to match today but drift tomorrow.
Handling token updates
Design systems evolve. Colors change. Spacing scales are refined. Typography updates. The question is how updates propagate from Figma to code to AI.
Automated pipeline:
- Designer updates a color in Figma
- CI job runs on a schedule (or webhook trigger) and re-exports tokens
- Token files are updated in a PR
- Team reviews the visual change in the PR diff
- Merge updates the tokens
- AI agents load the new tokens on next session
Manual pipeline:
- Designer updates Figma and notifies the team
- Developer re-exports tokens and commits the change
- PR review catches any unexpected changes
- AI agents load the new tokens on next session
The automated pipeline is better for large teams. The manual pipeline works for small teams. Both are better than no pipeline, where token updates are discovered months later when someone notices the button is the wrong shade of blue.
Common mistakes
Mistake 1: Tokens without context. A file with 50 CSS custom properties is useful. A file with 50 CSS custom properties plus comments explaining where each one should and should not be used is powerful. Always add usage context.
Mistake 2: Too many tokens. A design system with 200 color tokens is not a system. It is a list. Consolidate to the smallest set that covers your needs. Fewer tokens means fewer opportunities for agents to pick the wrong one.
Mistake 3: Tokens in Figma only. If your tokens exist in Figma but not in your repo, AI agents cannot read them. The extraction step is not optional. Tokens must be committed, versioned files.
Mistake 4: Hardcoded overrides. Developers (and AI agents) sometimes bypass tokens with hardcoded values "just this once." The override becomes permanent. Lint for hardcoded values in CI and enforce token usage.
Mistake 5: No Figma-to-repo sync. Figma and the repo drift apart. The designer updates Figma. The developer does not re-export. The AI generates components with old tokens. Schedule regular sync checks, or automate the pipeline.
BrandMythos and design tokens
When you upload your brand to BrandMythos, we extract design tokens automatically from your sources: URLs, PDFs, and Figma files. The output includes:
- tokens.css with CSS custom properties and usage comments
- tailwind.config.js snippet with theme extensions
- tokens.json for platform-agnostic consumption
- CLAUDE.md with token references and usage rules
- .cursorrules with code conventions that reference tokens
Every output format is designed to close the gap between where design decisions are made (Figma) and where they are applied (code, AI agents, and production). No more manual translation. No more drift.
Try BrandMythos with your brand and see your design system converted into agent-ready tokens in minutes.
Stay in the loop
Get brand intelligence insights delivered
Occasional deep dives on brand systems, AI governance, and what happens when guidelines become loadable infrastructure.
No spam. Unsubscribe anytime.
Share this article
Keep reading
The ROI of Brand Governance: Building the Business Case for Consistency
Brand governance is not a design initiative
Brand governance is not a design initiative
brandmythos.comThe ROI of Brand Governance: Building the Business Case for Consistency
Apr 10, 2026
Brand Voice for AI Chatbots: Writing System Prompts That Sound Like You
Your chatbot speaks to customers more often than your...
Brand Voice for AI Chatbots: Writing System Prompts That Sound Like You
Apr 9, 2026
Brand Governance in Regulated Industries: Healthcare, Finance, and Legal
In regulated industries, off-brand AI output is not...
Brand Governance in Regulated Industries: Healthcare, Finance, and Legal
Apr 7, 2026
Ready to try it?
See your brand DNA structured for agents
Enter your URL. BrandMythos extracts voice, visuals, and rules into CLAUDE.md, design tokens, and structured graphs your tools can load.