May 29, 2025
Master Cursor Custom Rules to Align Gen AI with Your Code
Use Cursor’s Custom Rules to enforce coding standards, project structure, and test coverage. Make AI generate code that follows your team’s best practices.
Author


Book a call
Table of Contents
In this blog, we’ll dive into what Cursor’s rules are, how they work, and how you can use them to bring structure, consistency, and actual team alignment to your AI-powered workflow. Just real, dev-focused examples that help you go from “AI that kind of helps” to “AI that codes like your best junior dev (who doesn’t forget lint rules).”
Understanding Cursor’s Custom Rules
- Project Rules: These are workspace-wide rules stored in .cursor/rules/ and committed to version control. They apply to everyone working in the repo, super useful for enforcing team-wide patterns, boilerplate structures, or naming conventions.
- User Rules: These live locally and are scoped only to your Cursor environment. Think of them as your personal tweaks or power-ups for one-off or experimental cases. Cursor stores them in your user settings directory.
To sum it up: Project rules = team alignment. User rules = personal productivity boosts.
How Do These Rules Actually Work?
- File matchers (globs): Decide which files the rule applies to.
- Prompts/Instructions: Tell Cursor what to do when editing those files.
- Referenced files (optional): Provide extra context, like shared types, utility functions, or templates.
So instead of writing the same prompt over and over again, like "Please generate a Zod schema and name everything in camelCase", you just write the rule once, and Cursor applies it automatically in the right places.
What About .cursorrules?
Setting Up Custom Rules in Cursor
The easiest way to get started is to use the built-in command:
This will prompt you for a name for the rule and create a markdown file at this location:
Here’s what a full rule looks like:
- description: Short explanation of what the rule does
- globs: File patterns where the rule should apply (e.g., **/*.ts)
- alwaysApply: If true, the rule is used without needing manual selection
- referencedFiles: (Optional) Files used as examples or context for better AI responses
- Body: The actual instructions shown to the AI when working in matching files.
- Go to Settings → Rules
- You’ll see both User Rules and Project Rules
- Toggle, delete, or update them as needed
Use Case 1: Enforcing Consistent API Validation with Zod
Rule Example
Use Case 2: Enforcing Consistent File Structure for Features
Rule Example
Use Case 3: Enforcing Unit Test Coverage with Vitest
You're using Vitest, and every utility function should have a corresponding test file. Devs often skip writing them.
Rule Example
Use Case 4: Auto-Wiring RPC Handlers with tRPC
Rule Example
With this, AI consistently generates boilerplate that aligns with your tRPC config without you needing to manually adjust every time.
Best Practices & Tips
Make Rules Iterative, Not Perfect
Be Specific in the Prompt
Review Rules as a Team
Keep It Human
Don’t over-engineer your prompts. Write it like you’re telling a junior dev sitting next to you. That’s usually the sweet spot.
Final Thoughts:
If you’ve ever wished AI could “just know how we do things around here,” this is how you get there.
Subscribe to Our Newsletter
Subscribe to RSS
Press & Media Hub RSS FeedRelated Articles.
More from the engineering frontline.
Dive deep into our research and insights on design, development, and the impact of various trends to businesses.

Jun 27, 2026
Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability

Jun 19, 2026
We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned

Jun 12, 2026
Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions

Jun 8, 2026
Geeklego: The Open-Source Design System Built to Work With AI

May 18, 2026
Your Vibe Code Has No Memory. DESIGN.md Fixes That.

May 14, 2026