Skip to main content
RapidDev - Software Development Agency
cursor-tutorial

How to Make Cursor Match Existing Code Style

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.

What you'll learn

  • How to document your naming conventions in .cursorrules so Cursor applies them automatically
  • How to use @file and @codebase context to show Cursor real examples from your project
  • How to prompt Cursor to audit existing generated files for convention violations
  • How to use Cmd+K to rename a specific identifier while preserving all references
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner9 min read10-15 minCursor Free+, any language or frameworkMarch 2026RapidDev Engineering Team
TL;DR

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

1

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.

.cursorrules
1# .cursorrules
2
3## Naming Conventions
4Follow these conventions exactly when generating new code:
5
6### Classes and services
7- Service classes: PascalCase ending in 'Service', e.g. UserService, PaymentService, NotificationService
8- Repository classes: PascalCase ending in 'Repository', e.g. UserRepository, OrderRepository
9- Controller classes: PascalCase ending in 'Controller', e.g. AuthController, ProductController
10- DTOs: PascalCase ending in 'Dto', e.g. CreateUserDto, UpdateOrderDto
11
12### Interfaces and types
13- Interfaces: PascalCase with 'I' prefix, e.g. IUserService, IPaymentGateway
14- TypeScript types: PascalCase, no prefix, e.g. UserRole, OrderStatus
15
16### Methods and properties
17- Public methods: camelCase starting with a verb, e.g. fetchUser, createOrder, validateInput
18- Private methods: camelCase with underscore prefix, e.g. _buildQuery, _formatResponse
19- Boolean properties: camelCase starting with 'is' or 'has', e.g. isActive, hasPermission
20
21### Constants and enums
22- Constants: UPPER_SNAKE_CASE, e.g. MAX_RETRY_COUNT, DEFAULT_TIMEOUT_MS
23- Enum names: PascalCase, e.g. UserRole, OrderStatus
24- Enum values: UPPER_SNAKE_CASE, e.g. UserRole.ADMIN, OrderStatus.PENDING
25
26### Files
27- Service files: kebab-case, e.g. user-service.ts, payment-service.ts
28- Controller files: kebab-case with controller suffix, e.g. auth-controller.ts
29- Test files: same name as file under test with .spec.ts extension

Pro 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.

2

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.

Cursor Chat prompt (Cmd+L)
1Using @file src/services/user-service.ts as a naming and structure reference:
2
3Generate a new service at src/services/order-service.ts for managing orders.
4Entities to handle: Order, OrderItem
5Methods 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>
10
11Follow 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.

3

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.

Cursor Chat prompt (Cmd+L)
1Using @codebase:
2
3Scan 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.
4
5For each violation:
6- Show the current name
7- Show the correct name based on .cursorrules
8- Show the file path and line number

Pro 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.

4

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.

Cursor Cmd+K inline prompt
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.

5

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.

Cursor Composer prompt (Cmd+I)
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:
2
3Scaffold a complete 'Product' feature following the same patterns:
41. src/services/product-service.ts ProductService class with fetchProductById, createProduct, updateProduct, deleteProduct
52. src/repositories/product-repository.ts ProductRepository class
63. src/controllers/product-controller.ts ProductController class
74. src/dtos/create-product.dto.ts CreateProductDto
85. src/dtos/update-product.dto.ts UpdateProductDto
9
10All 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

.cursorrules
1# Project Naming Conventions
2# Read this before generating any new class, method, or file.
3
4## Classes
5- Service layer: PascalCase + 'Service' suffix
6 Examples: UserService, PaymentService, EmailNotificationService
7- Repository layer: PascalCase + 'Repository' suffix
8 Examples: UserRepository, ProductRepository
9- Controller layer: PascalCase + 'Controller' suffix
10 Examples: AuthController, OrderController
11- DTOs: PascalCase + 'Dto' suffix
12 Examples: CreateUserDto, UpdateOrderStatusDto
13
14## Interfaces
15- PascalCase with 'I' prefix
16 Examples: IUserService, IEmailProvider, IPaymentGateway
17
18## Methods
19- Public: camelCase, verb-first
20 Examples: fetchUser, createOrder, validateToken, sendEmail
21- Private: camelCase, underscore prefix
22 Examples: _buildQuery, _parseResponse, _validateInput
23- Boolean return: camelCase, 'is' or 'has' prefix
24 Examples: isAuthenticated, hasPermission, isExpired
25
26## Properties
27- Public: camelCase
28- Private: camelCase, underscore prefix
29- Boolean: 'is' or 'has' prefix
30
31## Constants
32- UPPER_SNAKE_CASE
33 Examples: MAX_RETRY_COUNT, DEFAULT_PAGE_SIZE, JWT_SECRET_KEY
34
35## Enums
36- Enum names: PascalCase UserRole, OrderStatus, PaymentMethod
37- Enum values: UPPER_SNAKE_CASE UserRole.SUPER_ADMIN, OrderStatus.PENDING
38
39## Files
40- All source files: kebab-case
41 Services: user-service.ts, payment-service.ts
42 Controllers: user-controller.ts
43 Repositories: user-repository.ts
44 DTOs: create-user.dto.ts
45 Tests: user-service.spec.ts
46
47## NEVER
48- NEVER use 'Manager' suffix for service classes
49- NEVER use 'Helper' or 'Utils' as standalone class names use descriptive names
50- 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.

ChatGPT Prompt

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.

Cursor Prompt

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.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.