Tokextract — reverse-engineer a SwiftUI design system
Most design-token tools go Figma → code. Tokextract goes the other way. Point it at a SwiftUI codebase and it produces three artifacts:
tokens.json — W3C DTCG 2025.10 design tokens. The canonical machine-truth source.
DESIGN.md — Google @google/design.md alpha-format brand-narrative companion. Reads like a designer wrote it.
audit.md — drift report. Magic numbers, near-duplicate clusters, off-scale values, harmonization recommendations.
The pipeline is hybrid: a deterministic AST walk does the parsing (tree-sitter-swift, 9 token categories), then a chunked LLM pass adds semantic naming and the brand-narrative prose. The values come from your code; the names and intent come from Claude.
What it extracts
| Category | Patterns |
|---|
| Color | extension Color, Color(hex:), Color(.sRGB,…), Color("Asset", bundle:), Color(.assetName), .foregroundColor(.foo) shorthand, hex byte arithmetic (0xF3 / 255), Asset Catalog .colorset walk including dark/HC variants |
| Typography | Font.custom, extension Font static lets, extension Text { textStyleX() }, custom font enums (both : String { case } and static let *Name styles), font-weight inference from PostScript suffix |
| Spacing | .padding(N), .padding(.horizontal, N), EdgeInsets, VStack(spacing:), enum Spacing { static let xs = 4 } |
| Shape / radius | .cornerRadius, RoundedRectangle(cornerRadius:style:), UnevenRoundedRectangle, Circle/Capsule/Ellipse/ContainerRelativeShape |
| Shadow | .shadow(color:radius:x:y:), extension View wrappers |
| Animation | .easeInOut, .spring(response:dampingFraction:), withAnimation, extension Animation |
| Components | ButtonStyle, ViewModifier, extension View convenience wrappers, custom View structs (with confidence tiering) |
| iOS 26 Liquid Glass | .glassEffect(), GlassEffectContainer, content-layer-violation audit flag |
| Theme injection | EnvironmentKey, EnvironmentValues extensions, @Entry macro, @Observable providers |
Plus a vendor namespace derived automatically from the target's Info.plist CFBundleIdentifier or .xcodeproj PRODUCT_BUNDLE_IDENTIFIER (multi-target-aware: skips Watch / Widget / Complications variants).
What's validated
Two real iOS apps with structurally distinct token organizations:
| Grapla (BJJ tracker) | Ocras (fasting tracker) |
|---|
| .swift files | 727 | ~250 |
| Parse time | 4 seconds | <2 seconds |
| Color tokens | 113 | 23 |
| Typography tokens | 5 | 5 |
| Total DTCG tokens | 270 | 40 |
| Harmonize recommendations | 29 (23 high-conf) | 9 (7 high) |
| DESIGN.md prose | 346 lines (BJJ-correct) | 266 lines (fasting-correct) |
| DESIGN.md lint | 8/8 ✓ | 8/8 ✓ |
Sample LLM-generated DESIGN.md from Ocras:
"Ocras is a fasting tracker. Its core job is communicating a single binary state — fasting vs. eating — at a glance, across iPhone, Apple Watch, and multiple widget families. Every design decision flows from that constraint: reduce cognitive load, maximize legibility in small viewports, and let color carry the primary status signal."
Install
From any Claude Code session:
/plugin marketplace add conorluddy/tokextract
/plugin install tokextract@tokextract
Then invoke as:
/tokextract:extract --path <swift-repo> --output <dir>
This kicks off the full 8-step pipeline (parse → normalize → plan-harmonize → harmonize → emit → plan-narrate → narrate → finalize). The host Claude session spawns Haiku/Sonnet subagents for the LLM stages — no separate API key needed.
For deterministic / CI use without LLM passes, run the bundled CLI directly:
node ~/.claude/plugins/cache/conorluddy/tokextract/1.0.0/dist/extract.js \
parse --path <swift-repo> --output <dir> --no-llm
See plugins/tokextract/README.md for the full flag reference.
Repository layout