[ documentation ]
Implementation & setup guide
Everything you need to wire Maddox into your repo, coding agents that support hooks or MCP, and CI in under two minutes.
[ 01 ]
Quick start with maddox init
Run one command at your project root. It detects your CSS token file, creates maddox.config.json, wires the Claude Code hook, adds the MCP server to .mcp.json, and never overwrites existing entries.
npx -y maddox-engine init --dry-run
npx -y maddox-engine initnpm install -D maddox-engine
# or: pnpm add -D maddox-engine[ 02 ]
How it works
Maddox scans .ts, .tsx, .js, .jsx, and .css files (skipping tests, stories, and tailwind.config.*) and classifies every literal into three buckets:
Uses a real token reference (var(--...)) or exact token value.
Within RGB distance ≤ 25 (colors) or ≤ 2px (spacing/font-size). Safe for auto-fix.
Off-system literal with no close token, or a missing required component state.
[ 03 ]
Ground truth sources
When multiple token sources are provided, Maddox merges them in strict design-to-code precedence:
Tailwind v4 & CSS :root (zero config): Supports hex, rgb(), hsl(), bare shadcn HSL triplets, and oklch().
Tokens Studio JSON (any Figma plan): Export W3C Design Tokens JSON and reference it via tokensStudio in maddox.config.json.
Figma Variables REST API (Enterprise plan): Pass --figma-file <key> with MADDOX_FIGMA_TOKEN in CI.
Scanning a live URL and the page doesn't show its tokens?
Sites built with Tailwind's @theme inline write their colours straight into the compiled CSS, so a live page can't tell Maddox which values are meant to be tokens. Paste your theme into the scan instead. You don't need to find the exact block: paste your whole globals.css and Maddox reads the @theme block or :root variables from it.
Can't find the file? Ask your coding assistant to print the CSS file that defines your design tokens, or run npx -y maddox-engine init, which finds it for you and writes it into maddox.config.json. Tailwind v3 colours in tailwind.config.js are not read by the URL scan yet.
[ 04 ]
MCP server (for any agent that supports MCP)
maddox mcp starts a local, read-only stdio MCP server so agents read your real tokens before writing styles and verify files afterward.
{
"mcpServers": {
"maddox": {
"command": "npx",
"args": ["-y", "maddox-engine", "mcp"]
}
}
}| Tool | Inputs | What it returns |
|---|---|---|
| get_design_tokens | kind? (all | color | font-size | spacing | motion), limit? | Project tokens from maddox.config.json so the agent uses real tokens before writing styles. |
| find_token | value, kind?, role? (bg | text | border) | Exact match or nearest token, token value, and suggested CSS/Tailwind fix. |
| check_code | file, content?, limit? | Line-by-line drift findings for a file on disk or proposed content before writing. |
| scan_project | paths?[], limit? | Local health score, severity counts, and top findings (capped at 500 files / 10s). |
[ 05 ]
Claude Code & Git pre-commit hooks
Both hooks run 100% locally and report only newly introduced drift (ignoring legacy values elsewhere in the file). With maddox-engine installed in the project, the Claude Code hook checks an edit in about 60ms (median 61ms, p95 64ms on an Apple M1 Pro). Running it through npx, as below, adds roughly 0.4 to 0.5 seconds for npx itself, so install it locally if you edit a lot. A Write over an already committed file takes roughly 150 to 170ms because it asks git for the committed version, and the pre-commit hook takes roughly 0.4 to 0.8 seconds depending on how many files are staged, because it does the same for each one.
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"hooks": [
{
"type": "command",
"command": "npx -y maddox-engine hook claude-code"
}
]
}
]
}
}#!/bin/sh
npx maddox-engine hook pre-commit[ 06 ]
Running scans, auto-fix & ignore comments
# 1. Check a single file (uses maddox.config.json)
npx maddox-engine check src/components/Button.tsx
# 2. Full project scan + auto-apply safe near-miss fixes
npx maddox-engine --apply-fixes
# 3. Suggest new @theme tokens for repeated unmapped colors
npx maddox-engine --suggest-tokens
# 4. Scan any live deployed URL
npx maddox-engine - ./src/app/globals.css --url https://your-site.com// maddox-ignore-next-line
const chartAccent = "#eb6834";
const brandHex = "#123456"; // maddox-ignore[ 07 ]
CI / GitHub Action
Posts a line-by-line drift summary on every pull request. Add MADDOX_API_KEY to unlock PR diff vs main (Team) and central CI rules (Scale).
name: Design Token Check
on: [pull_request]
jobs:
maddox:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: omrdev1/maddox-cli@v0
with:
target-dir: ./src
theme-css: ./src/app/globals.css
github-token: ${{ secrets.GITHUB_TOKEN }}
fail-below: "85"
# api-key: ${{ secrets.MADDOX_API_KEY }}| Input | Description |
|---|---|
| target-dir | Directory to scan. Required unless url is set. |
| theme-css | Path to the CSS file containing your @theme or :root tokens. |
| motion-tokens | Optional path to a motion-tokens JSON file. |
| states | Optional path to a state-contract JSON file. |
| tokens-studio | Optional path to a Tokens Studio / W3C Design Tokens JSON export. |
| figma-file / figma-token | Optional Figma Variables source (store token in GitHub Secrets). |
| github-token | Required for posting PR comments, usually ${{ secrets.GITHUB_TOKEN }}. |
| fail-below | Optional minimum score threshold. Omit for comment-only mode. |
| api-key | Optional Maddox Cloud key for PR diff vs main, history, and Scale central rules. |
[ 08 ]
CLI reference
| Command / Flag | Behavior |
|---|---|
| init [--dry-run] [--yes] | Auto-detects your @theme / :root CSS and wires maddox.config.json, Claude Code hook, .mcp.json, and agent rules without overwriting existing entries. |
| mcp [--root <dir>] | Starts the read-only local stdio MCP server exposing get_design_tokens, find_token, check_code, and scan_project. |
| check <file> [--stdin] [--format json] | Checks a single file (or proposed content on stdin) against maddox.config.json. Local only, zero network. |
| hook claude-code [--insist] | Claude Code PostToolUse adapter. Reports only newly introduced drift back in the same turn. |
| hook pre-commit [--all] | Blocks git commits that add new drift in staged files (--all checks all drift in staged files). |
| --project <name> | Project name. Defaults to the target directory basename, or the URL hostname in --url mode. |
| --motion <path> | Path to a JSON file of motion tokens (duration, delay, stagger, ease, spring). |
| --states <path> | Path to a component state-contract JSON file (source scans only). |
| --tokens-studio <path> | Path to a Tokens Studio / W3C Design Tokens JSON export. Overrides @theme on shared paths. |
| --figma-file <file-key> | Pull COLOR and FLOAT tokens from Figma Variables REST API (Enterprise plan + MADDOX_FIGMA_TOKEN). |
| --url <page-url> | Scan a live deployed URL instead of local source. Pass '-' as target-source-dir. |
| --exclude <glob> | Skip matching files/directories (repeatable). Also reads .maddoxignore. |
| --apply-fixes | Writes safe near-miss color, font-size, and spacing fixes back into source files. |
| --suggest-tokens [--min-uses N] | Lists repeated unmapped colors (default 5+ uses) as a ready-to-paste @theme block. |
| --fail-below <0-100> | Exit 1 if the drift health score falls below this threshold. |
| --api-key <key> | Optional: upload scan results to Maddox Cloud (or set MADDOX_API_KEY). |
[ 09 ]
Health score formula
Every scanned usage contributes deterministically to a 0–100 score:
Unrecognized values and missing component states count as 0. A clean scan with zero checks scores 100.
Colours follow the score everywhere: 85 to 100 is on system, 60 to 84 is drifting, and below 60 is off system.