shadcn-ui

A set of Cursor rules for shadcn/ui, a collection of editable interface components built with Radix and Tailwind CSS. It explains how to add components, wrap them safely, and apply the project’s theme.

In plain words
What is it for?
Use it when building buttons, dialogs, forms, tables, tabs, and other interface elements with shadcn/ui.
Why use it?
It reduces styling inconsistencies and prevents custom changes from being overwritten when components are updated.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/nedcodes-ok/cursorrules-collection/shadcn-ui
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collection
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 761 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00761
Opus 5 $0.00000 $0.00380
Sonnet 5 $0.00000 $0.00152
Haiku 4.5 $0.00000 $0.00076

Measured 2d ago against content hash 995daa2159ef, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

shadcn-ui scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules-mdc/frameworks/shadcn-ui.mdc · 44 lines

How it starts

The opening of the file, as written. The whole thing — 44 lines — stays where its author put it; the contents beside it link to each section on GitHub.

shadcn/ui Rules

Component Usage

  • Import components from @/components/ui/, never from the underlying Radix/react-aria source directly
  • Add new components via CLI: npx shadcn-ui@latest add [component] — this copies source into your project, not a node_modules dependency
  • Do not modify files in components/ui/ directly — create wrapper components in components/ that compose the ui/ primitives. When you re-run add, your changes get overwritten
  • Check if a shadcn component exists before building custom: Button, Dialog, Sheet, Popover, Command, Table, Form, Toast, Tabs, Accordion, etc. — the library covers more than people expect
  • shadcn components are unstyled skeletons using your theme — they look broken without your tailwind config and globals.css set up

Styling

  • Use the cn() utility (lib/utils.ts) for all conditional classes — it wraps clsx + tailwind-merge so conflicting utilities resolve correctly
  • Follow the existing color convention: CSS variables in globals.css (--primary, --secondary, --muted, --destructive, --ring, etc.) mapped in tailwind.config — never use raw Tailwind colors like bg-blue-500 in shadcn components
  • Dark mode is built in via CSS variable switching — the same component renders both modes if your CSS variables are set up for both .dark and :root
  • When extending a component's style, pass className to the component root — shadcn components forward className and merge it with cn()

Forms

  • Use react-hook-form + zod + shadcn <Form> components together — FormField, FormItem, FormLabel, FormControl, FormMessage provide accessible wiring automatically
  • FormField's render prop gives you field — spread it onto the shadcn input: <Input {...field} />. Don't manually wire onChange/value
  • FormMessage renders the zod error for that field automatically — no need for custom error display logic
  • For select/combobox in forms, use shadcn Select inside FormControl — it handles the hidden input value that react-hook-form needs

Read the full file on GitHub · 44 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 44 lines · 761 tokens per session scan A 995daa2159ef

Subscribe to this mod's changes

shadcn-ui is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 761 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.