Topic 3 of 4 · 4 min read
Keeping agent UI inside the design system
Goal: Spot a diff where an agent re-implemented an existing component or hard-coded styles, and redirect it.
Left alone, an agent builds the UI in front of it from scratch; your job is to point it at the components and tokens you already have, and to catch the diff that did not use them. The result of ignoring this is a codebase where every screen has its own button.
Check yourself · 1 of 3
Why does an agent often write a new button instead of using yours?
Why it matters
An agent sees only the files it opened. If it never looked in src/components/ui, it will write a new text<button> with inline colors. The page works today. Next quarter you change the brand color and find forty places that did not follow.
How to steer it
- Tell it where components live. Put the folder, the naming rule and the "use these first" list in the project instructions file the agent reads, such as
CLAUDE.md,AGENTS.mdor Cursor rules. - Ask it to search first. "Before writing any new component, list the existing ones that could do this."
- Ban literal values. "No hex colors, no pixel values for spacing; use tokens."
- Show it a good example. One existing screen built the right way is worth a page of rules.
- Check the diff for the signs.
Signs in a diff
- New files named like ones you already have:
NewButton.tsx,Modal2.tsx. - Hex codes,
pxvalues andstyle={{ ... }}where tokens exist. - A copy of a component with one prop changed, instead of using that prop.
- A new dependency for something the system already does, such as a date picker.
Before and after
- <Button variant="primary" size="md">Save</Button>
+ <button style={{ background: "#3b6cf6", padding: "9px 17px", borderRadius: 6 }}>Save</button>
The agent swapped a design-system button for a hand-styled one that nearly matches. Redirect it with a short message:
Use Button from src/components/ui with variant="primary". Remove the inline style. If Button lacks something you need, tell me what instead of copying it.
What goes wrong
- Near-duplicates. Two components that differ by 2px are harder to fix than one clearly wrong one.
- Silent forks. The agent edits the shared component for one screen and changes every other screen.
- Rule drift. The instructions file lists components that were renamed. Keep it current.
Examples
A rule block for the instructions file
## UI rules
- Use components from src/components/ui before writing new ones.
- Colors, spacing and radii come from src/styles/tokens.css. No hex or px literals.
- Need a variant that does not exist? Stop and ask; do not copy the component.
Redirecting a duplicate
The agent adds ~~~TableV2.tsx~~~ beside an existing ~~~DataTable~~~. Reply: "DataTable already supports sorting through the sortable prop. Delete TableV2 and use DataTable." Naming the existing prop is more effective than saying "reuse components".
Key points
- An agent only knows the files it has opened, so it rebuilds components that already exist unless you point to them.
- Put the component folder and a no-literal-values rule in the project instructions file the agent reads.
- In a diff, look for hex codes, pixel values, inline styles and files that duplicate an existing component.
- When the shared component lacks something, ask the agent to say so rather than copy it.
- Check that a change did not quietly alter a shared component used by other screens.
Common mistakes
- Approving a diff because the screenshot looks right, without reading what it was built from.
- Writing "follow the design system" and never saying where it is.
- Letting the agent edit a shared component to suit one screen.
- Leaving a stale component list in the instructions file after a rename.
Check yourself · 2 of 3
Which line in a diff most clearly signals a design-system violation?
Check yourself · 3 of 3
The existing Button lacks a variant the agent needs. What is the best instruction?
Practice items, not counted towards your mastery.
Start here
- Playwright MCP server (Microsoft) (opens in a new tab)ToolFree
The common way to let an agent drive a real browser and take screenshots.
- Chrome DevTools MCP (opens in a new tab)ToolFree
Gives an agent console, network and performance data from Chrome.
- WCAG 2 Quick Reference (W3C) (opens in a new tab)StandardFree
The accessibility success criteria to check agent-built UI against.
More for this topic
- Best practices for Claude Code (Claude Code docs) (opens in a new tab)DocsFree
Explains how project instruction files steer an agent toward your conventions.
- Storybook documentation (opens in a new tab)DocsFree
A way to catalogue existing components so people and agents can find them before building new ones.