Cursor rules (.cursor/rules/*.mdc): format, examples and generator
Cursor project rules are .mdc files in .cursor/rules/. Each starts with YAML frontmatter (description, globs, alwaysApply) that controls when Cursor includes it: always, when matching files are in context, when the agent decides it is relevant, or only when you @-mention it. Splitting rules by concern keeps context small and relevant.
Generate a Cursor rules (.mdc) file
Where the file goes
.cursor/rules/*.mdcin your project (subfolders allowed).- Cursor also reads
AGENTS.mdat the root and in subdirectories. - User rules (global for you) live in Cursor Settings.
How it works
alwaysApply: trueloads the rule in every chat.alwaysApply: false+globsauto-attaches it when a matching file is in context. Separate multiple globs with commas.alwaysApply: false+descriptiononly lets the agent pull it in when relevant.- No description and no globs means the rule is only used when you @-mention it.
- Files must use the
.mdcextension; plain.mdfiles in.cursor/rulesare ignored.
Tips for a good Cursor rules (.mdc)
- Keep one small always-apply rule for project-wide workflow and put stack details in glob-scoped rules.
- Keep each rule well under 500 lines.
- Reference example files with
@filenameso the agent reads a real pattern instead of a description.
Example: Next.js (App Router) + Tailwind CSS v4 + shadcn/ui
---
description: "Core rules for this project"
alwaysApply: true
---
# this project
A Next.js (App Router) + Tailwind CSS v4 + shadcn/ui project.
Stack: Next.js (App Router), Tailwind CSS v4, shadcn/ui.
## Commands
- Dev server: `npm run dev`
- Production build (also type-checks): `npm run build`
- Lint: `npm run lint`
- Add a component: `npx shadcn@latest add <component>`
## How to work in this repo
- Read the relevant files before editing. Follow the patterns already in the codebase over these generic rules.
- Make the smallest change that solves the task. Do not refactor or reformat unrelated code.
- Before saying a task is done, run the type-check, lint and tests listed under Commands and fix what you broke.
- If requirements are ambiguous, ask one clear question instead of guessing.
- Never commit secrets, API keys or `.env` files. Use env vars and keep `.env.example` up to date.
- Do not add a new dependency when the standard library or an existing dependency already covers it.
- Ask before adding, removing or upgrading any dependency.
- Ask before changing database schemas, auth, payments or CI configuration.
- Never delete files, drop data or run destructive commands (`rm -rf`, `git push --force`, `DROP TABLE`) without explicit approval.
- Keep each change under ~200 changed lines where possible; split larger work into steps.
---
description: "Next.js (App Router) conventions: Next.js App Router with React Server Components and TypeScript."
globs: app/**/*.tsx, app/**/*.ts, src/**/*.tsx, src/**/*.ts
alwaysApply: false
---
# Next.js (App Router)
- Check the Next.js major version in `package.json` before using an API; follow the docs for that version.
- Components are Server Components by default. Add `"use client"` only to the smallest leaf component that needs state, effects, or browser APIs.
- Fetch data in Server Components or Server Actions, not in `useEffect`.
- In Next.js 15+, `params`, `searchParams`, `cookies()` and `headers()` are async: always `await` them.
- Mutations go through Server Actions (`"use server"`) or `route.ts` handlers. Validate every input on the server and re-check auth inside the action.
- After a mutation, call `revalidatePath()` or `revalidateTag()` instead of forcing the whole route dynamic.
- Use `next/image` for images, `next/font` for fonts and `next/link` for internal links.
- Export `metadata` or `generateMetadata` from every page for title, description and Open Graph tags.
- Only variables prefixed `NEXT_PUBLIC_` reach the browser. Never put secrets in them.
- In Next.js 16, `middleware.ts` is renamed `proxy.ts`. Use whichever file the project already has.
## Avoid
- Do not add `"use client"` to layouts or pages just to silence an error; move the interactive part into a child component.
- Do not use the Pages Router (`pages/`) APIs such as `getServerSideProps` in an App Router project.
Docs: https://nextjs.org/docs
---
description: "Tailwind CSS v4 conventions: Utility-first styling with Tailwind CSS v4."
globs: **/*.css, **/*.tsx, **/*.vue, **/*.svelte, **/*.astro, **/*.html, **/*.blade.php, **/*.erb
alwaysApply: false
---
# Tailwind CSS v4
- Tailwind v4 is configured in CSS: `@import "tailwindcss";` plus `@theme { ... }` for design tokens. Do not create a `tailwind.config.js` unless the project already has one.
- Use theme tokens (colors, spacing) instead of arbitrary values like `w-[37px]`.
- Build responsive layouts mobile-first with `sm:`, `md:`, `lg:` prefixes.
- Extract repeated class lists into components, not `@apply` chains.
- Support dark mode with the `dark:` variant when the project uses it.
Docs: https://tailwindcss.com/docs
---
description: "shadcn/ui conventions: Copy-in React components built on Radix and Tailwind."
globs: components/ui/**/*.tsx, src/components/ui/**/*.tsx
alwaysApply: false
---
# shadcn/ui
- Before building a UI primitive, check whether a shadcn/ui component exists and add it with `npx shadcn@latest add <component>`.
- Components live in `components/ui/` and are owned code: customize them there rather than wrapping them in more layers.
- Merge class names with the `cn()` helper from `lib/utils`.
- Keep accessibility props from Radix (labels, `aria-*`, focus handling) intact.
Docs: https://ui.shadcn.com/docs
FAQ
What is the difference between .cursorrules and .cursor/rules?
.cursorrules is the legacy single file at the repo root. .cursor/rules/*.mdc is the current format, with multiple scoped rules and frontmatter.
Why is my Cursor rule ignored?
Common causes: the file ends in .md instead of .mdc, the frontmatter is malformed, or globs do not match the files in context.
Can I use AGENTS.md instead of Cursor rules?
Yes, Cursor reads AGENTS.md. Use .mdc rules when you want file-pattern scoping.
Cursor rules (.mdc) templates by stack
- Next.js (App Router) + Tailwind CSS v4 + shadcn/ui + Supabase + Zod validation Cursor rules (.mdc)
- Next.js (App Router) + Tailwind CSS v4 Cursor rules (.mdc)
- Next.js (App Router) + Tailwind CSS v4 + Prisma + Stripe payments + Zod validation Cursor rules (.mdc)
- Next.js (App Router) + Tailwind CSS v4 + Drizzle ORM + Clerk auth + Zod validation Cursor rules (.mdc)
- Next.js (App Router) + Tailwind CSS v4 + shadcn/ui + Vercel AI SDK + Zod validation Cursor rules (.mdc)
- Next.js (App Router) + Tailwind CSS v4 + Supabase + Stripe payments + Zod validation + Vitest Cursor rules (.mdc)
- Next.js (App Router) + Tailwind CSS v4 + Firebase Cursor rules (.mdc)
- Next.js (App Router) + Tailwind CSS v4 + Vitest + Playwright E2E Cursor rules (.mdc)
- React + Vite + Tailwind CSS v4 + TanStack Query + Vitest + Zod validation Cursor rules (.mdc)
- React + Vite + Tailwind CSS v4 + Supabase + Zustand Cursor rules (.mdc)
- React + Vite + Tailwind CSS v4 + Firebase + Vitest Cursor rules (.mdc)
- Astro + Tailwind CSS v4 Cursor rules (.mdc)
- SvelteKit (Svelte 5) + Tailwind CSS v4 + Supabase + Zod validation Cursor rules (.mdc)
- SvelteKit (Svelte 5) + Tailwind CSS v4 + Drizzle ORM + Vitest Cursor rules (.mdc)
- Nuxt (Vue 3) + Tailwind CSS v4 + Zod validation Cursor rules (.mdc)
- Nuxt (Vue 3) + Tailwind CSS v4 + Supabase Cursor rules (.mdc)
- Expo (React Native) + Supabase + Zod validation + Jest Cursor rules (.mdc)
- Expo (React Native) + TanStack Query + Zustand + Jest Cursor rules (.mdc)
- Node.js + Express + Prisma + Zod validation + Vitest + Docker Cursor rules (.mdc)
- Node.js + Express + Drizzle ORM + Zod validation + Docker Cursor rules (.mdc)
- Python + FastAPI + SQLAlchemy 2 + Alembic + pytest + Docker Cursor rules (.mdc)
- Python + FastAPI + LLM / agent SDKs (Python) + pytest Cursor rules (.mdc)
- Python + FastAPI + Supabase + pytest Cursor rules (.mdc)
- Python (scripts, agents, libraries) + LLM / agent SDKs (Python) + pytest Cursor rules (.mdc)
- Python + Django + pytest + Docker Cursor rules (.mdc)
- Python + Django + Tailwind CSS v4 + pytest Cursor rules (.mdc)
- Ruby on Rails + Tailwind CSS v4 + Docker Cursor rules (.mdc)
- PHP + Laravel + Tailwind CSS v4 + Stripe payments Cursor rules (.mdc)
- Go + Docker Cursor rules (.mdc)
- Rust + Axum + Docker Cursor rules (.mdc)
- Java + Spring Boot + Docker Cursor rules (.mdc)
- Flutter (Dart) + Firebase Cursor rules (.mdc)
- Flutter (Dart) + Supabase Cursor rules (.mdc)
- Swift + SwiftUI Cursor rules (.mdc)
- Unity (C#) Cursor rules (.mdc)
- Godot 4 (GDScript) Cursor rules (.mdc)
- Phaser (TypeScript web games) + Vitest Cursor rules (.mdc)
- Chrome Extension (MV3) + Tailwind CSS v4 + Zustand + Vitest Cursor rules (.mdc)
Official docs: Cursor rules docs. Last reviewed 2026-10-21.