Best Practices for Writing Cursor Rules
Best Practices for Writing Cursor Rules
Creating effective cursor rules requires understanding how AI assistants interpret instructions. Here are proven best practices.
Be Specific, Not Vague
Instead of "write good code", specify what good means:
Include Context
The AI needs to understand your project:
Prioritize Important Rules
Place your most critical rules first. AI assistants pay more attention to rules that appear early in the file.
Use Examples When Helpful
For complex patterns, show an example:
Bad: "Use proper error handling"
Good: "Handle errors using this pattern:
try {
// operation
} catch (error) {
logger.error(error)
throw new AppError(error.message)
}"
Keep It Updated
Your rules should evolve with your project. Review and update them regularly as your codebase grows.
Test Your Rules
After creating rules, test them by asking the AI to generate code. Refine rules that don't produce desired results.
Generate your own cursor rules with CursorRulesSpark