You ask your coding agent to build another screen, and it picks a slightly different blue, padding, and font size. After a few screens, the app looks patched together and every visual fix means hunting through more code. A small design tokens file gives the agent a shared set of choices it can reuse.
Design tokens are named values for recurring visual decisions, such as your main text color or the space around a card. Put them in a file your app loads, tell the agent to use them and existing components, then review each screen as you migrate it. The file gives the agent a reference; the instruction and your review help keep it from wandering.
Why the same app starts looking different
Say you ask for a login screen, then a settings page, then a dashboard. Each request describes what the screen should do, but says little about the exact styles. The agent may choose values that look reasonable for that screen without matching the values it used elsewhere.
You end up with buttons that have different corner shapes, headings that almost match, and several blues that were all meant to be the primary color. None of those choices has to be wildly wrong for the app to feel inconsistent.
A token gives a choice a name and a job. Instead of deciding on a blue every time, the agent uses --color-primary. Instead of guessing card padding, it chooses from the spacing values you’ve already defined.
This also makes changes easier to manage. If the primary color needs to change, you can edit its token and review the places that use it, rather than searching for every occurrence of the old color. MDN explains how CSS custom properties let you define and reuse values.
Make a small tokens file
Start with roles you actually need: background, text, primary action, and danger. Add a short spacing scale, a few type sizes, and corner radii. You can expand the file when a real need appears.
Here’s a starter file called src/styles/tokens.css. The values are examples: replace them with choices that suit your app.
:root {
--color-background: #ffffff;
--color-text: #1f2937;
--color-primary: #1d4ed8;
--color-on-primary: #ffffff;
--color-danger: #b91c1c;
--space-small: 0.5rem;
--space-medium: 1rem;
--space-large: 1.5rem;
--text-small: 0.875rem;
--text-body: 1rem;
--text-heading: 1.5rem;
--radius-small: 0.25rem;
--radius-medium: 0.5rem;
}
Make sure the file is loaded by your app’s existing global stylesheet or entry point. A file that sits in the repository without being loaded won’t give your screens access to its values.
Here’s how a button can reference the tokens:
.button-primary {
background: var(--color-primary);
color: var(--color-on-primary);
padding: var(--space-small) var(--space-medium);
font-size: var(--text-body);
border-radius: var(--radius-medium);
}
Check your chosen text and background combinations for readability, including button, error, and focus states. A named token can still hold a poor color choice.
If your app already uses Tailwind, its theme variables are another way to define shared values and related utility classes. Use your project’s existing theme setup rather than maintaining a second, competing palette.
Give the agent a rule it can follow
A tokens file alone doesn’t stop new values from appearing. Put an explicit instruction in the instructions file your agent reads for the project. Adjust the path if your tokens live somewhere else:
For UI work, use the values in src/styles/tokens.css.
Do not add raw hex colors or px values outside the tokens
file. Use the existing spacing, type and radius tokens rather
than inventing new rem values for individual components.
Reuse existing components before creating new ones.
If an existing token doesn't fit, propose a token change
and explain where it will be used. Ask before adding it.
If a literal value is technically necessary, explain the
exception and ask before adding it.
That last line matters. For example, MDN's guide notes that var() can't be used in a media query, so a breakpoint width may have to stay a literal value. An absolute ban with no way to request an exception can leave the agent guessing.
Be specific about what “reuse” means in your app. If you already have a button component, tell the agent where to find it. If there’s no shared component yet, ask it to identify repeated buttons before creating one.
If you want an agent to try this on, you can try the zcode agent harness free.
Audit one screen at a time
Don’t ask for a whole-app restyle in one pass. Start with a screen you can check easily, such as settings. Ask the agent to identify values and components first, then make the smallest useful changes.
Paste this prompt and replace the bracketed screen name and file path:
Audit [screen name] for hard-coded colors, spacing,
font sizes and corner radii.
Use [path to tokens file] as the source of design values.
First, list the files and values you found, plus existing
components that could be reused.
Then update this screen only:
- Replace suitable values with existing tokens.
- Reuse existing components where appropriate.
- Keep the screen's behavior unchanged.
- Do not invent new tokens or literal style values.
- Flag anything that needs a new token or an exception.
Show me the diff and tell me what to check visually.
Do not move on to another screen until I approve.
Review the diff before accepting it. A replacement can be technically tidy and still make a screen worse: a compact label might become cramped, or a danger action might lose its distinction. Check the screen on a phone and a wider display, including hover, focus, error, and disabled states where they exist.
Once that screen looks right, repeat the process on the next one. If a shared component changes, check the other places that use it too.
If your agent runs on a GLM coding plan, here's 10% off GLM coding plans.
Catch stray hex values in the diff
From the root of a Git repository, run this after the agent changes tracked files:
git diff --no-color -- . ':(exclude)src/styles/tokens.css' \
| grep -E '^\+.*#[[:xdigit:]]{3,8}([^[:xdigit:]]|$)' \
| grep -v '^+++'
This looks for possible hex colors on added lines while excluding the example tokens file. Change the excluded path to match your project. If a line appears, inspect it: it might be a color that should use a token, or something unrelated such as a selector or comment.
This is a quick check, not a complete style audit. It won’t catch every color format, arbitrary utility class, or hard-coded spacing value. It also checks unstaged changes to tracked files; newly created untracked files and staged changes need separate review. For staged changes, use git diff --cached in the command instead. Git’s documentation explains the different diff views.
Before you accept the changes
Use this checklist for each screen:
- The tokens file is loaded by the app
- Colors, spacing, type and radii use agreed tokens
- Existing components were reused where appropriate
- New tokens or literal-value exceptions are explained
- The screen still works and looks right on a phone
- Focus, error and disabled states were checked
- Shared component changes were checked elsewhere
- The diff and any grep matches were reviewed
A token file is a starting point you can improve as the app grows. Keep the list small enough to understand, and make new values deliberate choices rather than surprises in a screen diff.
There's more on our blog for practical build notes like this one.
If this saved you time, a tip in $WURK helps us keep writing these.






Latest comments
0