← Back to Guides · CURSOR RULES
Cursor Rules Generator Prompts: 15 Copy-Paste Examples for 2026
Short answer: a good .cursor/rules file in 2026 is a stack of small, glob-scoped .mdc files — not one giant .cursorrules blob. Below are 15 copy-paste rule snippets across Next.js, Stripe, Postgres and auth, the mistakes that make rules useless, and a 30-second way to generate your own set instead of hand-typing these.
If you want the full philosophy first (apply modes, the always-on core, why .cursorrules is legacy), read Best Cursor Rules for Next.js and SaaS in 2026 — this post is the fast-copy companion: shorter snippets, more stacks, less explanation per rule.
What makes a good .cursor/rules file in 2026
Three things separate a rule that actually changes agent behavior from one that just burns tokens:
- It's scoped. A rule with
globs: app/api/**/*.tsonly loads when the agent touches a matching file. A rule with noglobsandalwaysApply: trueloads on every single prompt, whether relevant or not — that's expensive and it's the main reason large.cursorrulesfiles feel ignored. - It's testable. A reviewer should be able to point at a diff and say "this breaks rule 3." "Write secure code" tells the agent nothing it didn't already believe about itself. "Verify the Stripe signature with
constructEventbefore parsing the body" is checkable. - It doesn't fight the model. Rules that contradict a framework's own defaults, or that restate what the linter already enforces, get silently dropped or inconsistently applied. Save rules for decisions a linter can't make: which pattern to use, what order steps happen in, what the trust boundary is.
Project rules live in .cursor/rules/*.mdc. Each file's frontmatter has description (what it's for), globs (when it loads), and alwaysApply (force it into every prompt — use sparingly).
15 copy-paste rule snippets by stack
Adjust paths to your repo layout. Each one is intentionally under 15 lines — paste it as-is or trim further.
Next.js App Router
1. Server vs. client components
---
description: Server/client component boundary
globs: app/**/*.tsx
alwaysApply: false
---
- Components are Server Components by default. Add "use client" only for state, effects, or browser APIs.
- Fetch data in Server Components or route handlers, never in useEffect.
- Do not import a "use server" module or secrets into a file marked "use client".
2. Data fetching and caching
---
description: Data fetching and revalidation
globs: app/**/*.tsx,app/**/actions.ts
alwaysApply: false
---
- Fetch in the Server Component that renders the data, not a parent passing props down.
- Tag cached fetches and call revalidateTag after the mutation that changes that data.
- Never fetch the same endpoint twice on one page; lift it up or use React's cache().
3. Route handlers
---
description: Next.js route handler conventions
globs: app/api/**/*.ts
alwaysApply: false
---
- Validate the request body with zod before touching any service.
- Return typed JSON with an explicit status code, never an unhandled throw.
- Re-check auth/session inside the handler. Never trust a client-side redirect as the only gate.
4. Loading and error boundaries
---
description: Route-level loading and error UI
globs: app/**/page.tsx
alwaysApply: false
---
- Every route segment that fetches data gets a sibling loading.tsx.
- Every route segment that can fail gets a sibling error.tsx with a retry action.
- Do not render a blank screen while data loads; use the loading boundary, not a spinner div inside the page.
Stripe
5. Webhook signature + idempotency
---
description: Stripe webhook handlers
globs: app/api/stripe/**/*.ts,app/api/webhooks/**/*.ts
alwaysApply: false
---
- Read the raw body with request.text() and verify with stripe.webhooks.constructEvent before parsing.
- Store the event id and skip events already processed; webhooks can be delivered more than once.
- Return 200 quickly; do slow work (email, analytics) after recording the event.
6. Subscription state as source of truth
---
description: Billing state and subscription sync
globs: lib/stripe/**/*.ts,lib/billing/**/*.ts
alwaysApply: false
---
- The webhook, not the checkout success redirect, is the source of truth for subscription status.
- Store Stripe's subscription status string directly; don't invent your own enum that can drift from it.
- Never grant access on the client before the webhook has confirmed payment.
7. Checkout and pricing
---
description: Stripe Checkout session creation
globs: app/**/checkout/**/*.ts
alwaysApply: false
---
- Create Checkout Sessions server-side only. Price IDs come from env/config, never from client input.
- Pass the user and tenant id in metadata so the webhook can attribute the event without a second lookup.
- Pin the Stripe API version in one place (lib/stripe/client.ts), not per call site.
8. Secret hygiene
---
description: Stripe secret and key handling
globs: lib/stripe/**/*.ts,app/api/stripe/**/*.ts
alwaysApply: false
---
- The secret key and webhook signing secret are server-only env vars. Never import them in a client file.
- Never log full event payloads, card details, or customer PII in webhook handlers.
Postgres
9. Row Level Security
---
description: Postgres RLS on new tables
globs: supabase/migrations/**/*.sql,prisma/migrations/**/*.sql
alwaysApply: false
---
- Every new table with user data gets RLS enabled in the same migration that creates it.
- Every policy is tied to auth.uid() or a tenant id column. No "using (true)" policies.
- Add an index for every foreign key and every column referenced in a policy.
10. Migrations
---
description: Database migration conventions
globs: **/migrations/**/*.sql
alwaysApply: false
---
- Migrations are new, timestamped files. Never edit a migration that has already been applied.
- Every migration that adds a NOT NULL column either has a default or backfills existing rows first.
- Destructive changes (drop column, drop table) go in their own migration, separate from additive changes.
11. Query patterns
---
description: Postgres query conventions in app code
globs: lib/db/**/*.ts
alwaysApply: false
---
- Select explicit columns. No select("*") in app code.
- Every query that touches user data filters by tenant id, even if RLS also enforces it.
- Wrap multi-table writes in a transaction; don't rely on sequential awaits to be atomic.
12. Service-role key boundary
---
description: Supabase service-role key usage
globs: lib/db/**/*.ts,app/api/**/*.ts
alwaysApply: false
---
- The service-role key bypasses RLS. It is server-only and used only for admin tasks (migrations, cron jobs, webhooks).
- Never return a service-role client from a function a request handler calls directly on user input.
Auth
13. Session checks
---
description: Auth session verification
globs: app/api/**/*.ts,app/**/actions.ts
alwaysApply: false
---
- Every server action and route handler re-checks the session; never trust that the UI hid a button.
- Take the user and tenant id from the verified session, never from request arguments or form fields.
- A 401 for "not logged in" and a 403 for "logged in but not allowed" are different responses. Don't merge them.
14. Protected routes
---
description: Route-level auth gating
globs: middleware.ts,app/(protected)/**/*.tsx
alwaysApply: false
---
- Middleware checks session presence only; it does not decide tenant-level authorization.
- Fine-grained permission checks (can this user edit this resource) happen in the handler or query, not middleware.
- Redirect unauthenticated users to a login page that preserves the original destination.
15. Password and token handling
---
description: Credentials and token storage
globs: lib/auth/**/*.ts
alwaysApply: false
---
- Never log a password, token, or session cookie value, even at debug level.
- Hash passwords with a vetted library (bcrypt/argon2); never roll your own hashing.
- Set auth cookies httpOnly, secure, and sameSite=lax at minimum.
Common mistakes: rules too vague, rules that fight the model
- Too vague to test. "Write secure, maintainable code" is a wish, not a rule. If a reviewer can't point to the line in a diff that violates it, the agent can't either. Every rule above names a specific action (verify this, check that, never log this) for exactly that reason.
- Fighting the framework's own defaults. Telling an agent to avoid Server Components "for simplicity" means it's now fighting App Router's whole design on every file. Rules should pick between genuinely open choices, not override the framework.
- Duplicating the linter. If ESLint or TypeScript already catches it (unused vars, missing return types), a rule restating it just costs tokens on every matching prompt without changing anything the linter wasn't already going to flag.
- One file, no globs. A 300-line
.cursorruleswith no scoping loads in full on every prompt. Split it; most of those lines are irrelevant to whatever file is open. - No bad/good example where the mistake is subtle. "Validate input" is obvious enough that the agent usually does it anyway. The rules that change behavior are the ones that catch the non-obvious case — e.g., webhook idempotency, which isn't a validation problem at all.
Rules vs. agents.md vs. CLAUDE.md: quick decision
Cursor .mdc rules | AGENTS.md | CLAUDE.md | |
|---|---|---|---|
| Scope | Per-file, via globs | Whole repo, one file | Whole repo, one file |
| Tool support | Cursor only | Any agent that reads the convention (Codex, Cursor, others) | Claude Code only |
| Best for | Rules that only apply to specific paths (webhook handlers, migrations) | A single portable file when you work across multiple agent tools | Claude Code-specific conventions, plus pointers to skills/commands |
| Granularity | High — many small files | Low — one file, read in full every time | Low — one file, read in full every time |
Use .mdc rules when the guidance is path-specific (Stripe webhooks, migrations, auth routes) — that's most of what's above. Use a single AGENTS.md or CLAUDE.md for repo-wide conventions that apply no matter what file is open (code style, commit message format, which package manager to use). The two aren't exclusive: a root CLAUDE.md/AGENTS.md plus a handful of scoped .mdc files for the path-specific stuff is a reasonable default. For the fuller case on the always-on core file and how it fits an agent/skill setup, see Cursor Rules for SaaS Founders.
Generate your own in 30 seconds with our free rules generator
Hand-copying 15 snippets and editing paths for your repo works, but it's slower than ticking boxes. The Cursor Rules Generator runs in your browser: pick your framework, database, auth provider and payment stack, set a strictness level, and it outputs separate .mdc files — each with frontmatter and under 50 lines — plus the option to export the same content as a single SKILL.md or AGENTS.md instead. It grades the output with the same checks as the Rules File Grader, so you can see which generated files are still too vague before you commit them.
FAQ
Do I need all 15 of these rules? No — install the ones matching your actual stack. A Next.js + Supabase + Stripe app probably wants most of them; drop the Postgres-specific ones if you're on a different database.
Should these go in .cursor/rules/ or a root .cursorrules file?
.cursor/rules/*.mdc with globs set. A root .cursorrules file can't be scoped by path, so it either loads everything on every prompt or nothing conditionally — see Best Cursor Rules for Next.js and SaaS in 2026 for why that format is now legacy.
Can I use these same rules in Claude Code?
The content translates, but the format doesn't directly — Claude Code reads CLAUDE.md and SKILL.md, not .mdc frontmatter. The Config Converter can reshape a rules file between the two.
What if a generated rule is too generic for my codebase? Treat the generator's output as a starting draft. Edit in the specific gotcha from your last incident (the actual bug, not a generic warning), then re-run it through the Rules File Grader.
Is the rules generator free? Yes, it runs entirely in your browser with no signup — see the Cursor Rules Generator for details.
Related Tools & Agents
Generate your rule files in 30 seconds
Pick your stack, get glob-scoped .mdc files instead of typing 15 of them by hand.
Open the Cursor Rules Generator