BXUP Track progress & test yourself — free
Frontend & Mobile · Playbook · Core · ~4 min read
FRONTEND & MOBILE · PLAYBOOK · CORE

Sweep Hardcoded Values to Design Tokens with Evidence

Every mature frontend leaks hardcoded hex colors, magic spacing, and one-off font sizes. An agent can find all of them in minutes and propose a token for each — but only a per-mapping evidence table, approved row by row by a human, keeps the sweep from silently repainting your product.

Tier: Core · Workflow area: Design-to-code & design systems

This playbook turns "we should really tokenize this" from a quarter-long chore into one afternoon of mechanical inventory, one agent-built mapping table, and one focused review session.

USE THIS WHEN

The sweep pays off

  • A token source of truth exists — style-dictionary JSON, a Tailwind theme, CSS custom properties — but adoption is partial.
  • Dark mode, theming, or a rebrand is coming, and every hardcoded #333 will break it.
  • You inherited screens built before the design system existed.
  • Design review keeps flagging "off-brand" colors that nobody can locate in code.
SKIP IT WHEN

It cannot pay off

  • No token source of truth exists yet. Define tokens first — a sweep needs a target vocabulary, not a wish.
  • The surface is being redesigned or deleted next quarter; you would tokenize dead code.
  • The values are intentionally off-system (a marketing splash page, a third-party embed) — mark them exempt instead.

Prerequisites

  • The token source of truth in the repo: a tokens.json consumed by style-dictionary, a Tailwind @theme block, or a theme.ts / CSS-variables file.
  • A coding agent with repo access (Claude Code, Cursor agent mode).
  • Some visual gate — Storybook, a Playwright screenshot script, or Chromatic — to prove "zero visual change" batches actually changed nothing.

The recipe

  1. Size the problem mechanically before involving a model. Counting is a job for ripgrep, not tokens:

    rg -n --no-heading \
      -e '#[0-9a-fA-F]{3,8}\b' \
      -e 'rgba?\(' \
      -e '\b\d+px\b' \
      src/ --glob '!**/tokens/**' --glob '!**/*.test.*' | wc -l
    

    Record the number. It is your progress metric and your PR-slicing guide — 900 hits means several batched PRs, not one.

  2. Load the token vocabulary into the agent. The single biggest failure mode is an agent that invents plausible-sounding tokens. Anchor it:

    Read src/design-tokens/tokens.json (style-dictionary format). Build a
    lookup of every color, spacing, radius, and typography token with its
    RESOLVED value (follow aliases like {color.brand.600}). Output the
    lookup as a table. Do not modify any files yet.
    

    Spot-check five rows against the file. If an alias resolved wrong here, every mapping downstream is wrong.

  3. Demand a mapping table with evidence — not edits. This is the heart of the playbook:

    For every hardcoded color, spacing, radius, and font-size value under
    src/features/billing/, produce a table with columns:
    file:line | code excerpt | current value | proposed token |
    token's resolved value | delta | confidence (exact/near/none).
    "exact" = resolved values identical. "near" = within 2% lightness or
    one spacing step. "none" = no token within that range — propose
    nothing, flag for design. Never round silently. Do not edit files.
    

    Sample of what a healthy table looks like:

    file:linecurrentproposed tokenresolves todeltaconfidence
    InvoiceCard.tsx:41#2563ebcolor.brand.600#2563ebnoneexact
    InvoiceCard.tsx:78padding: 18pxspace.40016px−2pxnear
    StatusPill.tsx:12#e8fff1———none
  4. Approve per mapping, not per file. Three verdicts, three speeds. Exact rows: skim and approve in bulk. Near rows: these are design decisions in disguise — an 18px padding becoming 16px moves pixels; get a designer's yes, row by row. None rows: send the list to the design-system owner; they either mint a new token or declare the value a bug.

  5. Apply in confidence-ordered batches, gated visually. Have the agent apply only approved exact rows first, then run your screenshot diff:

    Apply only the rows marked APPROVED-EXACT in mapping.md. One commit
    per component directory. Touch nothing outside those rows.
    

    The exact batch must produce a pixel-identical diff — if it does not, a "resolved value" was wrong, and you stop and re-audit step 2. Near batches land next, each with its expected visual delta named in the PR description.

  6. Lock the door behind you. A sweep without a gate decays in a month. Add stylelint-declaration-strict-value (or an ESLint rule for CSS-in-JS) so raw hex and px literals fail CI, with an explicit /* token-exempt: reason */ escape hatch for the genuinely intentional cases.

Warning

"Near" matches are where AI sweeps quietly redesign your product. A model rounding #334155 to color.gray.700 feels harmless per line — across 400 lines it is an unreviewed restyle. Every near mapping gets a human eye, no exceptions.

Tool variations

  • Claude Code: strongest for the multi-file table-then-apply loop; keep mapping.md in the repo so approvals survive across sessions.
  • Cursor: run the inventory prompt per feature directory in agent mode; its inline diff view makes the near-batch review fast.
  • style-dictionary shops: point the agent at the built platform output too (build/css/variables.css) so it maps to the names your code actually imports.
  • Tailwind projects: the sweep targets arbitrary values (bg-[#2563eb], p-[18px]) and maps them to theme utilities (bg-brand-600, p-4); the same table format applies.
  • Mobile: identical recipe against Compose (Color(0xFF2563EB) → MaterialTheme.colorScheme) or SwiftUI (Color(red:green:blue:) → asset-catalog / token extension values).

Quality check

  • Traceabilityevery changed line maps to an approved row in the table; nothing was edited "while in there."
  • Exact batch proofthe exact-confidence PR shipped with a zero-diff screenshot run attached.
  • Near-batch sign-offeach visual delta was named in the PR and approved by design, not discovered by design.
  • Residual countthe step-1 ripgrep number dropped to your target, and the remainder are tagged token-exempt with reasons.
  • Regression gatethe lint rule is merged, so the number cannot silently climb back.
Key Takeaway:

The deliverable is not the diff — it is the evidence table. An agent that must show file:line, resolved value, and delta for every proposal cannot hallucinate a token or round a color silently, and a human approving rows instead of reading diffs reviews ten times faster with more control, not less.

This is the free reading view. Open BXUP to track your progress, run the hands-on labs, and prove it with original, exam-pattern assessments.
© Anvi Innovate · BXUP — Be Exponentially Upskilled · BXUP is an independent learning platform, not affiliated with or endorsed by AWS, Microsoft, Google, NVIDIA, IBM, Salesforce, Databricks, Oracle or Anthropic. All trademarks belong to their respective owners. · bxup.in