Exporting Figma Variables to Production Token Pipelines
Bridge design decisions between Figma and code so teams stop duplicating brand context.
Exporting Figma variables to production takes engineering work in three stages, which are define, export, and transform. When each stage works, design decisions become machine-readable context that developers, production tools, and AI coding agents can share. The goal is not merely a cleaner handoff, but a maintained source of brand decisions that prevents each contributor from reconstructing those decisions independently.
Why the Figma-to-production token gap keeps reopening
A button still uses the old color weeks after a brand refresh was approved in Figma, because the update requires finding hardcoded values in fourteen files. What should have been a small change becomes a three-day update, with opportunities for regressions along the way.
Visual decisions live in Figma, while their production equivalents live in code, with no machine-readable bridge between them. Shared folders, Slack messages, and nightly sync scripts leave people responsible for noticing changes and carrying them across that boundary. These workarounds move information without removing the need for manual coordination. As long as components contain copied values rather than references to shared decisions, the gap can reopen after every update.
An agent without current brand context can generate plausible UI while reproducing none of the approved decisions behind it. The consistency problem therefore grows with agent sessions, generated components, and automated code change requests, not just team size. Both human and automated contributors need the same foundation, which is a machine-readable source of truth they can read when they work.
What design tokens actually are and the three-tier hierarchy they require
A design token is a named design decision stored as a key-value pair. Components and tools reference its name rather than copying its value, allowing an update to propagate through those references. Figma variables provide the right foundation because they are typed, support aliases, and hold different values for different modes. A variable declared as COLOR accepts only color values, a type boundary that makes downstream transformation reliable by making the value’s meaning explicit.
Styles serve a different purpose. They hold static values and retain a role for composite typography definitions that variables cannot yet fully express. Variables suit color, spacing, border radius, opacity, and component-level toggles.
The token hierarchy has three tiers, which are primitives, semantics, and optional component tokens. Primitives contain raw values named by scale position, while semantics alias those values under names that express purpose. Component tokens exist only where a component needs a distinct decision, and they alias semantics. The chain button.background.primary → color/brand/primary → color/orange/600 shows that separation. Bypassing the semantic tier removes the intent that makes theming understandable.
Modes belong in semantic collections. Every variable in a collection shares its mode set, so switching a frame’s mode can change its resolved values without changing its components. Keeping primitives free of mode variation preserves an auditable base.
Stage one: defining variables in Figma so the export is clean
Start by auditing the codebase for hardcoded values, CSS custom properties, SCSS variables, and JSON theme keys. This inventory identifies the existing sources of design decisions before they are recreated in Figma. Build primitives first, then semantic aliases, and finally component variables where needed. Working in the reverse order leaves semantic tokens with no valid targets and can lead to duplicate tokens or broken references.
Collection boundaries matter for the same reason. Animation tokens, including duration and easing, belong in a separate collection because mixing them with color and spacing creates mode conflicts. Names also need a consistent delimiter. Spaces can become broken CSS custom property names, while dots introduce delimiter ambiguity in Style Dictionary. It is safer to use slash-separated groups such as gray/50, space/8, and font/size/16.
Semantic naming makes this structure readable to both developers and agents. A name such as color/surface/overlay communicates where a token belongs without requiring someone to inspect its hex value. Metadata fields including primary_purpose, when_to_use, avoid_when, and semantic_role make the remaining intent explicit. After variable setup, a coverage audit catches values that were not tokenized before those omissions become pipeline failures.
Stage two: exporting variables as W3C DTCG-compliant JSON
The export contract should be W3C Design Tokens Community Group format. The W3C Design Tokens specification reached its 2025.10 Stable release, giving the pipeline a shared format for compatible transformers. DTCG uses $type and $value fields to distinguish a token’s meaning from its stored value. A small export can have a color entry named color.orange.600, a spacing entry named spacing.4, and a semantic entry named color.brand.primary. Their values represent the raw color, the spacing measurement, and an alias to the primitive respectively.
The API route suits teams with engineering resources and automation requirements. Figma’s REST API exposes variables, and a script using FigmaAPI can authenticate with a personal access token stored in an environment variable. A conversion function such as tokenFilesFromFigmaVariables then converts the way Figma stores variables. That conversion must handle name normalization, type mapping, mode grouping, and alias preservation. References must remain aliases rather than being flattened into raw values, because downstream tools should control resolution.
The plugin route reduces setup work for smaller teams or early-stage pipelines. Token Exporter produces DTCG-compliant .tokens.json from Figma and supports both the Editor’s Draft and the 2025.10 Stable specification. Its tradeoff is dependence on plugin maintenance and a manual export step unless paired with GitHub sync integration.
Designers still control when changes move forward, while developers can check what they affect before merge. A GitHub Actions workflow triggered when a PR opens or updates can run transformation automatically, placing generated CSS beside the raw JSON diff for review.
Stage three: transforming tokens into platform-specific output with Style Dictionary
Style Dictionary, first built by Amazon and kept up to date as open source, turns token JSON into output for each platform. One source can generate CSS custom properties, TypeScript constants, SCSS variables, Swift color extensions, and Android XML. The transformation resolves references, converts values, and writes generated files to a build path. The resulting CSS is ready to import at the application root.
A minimal configuration needs a source glob, a platforms definition, a CSS format, and a buildPath. Within the CSS platform, transformGroup selects the relevant transforms, while files specifies the destination and the css/variables format. Built-in transform groups handle common cases. Custom transforms address needs such as kebab-case enforcement, mode-aware output, and preservation of semantic references.
A custom formatter can separate global color primitives, mode-specific semantic colors, spacing and sizing, typography utility classes, and language overrides into distinct CSS regions. A postprocessor then converts preserved aliases into CSS custom property references, normalizes spacing references, maps brand aliases, and removes duplicate declarations.
For planning, a medium token inventory is estimated to take roughly one to two weeks end to end. The benchmark includes one to two days for audit, two to three days for variable mapping, one day for export and configuration, and one day for coverage audit and cleanup. The final audit is needed because future token updates will leave any leftover hardcoded values unchanged. Checking code early in review helps keep those values from coming back.
How AI coding agents consume tokens and why semantic naming determines output quality
A production token file is also machine-readable brand context. An AI coding agent that reads it can use approved decisions instead of generating a plausible approximation from the prompt alone. A raw color tells the agent what is available, while a semantic token tells it where that color belongs. Explicit usage metadata narrows the remaining ambiguity.
Claude Code reads a project-root CLAUDE.md at the start of every conversation. With token documentation in that file, it has the success color, border radius, font family, and spacing scale before it starts to generate code. Context should still match the task. To generate components, an agent needs color, spacing, and radius, while to generate copy, it needs voice parameters. Including visual and verbal context in a shared source supports both without making every agent load every category.
Rainbrand ingests existing brand assets and exposes them as structured, versioned context through API or MCP access. Connected agents get context from one source shared by the whole team, so each developer no longer has to keep a separate CLAUDE.md or token file for every project. The distinction is between distributing copies of brand context and maintaining a source that contributors can query.
Retrieval still needs validation. After generation, a check can parse output styles and compare them against token values, rejecting hardcoded hex values or out-of-range spacing before review. This applies the same coverage discipline used during migration at the speed of automated generation.
Exposing tokens to agents via MCP and the architectural tradeoffs that follow
The Model Context Protocol makes brand context queryable at runtime. Rainbrand implements this pattern by exposing tokens, voice parameters, and asset metadata as a machine-readable resource retrievable through MCP. An MCP-compatible agent, including Claude, an editor-integrated agent, or a custom coding agent, can pull the current token set without a developer maintaining a separate configuration. For a request to update primary call-to-action buttons across brands to a 16px corner radius, the agent can retrieve tokens and component metadata, apply the change, and run regression checks. The interface connects the instruction to structured design decisions.
That connection carries a context cost. Loading many servers and their tool definitions before answering a query creates overhead that accumulates at production volumes. Anthropic engineering documented in November 2025 that replacing upfront tool definitions with code execution cut token usage by orders of magnitude on the same workflow. Agents built for a specific purpose make it clearer which servers to connect to than if every session connects to every available server. A coding agent can connect to the repository, issue tracker, and token server, with AI token costs budgeted as recurring infrastructure expense.
Security also requires an explicit boundary. MCP initially shipped without built-in authentication and added OAuth 2.1 in March 2025, while risks include tool poisoning, rug pull attacks, shadow MCPs, and prompt injection. Plans for deployment need to cover authentication and access scope. A read-only token endpoint exposes a smaller attack surface than a general-purpose server with permission to modify the design system. Its scope should allow retrieval only, even when the wider workflow can make updates.
The operational discipline that keeps the pipeline honest over time
A pipeline without maintenance drifts back toward hardcoded values and stale context. Version the token file as code so merged changes propagate automatically to downstream CI pipelines, agents, and MCP servers. The Pull Request remains the governance checkpoint. Each change becomes a reviewable diff, and each merge becomes auditable.
Coverage audits must also continue after migration. Regular scans catch newly introduced hardcoded values before they accumulate, while automated linting can flag CSS values that do not reference custom properties. Alias-chain validation and naming checks enforce the architecture alongside reviewers. Machine Experience design extends this discipline to documentation by treating agents as readers that need explicit intent. What people know needs to be written down in declarations that an automated contributor can query and use.
A second brand inherits any confusion in the primitive, semantic, and component hierarchy, and MCP exposes whatever quality already exists in the token source. The lasting shift is to treat token pipelines as brand infrastructure. Like a CI pipeline or an API, this infrastructure runs continuously, is versioned, and deserves maintenance as a first-class engineering concern.