AI guardrails for Claude Code, Cursor, and Codex

Download project rules for approved components, spacing, interactions, and review steps.

Better Design

Direct answer

AI guardrails reduce improvisation by Claude Code, Cursor, and Codex. Tests, browser checks, and human review enforce the result.

A hand-drawn workflow where improvised interface fragments pass through spacing, token, component, and review constraints to become one coherent screen.

Download the rules

Claude Code

File
better-design.md
Save to
.claude/rules/better-design.md
Download rules

Cursor

File
better-design.mdc
Save to
.cursor/rules/better-design.mdc
Download rules

Instructions guide behavior, but they do not enforce it. Use lint rules, tests, hooks, visual checks, and code review when a requirement must be guaranteed. Merge the Codex section into an existing AGENTS.md instead of replacing other project rules.

What changes when the rules are present?

The agent stops improvising local styles and starts from the product's existing system, reachable states, and review requirements.

From improvised output to a controlled interface

The same team-access task becomes easier to understand when the agent reuses the product system and names one clear outcome. This is an illustrative example, not a measured benchmark.

A hand-drawn comparison of inconsistent interface fragments without guardrails and one coherent interface with guardrails.
  • Before, repeated surfaces: The team-access task is split across overlapping cards with unrelated shapes.
  • Before, competing actions: Continue and Save compete even though only one action should complete the task.
  • Before, vague labels: The action does not explain what will be saved or what changes next.
  • After, one component language: The interface reuses one surface, one control shape, and the existing access pattern.
  • After, one primary action: Save access is the single dominant action for the team-access task.
  • After, clear outcome: The supporting copy explains who can view billing and manage the plan.

What do the guardrails constrain?

Each group turns a broad design preference into decisions the coding agent can follow and the team can review.

Start from the system

Treat the project's existing tokens and components as an allowlist before writing new UI.

  • Inspect the project for its design tokens, component library, type scale, spacing scale, radii, and shadows before styling.
  • Reuse an existing component when it already serves the interaction. Do not recreate a design-system component locally.
  • Use semantic tokens and approved variants. Do not invent raw colors, arbitrary spacing, one-off radii, or one-off shadows.
  • If the project has no visual system, establish one before polishing individual screens.

Make hierarchy and spacing explain the screen

Use purpose, priority, type, and proximity to make the reading order obvious.

  • Give each screen one primary purpose and one visually dominant action. Keep secondary actions quieter.
  • Use values from the spacing scale. Keep spacing tighter within a group and noticeably larger between groups.
  • Keep body text between roughly 45 and 75 characters per line and use balanced wrapping for headings.
  • Make distinct type roles visibly distinct. Aim for about a 25 percent size jump between adjacent roles.

Use durable interaction patterns

Prefer native behavior, explicit outcomes, and controls that work with keyboard, touch, and pointer input.

  • Use links for navigation, buttons for actions, real forms for submission, and native elements before ARIA workarounds.
  • Keep every flow keyboard-operable with a visible focus indicator and logical focus order.
  • Use at least 44 by 44 pixel hit areas on touch surfaces and at least 24 by 24 pixels for pointer input.
  • Gate hover-only styling behind hover and fine-pointer media queries. Never hide a required action behind hover.
  • Give every control a clear accessible name and every call to action a defined outcome.

Design every reachable state

A production component handles empty, loading, error, and success states instead of only the happy path.

  • Implement empty, loading, error, and success states for every component that loads or changes data.
  • Keep loading feedback next to the action that caused it and preserve useful content while background work runs.
  • Make errors answer what happened, why when useful, and what the user can do next.
  • Do not turn a failed request into a false empty state, expose internal errors, or discard user input silently.
  • During form submission, keep the original action label visible, disable repeat submission, and surface field errors beside their fields.

Build accessibility and responsiveness in

Treat contrast, focus, reflow, zoom, and reduced motion as implementation requirements.

  • Meet WCAG AA contrast floors: 4.5 to 1 for normal text and 3 to 1 for large text and non-text interface elements.
  • Never use color as the only signal. Pair it with text, shape, position, or an icon.
  • Build mobile-first and reflow instead of shrinking. The page must work at 320 pixels without page-level horizontal scrolling.
  • Do not disable browser zoom. Verify the layout with larger text and at 200 percent zoom.
  • Respect reduced-motion preferences while preserving the same content, state, and task completion path.

Review evidence before calling the UI complete

Verify the rendered interface, not only the source code or a successful build.

  • Check the rendered interface at a narrow width and a representative desktop width.
  • Complete the primary flow with keyboard only and inspect every focus indicator.
  • Test empty, loading, error, success, long-content, and reduced-motion states that the change can reach.
  • Run the project's type, lint, test, and build checks that cover the changed surface.
  • When Better Design MCP tools are available, load the relevant UI and UX principles before implementation, then run get-review-rules and check-comprehension before presenting the result.

What does the code change?

The rules prefer a known component and an outcome-specific label over a one-off control with local visual decisions.

- <button className="rounded-2xl border px-5 py-3 shadow-lg">
-   Continue
- </button>
+ <Button type="submit" variant="primary">
+   Save access
+ </Button>

Representative diff: replace a one-off control and vague label with the project component and an action that names the result.

How should an agent use the guardrails?

Use the file as the persistent baseline, then load the specific design context needed for the task.

  1. Add the project rule: Save the download at the path shown for the coding agent and commit it with the repository.
  2. Load task-specific context: Use Better Design MCP to load the active design system plus the relevant UI and UX principles before implementation.
  3. Verify the rendered result: Run the review rules, comprehension check, project checks, keyboard flow, and narrow-width browser review.

Questions

What are AI guardrails for UI?

They are durable project instructions that constrain an agent to the product's approved tokens, components, interaction patterns, accessibility requirements, and review workflow.

Do instruction files enforce the rules automatically?

No. They guide agent behavior, but they are not a policy engine. Use lint rules, tests, hooks, visual checks, and code review when a requirement must be enforced mechanically.

Can the same guardrails work with Claude Code, Cursor, and Codex?

Yes. The core rules are shared. Better Design renders them into each tool's current project-instruction format so the content stays aligned while the file location and frontmatter differ.

Where do the rules come from?

The rules are distilled from Better Design's UI and UX principle docs, including component architecture, spacing, typography, accessibility, forms, errors, navigation, responsive behavior, and microcopy.

Sources

The shared rule model is distilled from the project's UI and UX documents. The official coding-agent references define where each generated file belongs.

  • Component architecture: docs/ui/component-architecture.md
  • Spacing and layout: docs/ui/layout-spacing.md
  • Typography: docs/ui/typography.md
  • Color system: docs/ui/color.md
  • Accessibility: docs/ui/accessibility.md
  • UI polish: docs/ui/polish.md
  • Design process: docs/ux/design-process.md
  • Anti-patterns catalog: docs/ux/anti-patterns.md
  • Form behavior: docs/ux/forms.md
  • Error handling and recovery: docs/ux/errors.md
  • Interactions and accessibility: docs/ux/interactions.md
  • Navigation: docs/ux/navigation.md
  • Responsive design: docs/ux/responsive.md
  • Microcopy and content: docs/ux/microcopy.md
  • Claude Code project-rule documentation
  • Cursor project-rule documentation
  • Codex project-rule documentation