Rules & Context
Teach Cursor your project\u2019s conventions, structure, and preferences so every AI response is project-aware.
What's possible
- Enforce consistent coding style across all AI suggestions
- Define framework-specific patterns (Next.js App Router, Tailwind, etc.)
- Specify preferred libraries, tools, and approaches
- Reference specific files and folders for targeted context
- Index external documentation for @docs lookups
- Set project-wide and global rules that apply to every interaction
Getting started
- 1
Create a .cursorrules file
Add a .cursorrules file to your project root. This file contains plain-text instructions that Cursor includes as context for every AI interaction.
- 2
Define your conventions
Describe your coding style, framework patterns, naming conventions, and project structure. Be specific — Cursor follows these rules in Tab, Chat, and Composer.
- 3
Use @-mentions for context
Reference files with
@filename, folders with@folder, your entire codebase with@codebase, or documentation with@docs. - 4
Index documentation
In Cursor Settings, add documentation URLs under "Docs". Cursor indexes them so you can reference them with @docs in Chat and Composer.
Example .cursorrules content
Framework rules
“Use Next.js App Router with server components by default. Only add 'use client' when state or event handlers are needed.”
Style rules
“Use Tailwind CSS utility classes. Never write custom CSS unless absolutely necessary. Follow mobile-first responsive design.”
Testing rules
“Write tests for every new function. Use vitest for unit tests. Mock external APIs. Never make real network calls in tests.”
Code style
“Use TypeScript strict mode. Prefer const over let. Use named exports. No default exports except for page components.”
Tips
- Keep .cursorrules concise. Short, specific rules work better than long, vague ones.
- Include examples of your preferred patterns \u2014 show Cursor what good code looks like in your project.
- Use @-mentions to give Chat and Composer specific context instead of relying on automatic codebase indexing.
- Update .cursorrules as your project evolves. Outdated rules lead to inconsistent suggestions.