Point to an element to see the design tokens behind it.
Back to work

Primitree

A design token pipeline that checks architecture rules and generates CSS, Tailwind, and TypeScript.

My role
Creator & Maintainer
Timeline
2025 to present
Built with
  • TypeScript
  • DTCG 2025.10
  • Node.js 24
  • Turborepo
  • Figma Variables API
  • MCP
  • React 19
Primitree Playground showing token collections and configuration.
Token configuration in Primitree Playground

The system, running on this page

This is the portfolio’s own token graph, resolved by Primitree. Follow a reference from a raw value to its role in a component, then change the accent to see the page follow it. Break a rule to see the reference it loses.

Dark theme.Light theme.

Choose a detail from the site to see which tokens it uses. Arrow keys move between nodes. Enter traces the selected node.

Base

Raw values

color.brand.500#DB1834

Meaning

Shared decisions

semantic.color.accent.primary#DB1834

Component

Interface roles

component.button.accent.background#DB1834
component.inspector.label.background#DB1834
component.inspector.outline#DB1834

Base

Raw values

color.brand.700#D50A2F

Meaning

Shared decisions

semantic.color.accent.primary#D50A2F

Component

Interface roles

component.button.accent.background#D50A2F
component.inspector.label.background#D50A2F
component.inspector.outline#D50A2F

5 tokens and 4 references. 3 aliases follow this token.5 tokens and 4 references. 3 aliases follow this token.

Change the accent here. Select a token to see where it is used.

Explore the full system page, or use Inspect in the navigation to trace a value on the page itself.

When a semantic token holds a literal color

Each token source declares its layers. A layer names the roots it owns, whether it holds literals or references, and which other layers it can point at.

If a semantic layer requires references and one of its tokens holds a literal color, the build fails and names the token path.

PrimitreeRecorded CLI runs
Layer rule

meaningbase

Semantic tokens must reference the base layer.

Source tokentokens.json
semantic.action
{
  "$type": "color",
  "$value": {
    "colorSpace": "srgb",
    "components": [
      0.2,
      0.8,
      1
    ],
    "hex": "#33CCFF"
  }
}
Semantic token
semantic.action
Not referenced
color.cyan
Color value
#33CCFF
semantic.action contains #33CCFF directly, without referencing color.cyan.
primitree buildexit 1
Build stopped
PT1003semantic.action

Layer meaning does not allow this token value form.

No generated files were written.

Inspect configuration and full output

The two runs use the same configuration. Only semantic.action.$value changes.

primitree.config.ts
export default {
  "schemaVersion": 1,
  "sources": {
    "brand": {
      "type": "dtcg",
      "file": "./tokens.json",
      "architecture": {
        "layers": [
          {
            "id": "base",
            "roots": [
              "color"
            ],
            "values": "literal"
          },
          {
            "id": "meaning",
            "roots": [
              "semantic"
            ],
            "values": "reference",
            "references": [
              "base"
            ]
          }
        ]
      },
      "ownership": {
        "default": [
          "design-systems"
        ]
      },
      "outputs": {
        "directory": "./generated",
        "formats": [
          "css"
        ]
      }
    }
  }
}
tokens.json · Literal color
{
  "color": {
    "cyan": {
      "$type": "color",
      "$value": {
        "colorSpace": "srgb",
        "components": [
          0.2,
          0.8,
          1
        ],
        "hex": "#33CCFF"
      }
    }
  },
  "semantic": {
    "action": {
      "$type": "color",
      "$value": {
        "colorSpace": "srgb",
        "components": [
          0.2,
          0.8,
          1
        ],
        "hex": "#33CCFF"
      }
    }
  }
}
primitree check --format json · exit 1
{
  "schemaVersion": 1,
  "command": "check",
  "source": "brand",
  "findings": [
    {
      "findingId": "PT1003:source%3Abrand%2Ftoken%3Asemantic.action",
      "ruleId": "PT1003",
      "tokenId": "source:brand/token:semantic.action",
      "path": [
        "semantic",
        "action"
      ],
      "message": "Layer meaning does not allow this token value form.",
      "owners": [
        "design-systems"
      ],
      "disposition": "active",
      "layerId": "meaning"
    }
  ],
  "summary": {
    "active": 1,
    "baseline": 0
  }
}
primitree build · exit 1
PT1003 semantic.action: Layer meaning does not allow this token value form.
Build stopped with 1 active finding for source "brand".

Literal color: Build stopped. PT1003: semantic.action must use a reference. No generated files were written.

Output recorded from the real CLI. The browser switches between those two results.

Primitree 1.0.0-next.1

From Figma Variables to build rules

A token system runs on rules about which layers hold raw values, which must use references, who owns each token, and which aliases a change touches. I built Primitree so those rules live in configuration a build can check, and keep holding as the system changes.

It grew out of @figma-vars/hooks, which handled reading Figma Variables into React. Primitree adds the architecture checks, change reports, and generated output, split across six packages.

Configuration and change checks

Configuration for four output formats
typescript
export default defineConfig({
  schemaVersion: 1,
  sources: {
    brand: {
      type: 'dtcg',
      file: './tokens.json',
      architecture: {
        layers: [
          // holds raw values
          { id: 'base', roots: ['color'], values: 'literal' },
          // must point at base, never hold a value
          {
            id: 'meaning',
            roots: ['semantic'],
            values: 'reference',
            references: ['base'],
          },
        ],
      },
      ownership: { default: ['design-systems'] },
      outputs: {
        directory: './generated',
        formats: ['dtcg', 'css', 'typescript', 'tailwind'],
      },
    },
  },
})

Figma-export diffs match tokens on their stable Figma IDs. Matching on names would turn every rename into an unrelated deletion and addition.

For a configured DTCG source, the diff reports changed tokens, affected aliases, and policy findings.

  • Renames, moves, removals, and type changes are classified as breaking

  • --fail-on-breaking exits with code 2 so CI can block on it

  • Output as Markdown for review, or JSON for tooling

Running with --check reports missing, changed, and unexpected files without writing anything, and exits 1 on any difference. That's how CI confirms the committed tokens still match what the source produces.

Generated files need an ownership record

Each configured DTCG build writes a manifest next to its output. The next build reads that manifest and won't overwrite a listed file whose hash has changed, or touch any path the manifest doesn't list. If someone hand-edits a generated file, the build stops with an error.

Builds also stage their output before replacing anything, and keep recovery information if a run is interrupted.

Output follows DTCG 2025.10. Aliases stay as token references (they aren't flattened to values), and Figma modes map to Resolver contexts. Anything Figma-specific that the spec has no place for goes into a namespaced extension.

Figma IDs, scopes, and code syntax live under $extensions['com.primitree']. Booleans use a documented extension, since DTCG has no boolean type.

Output formats and file-safety checks

Generated formats

The configured pipeline produces four output formats:
  • DTCG 2025.10 token files plus a resolver document for contexts

  • CSS custom properties, with contexts as selector axes

  • Tailwind theme output

  • Typed TypeScript token exports

Transactional writes

  • Output staged before it replaces anything installed

  • An interrupted run leaves its backup and cleanup sidecars in place, reports every retained path, and stops before writing over them

  • The output directory must sit under the config directory and cannot contain the source file

  • File identity is recorded before a read and compared after, so a path swapped mid-read gets rejected

  • The output directory and its ancestors are rechecked during a scan, which stops if one changes underneath

Input limits

There are caps on file sizes, token file counts, directory entries, nesting depth, path length in UTF-8 bytes, and path component counts after symlink resolution. Symbolic links and special files are rejected.

Six packages, still a prerelease

Primitree is on npm as 1.0.0-next.1, a release candidate. I'm still settling the API before 1.0.

A Figma plugin exports local variables for teams without Enterprise API access, so you don't need a particular Figma plan to start.

All six packages are prereleases over a shared core, built with Turborepo on Node 24 and pnpm 11:

  • primitree for the unscoped CLI entry point

  • @primitree/core for normalization, the token graph, diffing, and API access

  • @primitree/dtcg for conversion and the CSS, Tailwind, and TypeScript emitters

  • @primitree/cli for check, build, inspect, diff, and scaffolding

  • @primitree/hooks for reading built tokens in React, or the live API with SWR

  • @primitree/mcp for serving the graph to MCP clients

The MCP server exposes the token graph through list_collections, get_token, resolve_context, search_tokens, and diff_tokens, so an agent can query tokens, resolve contexts, and diff changes.

Project notes

6 packages

CLI, token graph, DTCG emitters, React hooks, and an MCP server

DTCG 2025.10

Output follows the spec, with a documented boolean extension

1.0.0-next.1

Prerelease on npm, with the API still settling before 1.0