Context
Cursor
Foundations
Set Up .cursorrules
Configure Cursor-specific behavior with rules files
8 of 66
What are Cursor rules?
Rules are instruction files that Cursor loads based on file patterns, telling the AI how to handle specific parts of your codebase.
File locations
.cursor/rules/ frontend.md # Rules for React components backend.md # Rules for API routes testing.md # Rules for test files
Rule file format
Each rule file uses frontmatter to specify when it applies:
---
description: Rules for React components
globs: ["src/components/**/*.tsx", "src/components/**/*.ts"]
alwaysApply: false
---
## Component conventions
- Use functional components with TypeScript
- Props interface named `{ComponentName}Props`
- Place hooks at the top of the component
- Export components as named exports
Frontmatter options
| Field | Purpose |
|---|---|
description | When the rule applies (shown to the agent) |
globs | File patterns that trigger this rule |
alwaysApply | If true, loaded for every conversation |
Tips
- Use
alwaysApply: truesparingly (only for universal project conventions) - Keep rules focused: one rule per concern
- Include examples of correct and incorrect patterns