Guide for creating and modifying design tokens.
Tokens are defined in JSON5 files in src/tokens/:
{
tokenName: {
$value: '{reference.to.other.token}', // or literal like '16px'
$type: 'color', // color, dimension, shadow, duration, etc.
$description: 'Human-readable description',
$extensions: {
'org.primer.figma': {
/* Figma export config */
},
'org.primer.overrides': {
/* Theme-specific values */
},
'org.primer.llm': {
/* LLM guidelines metadata */
},
},
},
}Use curly brace syntax to reference other tokens:
{
bgColor: {
accent: {
$value: '{base.color.blue.5}',
$type: 'color',
},
},
}Override values for specific themes in org.primer.overrides:
{
$value: '{base.color.neutral.0}',
$type: 'color',
$extensions: {
'org.primer.overrides': {
dark: '{base.color.neutral.9}',
'dark-high-contrast': '{base.color.neutral.10}',
},
},
}Add org.primer.llm to include tokens in DESIGN_TOKENS_SPEC.md:
'org.primer.llm': {
usage: ['button-background', 'interactive-element'], // Max 3 items
rules: 'Use for primary interactive backgrounds. Pair with fgColor.onEmphasis for text.',
}- usage: List 1-3 concrete use cases
- rules: Include MUST/SHOULD/Do NOT guidance when applicable
- Only add to tokens that benefit from explicit documentation
When renaming a token, keep the old name as a deprecated alias:
{
// New canonical token
ansi: {
red: {
$value: '{base.color.red.5}',
$type: 'color',
$description: 'ANSI red for errors and alerts in terminal output',
$extensions: {
/* figma, overrides, etc. */
},
},
},
// Deprecated alias pointing to new token
color: {
ansi: {
red: {
$value: '{ansi.red}',
$type: 'color',
$deprecated: '{ansi.red}',
$description: 'Deprecated. Use ansi.red instead.',
$extensions: {
'org.primer.figma': {
/* keep for Figma backward compat */
},
},
},
},
},
}Key rules for deprecated aliases:
$valuereferences the new canonical token$deprecatedcontains the new token path (same as$value)$descriptionsays "Deprecated. Use {new.path} instead."- Keep
org.primer.figmaon aliases for Figma backward compatibility - Do NOT add
org.primer.overrideson aliases (overrides live on canonical tokens only) - Do NOT add
org.primer.llmon aliases
Functional color token groups use domain-specific prefixes:
| Group | CSS pattern | Example |
|---|---|---|
bgColor.* |
--bgColor-* |
--bgColor-accent-emphasis |
fgColor.* |
--fgColor-* |
--fgColor-danger |
borderColor.* |
--borderColor-* |
--borderColor-default |
ansi.* |
--ansi-* |
--ansi-red |
prettylights.syntax.* |
--prettylights-syntax-* |
--prettylights-syntax-keyword |
Deprecated prefixes (still emitted as var() aliases):
--color-ansi-*→ use--ansi-*instead--color-prettylights-syntax-*→ use--prettylights-syntax-*instead
-
Add to the appropriate file in
src/tokens/:base/- Primitive values (raw colors, sizes)functional/- Semantic tokens (bgColor, fgColor, etc.)component/- Component-specific tokens
-
Include required fields:
$value,$type -
Add
$descriptionfor non-obvious tokens -
Add
org.primer.llmif it should appear in LLM guidelines -
Run:
npm run lint && npm run test && npm run build
When you remove or rename tokens in src/tokens/, you must document them in src/tokens/removed.json.
src/tokens/removed.json is a flat JSON object. Each key is the source token path (dot-separated, matching the nested key structure in the JSON5 source files). The value is either:
null— token was fully deleted with no replacement"new.token.path"— token was renamed/replaced (points to the new name)
If you removed fgColor.onInverse and renamed bgColor.accent → bgColor.accent.default, add:
{
"fgColor.onInverse": null,
"bgColor.accent": "bgColor.accent.default"
}Token paths come from the nested keys in the JSON5 source files, joined with .. For example, this token in src/tokens/functional/color/fgColor.json5:
{fgColor: {muted: {$value: '...', $type: 'color'}}}has the path fgColor.muted. The file name/location does not matter — only the nested object keys matter.
- Add your entries to
src/tokens/removed.json(don't overwrite existing entries) - Every token path you delete or rename must have an entry
- Use
nullfor deletions, use the new token path string for renames