Fixing AI Design Drift with In-Code Design Systems

Brian Caselgo watch the original →

Prevent inconsistent UI generation by embedding a design system directly into your codebase and instructing your AI agent to reference it via CLAUDE.md directives.

The Breakthrough

Design drift in AI-generated applications occurs because agents lack a shared source of truth, causing them to reinvent UI components in every session. The solution is to move design systems out of static Figma mockups and into the codebase itself, creating a live reference page that agents can query to maintain consistent styling, spacing, and component structure.

What Actually Worked

  • Centralize Design Tokens: Define colors, typography, and spacing as reusable CSS classes (e.g., bg-accent, text-ink-body) rather than hardcoding raw hex values or font sizes in components. This allows for global theme updates by changing a single definition.
  • Create a Live Documentation Page: Build an internal admin page that serves as both a visual style guide and a technical reference for the agent. This page should document component usage, variations, and provide sample code snippets for elements like buttons, forms, and Kanban listings.
  • Enforce via CLAUDE.md: Add explicit directives to your CLAUDE.md (or agents.md) file that mandate the agent check the design system before generating any UI markup. Include the URL or file path to the design system documentation within these instructions.
  • Standardize Base Styles: Avoid inline utility-class bloat for common elements like <h1> tags by baking base styles directly into the application CSS. This forces the agent to rely on the established design system defaults rather than generating ad-hoc Tailwind classes.

Context

When building internal tools with AI, agents often produce inconsistent interfaces because they treat every screen as a blank slate. By treating the design system as a first-class citizen in the repository, the agent gains a persistent mental model of the application's visual language. This approach is most effective when implemented at the start of a project, as retroactive application to existing codebases is significantly more complex.

Notable Quotes

  • "A design system is just a set of decisions that you make once so your colors, your type, your spacing, the way buttons look, the way that form fields look define those once in one place and everything else in your app pulls from that same source."
  • "Don't just blindly plug them into your agents and hope for magic to happen."

Content References

  • #ai
  • #dev-tooling
  • #ui-design

summary by google/gemini-3.1-flash-lite. probably wrong about something. check the source.