Cursor will match your existing naming conventions when you show it real examples from your codebase using @file and @codebase context, and lock the rules in .cursorrules. Provide at least two existing class names as reference, state the convention explicitly (PascalCase services, camelCase methods, UPPER_SNAKE constants), and Cursor will scaffold new classes that fit seamlessly into your project without manual renaming.
Make Cursor match your existing code naming conventions
When Cursor scaffolds a new class without context, it applies generic naming patterns from its training data — UserService when your project uses UserManager, getUser when your convention is fetchUser, STATUS_OK when you use StatusCode.OK. These mismatches create noise in code reviews and slowly erode consistency. This tutorial shows how to prevent that by anchoring Cursor to your actual codebase: defining conventions in .cursorrules, supplying reference files as examples, and using @codebase search to enforce consistency across a whole project.
Prerequisites
- Cursor installed (Free plan or above)
- An existing project with at least some established naming patterns
- Basic familiarity with .cursorrules and Cursor Chat (Cmd+L)
Step-by-step guide
Document your naming conventions in .cursorrules
Document your naming conventions in .cursorrules
Open or create .cursorrules in your project root. Add a naming conventions section that lists each category — classes, interfaces, files, methods, constants, enums — with the exact casing rule and at least one real example from your codebase. Real examples are more reliable than abstract rules: 'Use PascalCase for services, e.g. PaymentService, EmailNotificationService' is clearer to Cursor than 'Use PascalCase for services.' If you have a linting config (ESLint naming rules, checkstyle), reference it too.
1# .cursorrules23## Naming Conventions4Follow these conventions exactly when generating new code:56### Classes and services7- Service classes: PascalCase ending in 'Service', e.g. UserService, PaymentService, NotificationService8- Repository classes: PascalCase ending in 'Repository', e.g. UserRepository, OrderRepository9- Controller classes: PascalCase ending in 'Controller', e.g. AuthController, ProductController10- DTOs: PascalCase ending in 'Dto', e.g. CreateUserDto, UpdateOrderDto1112### Interfaces and types13- Interfaces: PascalCase with 'I' prefix, e.g. IUserService, IPaymentGateway14- TypeScript types: PascalCase, no prefix, e.g. UserRole, OrderStatus1516### Methods and properties17- Public methods: camelCase starting with a verb, e.g. fetchUser, createOrder, validateInput18- Private methods: camelCase with underscore prefix, e.g. _buildQuery, _formatResponse19- Boolean properties: camelCase starting with 'is' or 'has', e.g. isActive, hasPermission2021### Constants and enums22- Constants: UPPER_SNAKE_CASE, e.g. MAX_RETRY_COUNT, DEFAULT_TIMEOUT_MS23- Enum names: PascalCase, e.g. UserRole, OrderStatus24- Enum values: UPPER_SNAKE_CASE, e.g. UserRole.ADMIN, OrderStatus.PENDING2526### Files27- Service files: kebab-case, e.g. user-service.ts, payment-service.ts28- Controller files: kebab-case with controller suffix, e.g. auth-controller.ts29- Test files: same name as file under test with .spec.ts extensionPro tip: Copy the exact names of 3-5 existing classes from your project into the examples. Cursor uses these as a pattern anchor, not just the abstract rule description.
Expected result: Cursor will apply these naming rules to all new classes and methods generated in this project.
Provide reference files as context when prompting
Provide reference files as context when prompting
When asking Cursor to scaffold a new class, use @file to reference an existing similar class from your project. Cursor will read that file's naming pattern and mirror it. This is especially useful for less common conventions that are hard to describe in plain text — an existing file demonstrates exactly what you want better than any rule.
1Using @file src/services/user-service.ts as a naming and structure reference:23Generate a new service at src/services/order-service.ts for managing orders.4Entities to handle: Order, OrderItem5Methods needed:6- fetchOrderById(id: string): Promise<Order>7- createOrder(dto: CreateOrderDto): Promise<Order>8- updateOrderStatus(id: string, status: OrderStatus): Promise<Order>9- deleteOrder(id: string): Promise<void>1011Follow the exact same naming conventions, import patterns, and method signature style as user-service.ts.Pro tip: Reference the file with the most complete example of your conventions, not necessarily the smallest one. Cursor extracts patterns more reliably from a full file than a partial snippet.
Expected result: order-service.ts is created with method names, parameter names, and return types that match user-service.ts exactly.
Use @codebase to audit convention consistency
Use @codebase to audit convention consistency
Open Cursor Chat and use @codebase to ask Cursor to scan your project for naming violations. This is useful after running Cursor in a new project for the first time, or when onboarding a teammate who has been using different prompts. Cursor will search semantically across files and list class or method names that do not match the patterns in .cursorrules. Review the list and decide which to fix.
1Using @codebase:23Scan all TypeScript files in src/services/ and list any class names, method names, or file names that do not follow the naming conventions in .cursorrules.45For each violation:6- Show the current name7- Show the correct name based on .cursorrules8- Show the file path and line numberPro tip: Run this audit after any large scaffolding session. Catching naming issues before they are referenced elsewhere is much cheaper than a project-wide rename.
Expected result: Cursor lists any naming violations with the current name, the correct name, and the file location.
Use Cmd+K to rename a specific identifier
Use Cmd+K to rename a specific identifier
When Cursor generates a name you want to change, select the identifier (class name, method name, or constant) and press Cmd+K. Tell Cursor the new name and ask it to update all references. Cmd+K's inline edit handles the rename and checks imports and usages in the same file. For project-wide renames across multiple files, switch to Composer (Cmd+I) with Agent mode instead.
1Rename this class from 'UserManager' to 'UserService' following the .cursorrules convention.2Update all references to the old name in this file.3Do not change any method names or property names.Pro tip: For renames that span many files, use Composer Agent mode with: 'Rename class UserManager to UserService across all files in src/. Update all import statements and usages.'
Expected result: The class is renamed to UserService and all references within the file are updated.
Scaffold multiple related classes in one Composer session
Scaffold multiple related classes in one Composer session
When you need a full feature scaffold (service, repository, controller, DTOs), use Composer (Cmd+I) with an existing feature as a @file reference. Ask for all files in a single prompt, listing the conventions explicitly or pointing to .cursorrules. Composer in Agent mode creates all files in one pass — review each diff before accepting.
1Using @file src/services/user-service.ts, @file src/repositories/user-repository.ts, and @file src/controllers/user-controller.ts as naming and structure references:23Scaffold a complete 'Product' feature following the same patterns:41. src/services/product-service.ts — ProductService class with fetchProductById, createProduct, updateProduct, deleteProduct52. src/repositories/product-repository.ts — ProductRepository class63. src/controllers/product-controller.ts — ProductController class74. src/dtos/create-product.dto.ts — CreateProductDto85. src/dtos/update-product.dto.ts — UpdateProductDto910All names must follow .cursorrules naming conventions exactly.Expected result: Five new files are created with class names, method names, and file names that match the existing User feature exactly.
Complete working example
1# Project Naming Conventions2# Read this before generating any new class, method, or file.34## Classes5- Service layer: PascalCase + 'Service' suffix6 Examples: UserService, PaymentService, EmailNotificationService7- Repository layer: PascalCase + 'Repository' suffix8 Examples: UserRepository, ProductRepository9- Controller layer: PascalCase + 'Controller' suffix10 Examples: AuthController, OrderController11- DTOs: PascalCase + 'Dto' suffix12 Examples: CreateUserDto, UpdateOrderStatusDto1314## Interfaces15- PascalCase with 'I' prefix16 Examples: IUserService, IEmailProvider, IPaymentGateway1718## Methods19- Public: camelCase, verb-first20 Examples: fetchUser, createOrder, validateToken, sendEmail21- Private: camelCase, underscore prefix22 Examples: _buildQuery, _parseResponse, _validateInput23- Boolean return: camelCase, 'is' or 'has' prefix24 Examples: isAuthenticated, hasPermission, isExpired2526## Properties27- Public: camelCase28- Private: camelCase, underscore prefix29- Boolean: 'is' or 'has' prefix3031## Constants32- UPPER_SNAKE_CASE33 Examples: MAX_RETRY_COUNT, DEFAULT_PAGE_SIZE, JWT_SECRET_KEY3435## Enums36- Enum names: PascalCase — UserRole, OrderStatus, PaymentMethod37- Enum values: UPPER_SNAKE_CASE — UserRole.SUPER_ADMIN, OrderStatus.PENDING3839## Files40- All source files: kebab-case41 Services: user-service.ts, payment-service.ts42 Controllers: user-controller.ts43 Repositories: user-repository.ts44 DTOs: create-user.dto.ts45 Tests: user-service.spec.ts4647## NEVER48- NEVER use 'Manager' suffix for service classes49- NEVER use 'Helper' or 'Utils' as standalone class names — use descriptive names50- NEVER use Hungarian notation (strName, intCount)51- NEVER abbreviate names unless the abbreviation is universally understood (e.g. 'id', 'url')Common mistakes when making Cursor Match Existing Code Style
Why it's a problem: Describing conventions abstractly without examples
How to avoid: Always include at least two real class names from your project alongside the rule. Example: 'Use PascalCase + Service suffix — e.g. UserService, PaymentService, EmailNotificationService.'
Why it's a problem: Only defining naming rules for new code without checking existing generated code
How to avoid: Run the @codebase audit prompt from Step 3 after updating .cursorrules to find and fix any existing violations before they spread.
Why it's a problem: Not referencing an existing similar file when scaffolding a new feature
How to avoid: Always include @file src/services/[similar-service].ts in prompts for new services. The reference file acts as a living template.
Best practices
- Write naming conventions in .cursorrules with at least two real examples per rule — abstract descriptions alone are insufficient.
- Include NEVER rules in .cursorrules for anti-patterns your team has explicitly rejected, such as 'NEVER use Manager suffix' or 'NEVER use Hungarian notation'.
- Run a @codebase naming audit after each large scaffolding session to catch violations before they propagate through imports.
- Reference an existing similar file with @file whenever scaffolding a new class — the example is more reliable than the rule description.
- Keep naming convention rules near the top of .cursorrules so they are in the highest-priority context window position.
- For project-wide renames, use Composer Agent mode rather than Cmd+K — it handles cross-file reference updates automatically.
- Add your team's naming conventions to .cursorrules as part of project onboarding so every team member's Cursor instance follows the same rules.
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I have a TypeScript project where services use PascalCase + 'Service' suffix (UserService, PaymentService), repositories use 'Repository' suffix, and private methods use an underscore prefix (_buildQuery). Generate an OrderService class following these conventions with methods: fetchOrderById, createOrder, updateOrderStatus, deleteOrder. Include a private _buildOrderQuery helper.
In Cursor Chat (Cmd+L), type: 'Using @file src/services/user-service.ts as a naming reference, generate src/services/order-service.ts for managing orders. Methods needed: fetchOrderById, createOrder, updateOrderStatus, deleteOrder. Follow the exact same naming conventions, import style, and method signature patterns as the reference file. Follow .cursorrules naming conventions.'
Frequently asked questions
Do .cursorrules naming conventions apply to Tab completion as well as Chat prompts?
Tab completion uses surrounding code as its primary context rather than .cursorrules directly. However, once your project has consistent naming established in existing files, Tab completion will mirror those patterns automatically through its in-context learning.
Can I have different naming conventions for different languages in the same project?
Yes. Structure .cursorrules with language-specific headings: '## TypeScript naming conventions' and '## Python naming conventions'. Cursor reads the whole file and applies the relevant section based on the file type it is generating.
What happens if Cursor's suggestion conflicts with my .cursorrules naming rules?
Reject the suggestion and use the follow-up: 'This class name conflicts with our convention — rename it to [CorrectName] per .cursorrules.' Cursor usually corrects immediately. If it keeps drifting, start a fresh Chat session — long conversations can cause .cursorrules instructions to lose priority.
How do I enforce naming conventions in a team where different developers use different prompts?
Commit .cursorrules to your repository so all team members automatically get the same rules. Pair it with an ESLint @typescript-eslint/naming-convention rule to catch violations at CI time even if someone bypasses Cursor entirely.
Can Cursor rename a method and update all call sites across multiple files?
Yes. Use Composer (Cmd+I) in Agent mode: 'Rename method getUser to fetchUser in UserService and update all call sites across the codebase.' Agent mode can search and edit multiple files. For safety, review the diff before accepting — verify test files are updated too.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation