Some links on this page are affiliate links. We earn a commission if you click and purchase, at no extra cost to you.

developer

The Complete .cursorrules Guide: Make Cursor Do Exactly What You Want

~5,600 mo. searches · cursorrules guide

Intro
If you've been using Cursor for more than a week, you've probably noticed it doesn't always write code the way you want. It picks the wrong framework, ignores your naming conventions, or generates comments in a style that makes you cringe. The fix isn't prompting harder — it's a .cursorrules file. This guide covers everything: what .cursorrules actually does, how to write rules that stick, real examples you can copy, and the mistakes that make your rules useless. By the end, you'll have Cursor generating code that looks like YOU wrote it.
What Is a .cursorrules File and Why It Matters

A .cursorrules file is a plain text file you place in the root of your project directory. Cursor reads it automatically and treats every instruction inside as a standing order for every AI interaction in that project. Think of it as a permanent system prompt that travels with your codebase. Without .cursorrules, Cursor is a generalist. It writes JavaScript with var instead of const, adds semicolons when you hate semicolons, and structures React components however feels right in the moment. With .cursorrules, it becomes a developer who already knows your preferences. The practical impact is real. Developers who use well-crafted .cursorrules files report cutting their edit-after-generation rate by 60-70%. Instead of accepting code and then fixing 8 things, you accept code and fix 2. Over a full workday of AI-assisted coding, that's hours saved. One important clarification: .cursorrules files work at the project level. You create one per project, not one globally. If you want global defaults, Cursor has a 'Rules for AI' setting in preferences, but the .cursorrules file always takes priority when it exists in a project folder.

The Anatomy of a .cursorrules File

A .cursorrules file has no strict syntax — it's plain text. But structure matters enormously for whether Cursor actually follows your rules. Sloppy, wall-of-text rules get followed inconsistently. Clear, organized rules get followed reliably. Here's the structure that works best, broken into five logical sections: **1. Project Context (2-4 sentences)** Tell Cursor what you're building and the stack you're using. Example: 'This is a SaaS dashboard built with Next.js 14 App Router, TypeScript, Tailwind CSS, and Supabase. The target users are small business owners with no technical background.' **2. Code Style Rules** This is where most rules live. Be specific. Don't write 'write clean code.' Write 'use const instead of let unless reassignment is required. Use arrow functions for all callbacks. Never use var.' Specificity is what separates rules that get followed from rules that get ignored. **3. Architecture Rules** Tell Cursor how your project is organized. 'API calls go in /lib/api. Components go in /components. Utility functions go in /utils. Never put business logic inside a React component.' This prevents Cursor from inventing new folders or scattering code randomly. **4. Patterns to Always Use** List the patterns you want repeated consistently. Error handling patterns, loading state patterns, how you structure TypeScript interfaces, how you name things. **5. Patterns to Never Use** This section is underrated. Explicitly banning things is often more effective than describing what you want. 'Never use any as a TypeScript type. Never use inline styles. Never use class components.' Negative rules are enforced more consistently than positive ones.

A Real .cursorrules File You Can Actually Use

Here's a complete .cursorrules file for a Next.js + TypeScript + Tailwind project. Copy it, modify it for your stack, and put it in your project root: --- Project: E-commerce storefront built with Next.js 14 (App Router), TypeScript, Tailwind CSS, Prisma, and PostgreSQL. CODE STYLE: - Use TypeScript for all files. Never use 'any' type. - Use const for all variables unless reassignment is required. - Use arrow functions for all function expressions. - Use named exports, not default exports, for all components and utilities. - Always type function return values explicitly. - Use template literals instead of string concatenation. FILE AND FOLDER STRUCTURE: - React components go in /components. Subdirectories by feature area. - API logic goes in /lib/api. Never in components. - Database queries go in /lib/db. Never in API routes directly. - TypeScript types go in /types. One file per domain area. - Server actions go in /actions. COMPONENTS: - All components are functional components. Never use class components. - Props interface is always named [ComponentName]Props. - Use Tailwind for all styling. No inline styles. No CSS modules. - If a component exceeds 150 lines, suggest splitting it. ERROR HANDLING: - All async functions must have try/catch blocks. - User-facing errors display with a toast notification using the useToast hook. - Log errors with console.error, never console.log. NEVER DO: - Never use 'any' in TypeScript. - Never use inline styles. - Never use class components. - Never put database queries in components. - Never use var. - Never use default exports. --- This file is 280 words. That's roughly the right length — long enough to be specific, short enough to be fully read by the model on every request.

Rules That Actually Get Followed vs. Rules That Get Ignored

After testing hundreds of rule variations, there's a clear pattern. Here's what separates effective rules from wishful thinking: **Rules that get followed:** - Specific, binary instructions ('use const, not let') - Rules with examples ('name event handlers handleEventName, e.g., handleButtonClick') - Short, imperative sentences ('always add JSDoc comments to exported functions') - Rules in bulleted lists, not paragraphs **Rules that get ignored:** - Vague quality claims ('write clean, readable code') - Long explanations ('when you're working with components, it's important to consider...') - Rules buried in paragraphs of context - Contradictory rules (you can't say 'be concise' and 'always add detailed comments') - Rules that conflict with what the user is asking for in the moment The 'conflict' problem deserves attention. If your rules say 'never use any' but you paste in a snippet that uses any and ask Cursor to extend it, the immediate context often wins. You can work around this by being explicit in your prompt: 'Fix this without introducing any types.' Your rules set defaults; your prompts set overrides. Also, shorter rules files outperform longer ones. If your .cursorrules file is 2,000 words, Cursor will start deprioritizing rules that seem less immediately relevant. Keep it under 500 words. If you need more, consider splitting into multiple focused rule blocks with clear headers.

Advanced .cursorrules Techniques

Once you have the basics working, these techniques take .cursorrules from useful to genuinely impressive: **Include a mini-glossary of your project's terminology** If your app has specific domain terms — 'a Member is different from a User, a Subscription is different from a Plan' — define them in your rules file. This prevents Cursor from inventing its own names for your concepts and creating inconsistencies across your codebase. **Reference your existing code patterns** Instead of trying to describe a pattern abstractly, you can say: 'When creating new API routes, follow the exact same pattern used in /app/api/products/route.ts.' Cursor can reference that file when generating new routes. This is significantly more reliable than describing the pattern from scratch. **Add security rules** This one is underused. Add rules like: 'Never expose API keys or secrets in client components. Always use environment variables accessed via server-side code only. All user inputs must be validated with Zod before processing.' These rules catch entire categories of bugs before they happen. **Version your rules file** Treat your .cursorrules file like code. Commit it to version control. When your stack changes or you adopt new patterns, update the rules file in the same commit. Add a comment at the top with the last updated date. This keeps your whole team's Cursor setup in sync if you're working collaboratively. **Create a template rules file for each stack you use** If you regularly start new projects with Next.js, or with FastAPI, or with React Native — keep a .cursorrules template for each stack. When you start a new project, drop in the template and customize the 10% that's project-specific. Building this library takes 2 hours; it saves 2 hours per new project after that.

Common .cursorrules Mistakes and How to Fix Them

**Mistake 1: Writing rules for things you could just configure in your linter** ESLint and Prettier already enforce semicolons, quote styles, and import ordering. Don't waste your .cursorrules tokens on things your tooling handles. Focus on the stuff tools can't enforce: architectural decisions, naming conventions for your domain, and patterns specific to your app. **Mistake 2: Making rules too long and explanatory** This is the most common mistake. People write: 'When working with TypeScript, it's important to have strong type safety. This means you should try to avoid using the any type as much as possible because it defeats the purpose of TypeScript...' Cut it to: 'Never use any as a TypeScript type.' Same instruction. 90% fewer tokens. Better compliance. **Mistake 3: Never updating the rules file** Your codebase evolves. The patterns you used six months ago might be deprecated. If your rules reference an old pattern, Cursor will generate old-pattern code. Schedule a 15-minute review of your .cursorrules file every month. Delete rules that are no longer relevant. Add rules for new patterns you've adopted. **Mistake 4: Using one generic rules file for all projects** A backend Python service needs completely different rules than a React Native mobile app. Don't try to make one rules file that covers everything — it ends up covering nothing well. Create project-specific files, even if they share a 50% overlap. **Mistake 5: Forgetting to test your rules** After writing your .cursorrules file, actually test it. Open Cursor, start a new file, and ask it to generate something your rules should govern. Check every rule. You'll almost always find 2-3 that aren't being followed because they were worded ambiguously.

Monetizing Your .cursorrules Knowledge

If you're reading this on aihustle.com, you're probably thinking about how this translates to money. Here are four concrete ways people are already earning with .cursorrules expertise: **Selling pre-built rule sets:** Developers are selling curated .cursorrules files on Gumroad for $9-$29 each. Stack-specific files (Next.js + Supabase, Django + HTMX, React Native + Expo) sell well because developers recognize the time saved. One seller reported $1,800 in three months selling 11 different stack templates. **Adding it to freelance projects:** When you set up a .cursorrules file as part of client onboarding, you're delivering something tangible that has ongoing value. It's a reason to charge $500 more for a project setup and an easy upsell to explain: 'This will make your team's AI coding 3x more consistent from day one.' **Creating educational content:** Tutorials specifically about .cursorrules are underrepresented. YouTube channels covering this topic are getting 20,000-80,000 views per video because demand is high and supply is low. A 4-part YouTube series + a companion Gumroad product is a legitimate $2,000-$5,000 launch. **Consulting for teams:** Larger dev teams are paying $500-$2,000 to have someone audit their AI coding setup and build out proper .cursorrules files for each of their repositories. If you have a background in engineering, this is a fast-to-sell consulting service because the deliverable is concrete and the value is immediate.

Conclusion
A .cursorrules file takes 30 minutes to write and pays you back every single day you use Cursor. The code it generates will match your standards, your architecture, and your patterns without constant correction. Start with the template in this guide, trim it to fit your stack, and commit it to your repo today. The best .cursorrules file is the one that gets written — not the perfect one you're still planning. Build it, use it for a week, and refine based on what Cursor is still getting wrong. That iteration loop is where the real gains come from.
Try these tools and support aihustle
FAQ

Where exactly do I put the .cursorrules file?

Place it in the root directory of your project — the same folder that contains your package.json or your main project configuration file. Cursor detects it automatically. You don't need to configure anything else. If you open a subfolder in Cursor instead of the root, it won't find the file, so always open the full project root.

Does .cursorrules work in all Cursor modes — chat, Ctrl+K, and Tab autocomplete?

The rules apply most reliably in Chat mode and Ctrl+K (the inline edit mode). Tab autocomplete is driven by a different mechanism and is less consistently affected by .cursorrules. For the biggest impact, focus on using Chat and Ctrl+K for code generation tasks where rules matter most.

How long should my .cursorrules file be?

Keep it under 500 words. Longer files don't get ignored entirely, but rule compliance drops as the file gets longer because the model has to deprioritize some content. If you find yourself writing 1,000+ words, you're probably including too much explanation. Cut every rule down to one imperative sentence.

Can I have different .cursorrules files for different parts of my project?

Not natively — Cursor reads one .cursorrules file per project root. However, you can organize your rules file with clear section headers (FRONTEND, BACKEND, DATABASE) and label which rules apply to which parts. Cursor is reasonably good at applying the relevant section when it knows which part of the codebase you're working in.

What's the difference between .cursorrules and the 'Rules for AI' setting in Cursor preferences?

Cursor's 'Rules for AI' preference setting is global — it applies to every project you open. The .cursorrules file is project-specific and overrides the global setting when it exists. Best practice: put universal preferences (like 'I always use TypeScript') in your global settings, and put project-specific patterns in the .cursorrules file.

Can I share my .cursorrules file with my team?

Yes, and you should. Commit it to your version control repository like any other project file. When a teammate clones the repo and opens it in Cursor, they automatically get the same rules. This is one of the best ways to enforce consistent AI-generated code standards across a whole team without any extra setup steps.

My rules aren't being followed consistently. What's wrong?

Three likely causes: First, your rules are too vague — replace descriptive rules with specific imperative instructions. Second, your rules file is too long — cut it down to your most important 15-20 rules. Third, your in-prompt request is conflicting with a rule — the immediate prompt often overrides standing rules, so if you paste code that violates your rules and ask Cursor to extend it, it may follow the example code instead of your rules file.

Free tools mentioned

Related tools and services mentioned in this guide, with quick links to full reviews.

ai_coding
v0

Vercel UI generator for rapid component shipping