Cursor: An AI-powered IDE based on VS Code that integrates autocomplete, chat, and multi-file editing capabilities using Claude, GPT-4, and other models.
Cursor wins on speed and familiarity. It’s VS Code with AI superpowers. For developers who live in their IDE, nothing else matches the flow.
# Project Context
This is a Next.js 14 SaaS application using TypeScript, Tailwind CSS,
and Supabase. Follow these patterns:
## Code Style
- Use functional components with hooks
- Prefer named exports over default exports
- Use TypeScript strict mode
- Use absolute imports (@/ prefix)
## Security Requirements
- All database queries must be parameterized
- Verify user ownership before data access
- Validate all inputs with Zod
- Never expose internal errors to clients
## Patterns to Follow
- Server Components by default
- Use 'use client' only when necessary
- API routes in app/api/ directory
- Types in types/ directory
## Patterns to Avoid
- Don't use any type
- Don't use inline styles
- Don't hardcode strings (use constants)
- Don't create circular dependencies
## Testing
- Unit tests with Vitest
- E2E tests with Playwright
- Test files next to source files (*.test.ts)
Cursor reads this file and applies it to all suggestions.
defaultContext: “codebase” includes relevant files automatically
autoApply: false to review changes before applying
Custom Prompts
Add frequently used prompts to snippets:
1
2
3
4
5
6
7
8
9
10
11
// .vscode/cursor.code-snippets
{"Security Review":{"prefix":"//secreview","body":"Review this code for security vulnerabilities including IDOR, injection, auth bypass, and information disclosure."},"Add Tests":{"prefix":"//addtests","body":"Add comprehensive unit tests for this file. Cover happy paths, error cases, and edge cases."}}
Mastering Autocomplete
Let It Learn
Cursor learns from your codebase. The more consistent your patterns, the better suggestions become.
Improve autocomplete quality:
Keep code consistent
Use descriptive names
Add TypeScript types
Write a few examples of each pattern
Tab-Tab-Tab Flow
The fastest workflow:
Start typing a function name
Tab to accept suggestion
Tab through arguments
Tab to complete
Don’t fight the autocomplete. Accept what’s close and modify.
Composer handles multi-file changes. Use for larger operations.
Feature Implementation
1
2
3
4
5
6
Add a notifications system:
1. Create NotificationService in lib/notifications.ts
2. Add notification types in types/notification.ts
3. Create NotificationProvider context
4. Add NotificationBell component in header
5. Create API route for fetching notifications
Composer creates and modifies multiple files in one operation.
Refactoring Across Files
1
2
3
4
5
Rename User to Account across the codebase:
- types/user.ts -> types/account.ts
- Update all imports
- Rename UserService to AccountService
- Update database schema comments
Pattern Application
1
2
Apply the existing error handling pattern from lib/api-utils.ts
to all API routes in app/api/
Advanced Workflows
The Review-Apply Loop
For complex changes:
Ask in Chat mode first
Review the suggestion
If good, ask to apply
If needs changes, refine the request
Apply only when confident
Context Building
Before big changes, build context:
1
2
3
4
5
6
Read and understand:
- app/api/users/route.ts
- lib/auth.ts
- types/user.ts
I need to add user deletion with cascade behavior.
Then ask for the implementation.
Incremental Complexity
Start simple, add complexity:
1
2
3
4
5
6
7
8
9
10
11
# First prompt
Create a basic UserList component that displays users in a table.
# After it works
Add pagination to the UserList. 10 items per page.
# After pagination works
Add sorting by clicking column headers.
# After sorting works
Add search filtering by name and email.
Security Review Mode
Before committing:
1
2
3
4
5
6
7
8
Review this diff for security issues:
[paste git diff or select changed code]
Look for:
- Auth bypass vulnerabilities
- Input validation gaps
- Information disclosure
- IDOR vulnerabilities
Bug: Users can see other users' private notes
Expected: /api/notes returns only current user's notes
Actual: Returns all notes in database
File: app/api/notes/route.ts
Fix this and add a test for the fix.
Adding Tests
1
2
3
4
5
6
7
8
9
10
Add tests for UserService in lib/services/user.ts
Cover:
- Creating a user
- Updating a user
- Deleting a user
- Finding by email
- Error cases (duplicate email, not found)
Use the existing test patterns from lib/services/auth.test.ts
FAQ
Cursor vs Claude Code - which is better?
Different tools for different tasks. Cursor for rapid iteration and autocomplete. Claude Code for complex reasoning and multi-step operations. Use both.
My autocomplete suggestions are bad. How do I improve them?
Add a detailed .cursorrules file. Keep code consistent. Use TypeScript with strict types. Remove old/dead code that might confuse the model.
Composer changes break things. What am I doing wrong?
Review changes before applying (disable autoApply). Make smaller requests. Build context by reading relevant files first.
How do I handle large files that exceed context?
Reference specific sections. “In the handleSubmit function around line 150, add validation.” Don’t try to process entire large files at once.
Conclusion
Key Takeaways
Configure .cursorrules with project patterns and security requirements