Lesson 7. .cursorrules and project context — customizing AI for yourself
.cursorrules is the vibe coder's secret weapon. You give the AI rules: what language to use, what style to follow, which libraries to pick. As a result, the AI consistently creates code that fits your project.
Topic breakdown
.cursorrules (or the .cursor/rules folder) is a file in the project root that gives the AI permanent instructions. Every time you use Chat or Agent, Cursor reads this file first and follows the rules.
Example: if you write in '.cursorrules' 'Always use TypeScript, use Tailwind CSS, function names must be camelCase' — the AI will never create JavaScript, will never write plain CSS, and will always name functions correctly.
For vibe coding, this is crucial: you don't have to write 'use TypeScript' in every prompt. Write it once in rules — the AI always complies. This saves time and ensures result consistency.
Context management is even broader: besides .cursorrules, Cursor reads package.json, tsconfig, README, and other config files. You add extra context via @ mentions. Together, all this vastly improves AI answer quality.
What you'll learn
- Creating and properly locating the .cursorrules file
- Writing effective project rules
- Getting consistent results from the AI
- Properly managing project context (@mentions, .cursorignore)
- Creating a complex rule system via the .cursor/rules folder
Deep dive
Structure of the .cursorrules file: The file is plain text or markdown. The AI reads it entirely and uses it as a system prompt. Best format: first role (who to act as), then a list of rules (what to do/avoid), and finally project context (technologies, structure).
The .cursor/rules folder: For large projects, one .cursorrules might not be enough. In the .cursor/rules/ folder, you can create separate files: frontend.md, backend.md, testing.md, styling.md. Cursor reads them all. This helps set distinct rules for each domain in team projects.
.cursorignore: Similar to .gitignore — files and folders specified here are not indexed by Cursor. Add node_modules, .next, dist, build. This speeds up AI responses and clears out irrelevant content.
Example of .cursorrules for a real project: In professional projects, rules include error handling strategies, naming conventions, behavior in ambiguous situations (e.g., 'if unsure — ask, do not guess'), test requirements, and commit message formats. This brings the AI almost to the level of a full team member.
Ready prompt template
Copy and adapt# Example .cursorrules file You are an expert TypeScript/Next.js developer. Rules: - Always use TypeScript (not JavaScript) - Use React Server Components by default, 'use client' only when necessary - Use CSS Modules for styling (no Tailwind) - Function names must be camelCase, component names PascalCase - Add a JSDoc comment to every function - Error handling is mandatory (try/catch) - Write comments in English
Why it works
Role: 'expert TypeScript/Next.js developer' — AI works from this perspective
Language: 'TypeScript, not JavaScript' — clear constraint
Architecture: 'Server Components by default' — project pattern defined
Style: 'CSS Modules' — design choices made in advance
Conventions: 'camelCase, PascalCase, JSDoc' — code standards
Comment language: 'in English' — chosen documentation language
Practice
- Create a .cursorrules file at the root of your project
- Write rules for your project based on the template above
- Ask Chat to create a simple component and check if the AI followed the rules
- Change the rules (e.g., 'use Tailwind') and observe the difference
- Create a .cursor/rules folder and add separate files (backend.md, frontend.md)
- Exclude node_modules and build folders in a .cursorignore file
Common mistakes
- Writing too many rules — 10-20 main rules are enough; 100+ will confuse the AI
- Contradictory rules — 'use TypeScript' and 'write pure JavaScript' cannot coexist
- Adding .cursorrules to gitignore — keep it with the project, it's useful for the team
- Failing to update rules — as the project grows, the rules should be updated too
Lesson FAQ
Where do I put the .cursorrules file?
In the root folder of the project — at the same level as package.json. Cursor finds and reads it automatically.
What language should I write rules in?
In any language — English, Russian, etc. The AI understands them all. However, rules in English generally perform more accurately since models are predominantly trained on English text.
How many rules files can I have in one project?
In the .cursor/rules/ folder — unlimited. But the total volume should not exceed 10,000 words, otherwise the AI might ignore important rules.