Reuse Existing Code
Configure Cursor’s AI to search for existing code before generating new solutions. This prevents duplicate implementations.
Add the AI Rule
- Open Command Palette (
Cmd + Shift + P
)
- Select
New Cursor Rule
- Add this instruction:
Before generating code, you MUST:
1. Rephrase the request as: "I am looking for code that does [requested functionality], is there existing code that can do this?"
2. Search the codebase for similar solutions
3. Only generate new code if no suitable existing solution is found
4. If creating new code, explain why existing solutions weren't suitable
Goal: Maintain a cohesive codebase by finding and reusing existing code patterns.
How It Works
When you ask:
"Write a function that handles user authentication"
The AI searches:
"I am looking for code that handles user authentication, is there existing code that can do this?"