Introduction
Mastering these techniques will help you say goodbye to AI spaghetti code and make Cursor your efficient programming partner.
Recently, Ryo Lu, the Chief Designer of Cursor (formerly the Chief Designer at Notion), shared insights on how to effectively use Cursor on social media platform X. He emphasized a core idea:
“Proper use = fast, clean code; improper use = you’ll spend a whole week cleaning up ‘AI spaghetti code.’”
This article will delve into the 12 practical suggestions proposed by Ryo Lu to help you maximize Cursor’s potential and improve your development efficiency and code quality.
1. Set Clear Project Rules
Before starting a project, use /generate rules to establish a clear structure and constraints, which helps Cursor understand the framework and boundaries.
How to operate:
- Use
/generate rulesto automatically generate rules. - Alternatively, manually set 5–10 constraints (e.g., tech stack, coding standards).
Key points:
- Store design documents in the
.cursor/folder to help AI understand the overall architecture. - For example: prohibit the use of
varand enforce “strictly use ES6 syntax” to prevent AI from improvising.
2. Be Specific with Prompts: Write Like a Mini Spec
Vague prompts will only yield vague code. Your prompts should clearly specify the tech stack, behavior logic, and constraints.
Structure formula: Tech stack + behavior requirements + constraints
Example comparison:
- Incorrect: “Write a login feature.”
- Correct: “Implement an OAuth2.0 login component using React+TypeScript without relying on third-party libraries; the button must support dark mode.”
3. Handle One File at a Time
Process one file at a time using a cycle of “generate → test → review” for more effective results.
- Strategy: Handle one file at a time and move on to the next after completion.
- Example: When building an e-commerce system, start by developing the “shopping cart component” individually rather than generating the entire system at once.
4. Write Tests Before Generating Code
Write tests and lock them in until the code passes all tests. This acts as a “tightening spell” for AI, ensuring code quality.
Test-Driven Development (TDD): Manually write tests (e.g., Jest unit tests) and then let Cursor fill in the code until all tests pass.
Advantage: Test failure messages can be directly fed back to AI for fixes, creating a feedback loop.
5. Always Manually Review and Fix Problematic Outputs
After fixing, inform Cursor that these are the “correct answers” to help generate more accurate code in the future.
- Principle: After fixing bugs, use
@fixedcomments to inform AI of the correct approach. - Example: If AI forgets to add an authentication header for an API, after fixing, add: “All APIs must include a JWT authentication header.”
6. Use @ Symbol for Precise Context
Use @file, @folder, and @git to focus the scope and accurately locate code context, preventing Cursor from going off track.
Useful commands:
@src/components: Limit the modification scope.@git#main: Compare changes against the main branch.@file:utils.js: Modify a specific file without affecting other modules.
Extended application: You can also use the @web feature for online searches or @docs to reference documents.
7. Place Design Documents in the .cursor/ Folder
Provide complete context so that the AI Agent knows what to do next.
- Practice: Keep architecture diagrams and design documents in the
.cursor/docsdirectory and maintain them alongside code updates. - Benefit: This provides AI with rich background information, enabling it to make decisions that better align with project needs.
8. Skip Explanations, Just Make Changes
Cursor learns fastest from actual modifications rather than verbal explanations.
- Truth: AI learns from your manual changes at a speed 10 times faster than from text explanations.
- Example: Rewrite an inefficient sorting algorithm and annotate: “Prefer using quicksort; disable bubble sort.”
9. Continuously Iterate Using Conversation History
Update old prompts without starting from scratch.
- History: Your second brain.
- Use
/historyto retrieve old conversations. - Organize frequently used prompts into templates for reuse (e.g., coding style guidelines).
10. Consciously Choose Models
Different models have different strengths; choose the appropriate model based on the task type.
- Gemini: High accuracy - suitable for algorithm implementations.
- Claude: Broader understanding - suitable for creative tasks (UI/writing).
- DeepSeek: Performs well in discussion and research scenarios.
11. Link Documentation for Unfamiliar Stacks
Ask Cursor to explain errors and fixes line by line by providing documentation links.
- Operation: Attach the official documentation link and request a line-by-line explanation of errors.
- Example:
@https://xxxx/docsto explain the dependency update rules ofuseEffect.
12. For Large Projects, Let Cursor Index Overnight
For larger projects, pre-indexing is recommended. Once completed, limit the context scope to speed up and reduce noise.
Strategy:
- Allow the project to undergo pre-processing so that AI fully grasps the structure.
- Use keywords like
@scope:coreto focus on core modules and enhance response speed.
Additional Useful Tips
In addition to the 12 core suggestions from Ryo Lu, there are some additional techniques worth mastering based on community practices:
1. Master Cursor’s Four Functional Modules
- Tab: Intelligent completion and code continuation.
- Inline Chat: Quick dialogue and code modification.
- Ask: Project-level Q&A and architecture analysis.
- Agent: Automate complex tasks.
2. Utilize Terminal Dialogue Functionality
Press Command + K (Mac) / Ctrl + K (Windows) to describe command operations in natural language.
Cursor will generate and execute the corresponding terminal commands for you.
3. One-Click Commit Message Generation
Say goodbye to the hassle of “What did my code change?”
Cursor can automatically generate compliant commit messages, significantly improving Git operation efficiency.
4. Use Checkpoint Functionality
When AI-generated code encounters issues, use the checkpoint feature to quickly revert to a previous stable version.
Avoid the hassle of manual fixes and boldly try various AI-generated solutions.
Conclusion: Become a Strategic Partner in AI Programming
Ryo Lu and the Cursor team emphasize:
“The ultimate form of AI programming is for humans to handle strategy while AI handles tactics.”
In summary, the key to efficiently using Cursor lies in writing more documentation and chatting less, providing clear guidance.
You need to become the system’s designer and architect, allowing Cursor to handle implementation details. Your mind should have a systematic development route and architecture, understanding what parts the system consists of and how each part should function.
Don’t believe those who claim to create complex functionalities purely through text descriptions without understanding code. You should write more documentation to describe your needs. This way, every subsequent modification by Cursor will pay attention to not violating your requirement documents.
The chat window is generally where you inform Cursor which documents to use for development. Try to avoid making requests in the chat window.
By following these principles and techniques, you will establish an efficient collaborative relationship with Cursor, achieving a qualitative leap in programming efficiency.
Comments
Discussion is powered by Giscus (GitHub Discussions). Add
repo,repoID,category, andcategoryIDunder[params.comments.giscus]inhugo.tomlusing the values from the Giscus setup tool.