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

Ajinkya Vinayak Palaskar
Ajinkya Vinayak PalaskarSoftware Engineer III

Date

May 29, 2025

Table of Contents

Generative AI tools like Cursor are changing the way developers write code;, but let’s be honest, the default AI behaviour doesn’t always match how you or your team builds software. Whether it’s naming conventions, project structure, or the way you wire up API calls, out-of-the-box AI can feel like working with a junior dev who doesn’t quite get the vibe yet.

That’s where Cursor’s Custom Rules come in. Instead of adapting your codebase to fit AI’s suggestions, you can flip the script and make AI generate code that follows your standards, your structure, and your expectations.

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

At its core, Cursor’s Custom Rules feature gives developers a way to shape the behaviour of the AI assistant so it actually respects your coding preferences. It’s not just about giving it tips, it’s about creating structured, repeatable rules that get applied every time you prompt it in certain files or folders.

Cursor supports two types of rules:

    1. 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.
    2. 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?

Cursor rules work by defining:

  • 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?

If you’ve used Cursor in the past, you might’ve seen the old .cursorrules file in the root of your project. That format is now deprecated in favour of the new .cursor/rules/*.json system, which is much more flexible and easier to manage across teams.

Setting Up Custom Rules in Cursor

Now that we know what rules are and why they matter, let’s get into how to actually set them up. The cursor makes this surprisingly smooth. You don’t need any weird config voodoo, just a well-structured JSON file, a clear prompt, and you’re good to go.

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:

Let’s break this down:

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

To see which rules are active or to edit them:

  • Go to Settings → Rules
  • You’ll see both User Rules and Project Rules
  • Toggle, delete, or update them as needed

Now that you have got the structure down, let’s look at how developers can use Cursor Custom Rules to handle real-world problems.

Use Case 1: Enforcing Consistent API Validation with Zod

The Problem

Your team uses Zod for request/response validation across all service files, but devs often forget to include schemas or name things consistently.

Rule Example

This makes the AI generate pre-validated, strongly typed service methods every time, no reminders or rework needed.

Use Case 2: Enforcing Consistent File Structure for Features

The Problem

Every new feature in your app should follow a clean structure like index.tsx, hooks.ts, types.ts, and api.ts, but different devs often structure things differently.

Rule Example

With this rule, Cursor automatically scaffolds the correct file layout and encourages modular, maintainable code across your repo.

Use Case 3: Enforcing Unit Test Coverage with Vitest

The Problem

You're using Vitest, and every utility function should have a corresponding test file. Devs often skip writing them.

Rule Example

With this rule in place, AI writes tests along with your utilities, improving test coverage and helping juniors not skip QA steps.

Use Case 4: Auto-Wiring RPC Handlers with tRPC

The Problem

You're using tRPC, and you want every new route to follow a specific handler format with proper input/output typing.

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

Getting started with Custom Rules is easy, but getting them to stick and scale well with your team takes a bit of finesse. Here are some battle-tested tips to help you make the most of them:

Make Rules Iterative, Not Perfect

Don’t try to write the ultimate prompt on Day 1. Start small, even a 1-liner like “Use Zod in all services” can go a long way. Watch how Cursor responds, and improve the rule over time. 

Think of rules like code: ship early, refine often.

Be Specific in the Prompt

Don’t just say “use tests”, say “use Vitest and place tests in the __tests__ folder next to the source file”. The more specific the language, the more reliable the output. 

Use phrasing like: “Always start with...”, “Never skip...”, “Follow the pattern from...” etc.

Review Rules as a Team

If you’re on a team, treat your rules like coding conventions. Do quick async reviews, and align on when a rule should apply (alwaysApply: true vs. manual). This helps avoid confusion or overreach from the AI.

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:

Custom Rules in Cursor are low-effort, high-impact. With just a few Markdown files, you can guide AI to follow your team’s coding style, enforce structure, and even auto-suggest best practices, all without writing extra logic or docs.

I have found that whether you’re working solo or on a big team, these rules let you offload the repetitive reminders and keep your codebase clean and consistent.

If you’ve ever wished AI could “just know how we do things around here,” this is how you get there.

SHARE ON

Related Articles.

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.

How We Built an AI System That Automates Senior Solution Architect Workflows
Article

Apr 6, 2026

How We Built an AI System That Automates Senior Solution Architect Workflows

Discover how we built a 4-agent AI co-pilot that converts complex RFPs into draft technical proposals in 15 minutes — with built-in conflict detection, assumption surfacing, and confidence scoring.

AI Code Healer for Fixing Broken CI/CD Builds Fast
Article

Apr 6, 2026

AI Code Healer for Fixing Broken CI/CD Builds Fast

A deep dive into how GeekyAnts built an AI-powered Code Healer that analyzes CI/CD failures, summarizes logs, and generates code-level fixes to keep development moving.

A Real-Time AI Fraud Decision Engine Under 50ms
Article

Apr 2, 2026

A Real-Time AI Fraud Decision Engine Under 50ms

A deep dive into how GeekyAnts built a real-time AI fraud detection system that evaluates transactions in milliseconds using a hybrid multi-agent approach.

Building an Autonomous Multi-Agent Fraud Detection System in Under 200ms
Article

Apr 1, 2026

Building an Autonomous Multi-Agent Fraud Detection System in Under 200ms

GeekyAnts built a 5-agent fraud detection pipeline that makes decisions in under 200ms — 15x cheaper than single-model systems, with full explainability built in.

Building a Self-Healing CI/CD System with an AI Agent
Article

Mar 31, 2026

Building a Self-Healing CI/CD System with an AI Agent

When code breaks a pipeline, developers have to stop working and figure out why. This blog shows how an AI agent reads the error, finds the fix, and submits it for review all on its own.

Maestro Automation Framework — Advanced to Expert
Article

Mar 26, 2026

Maestro Automation Framework — Advanced to Expert

Master Maestro at scale. Learn architecture, reusable flows, CI/CD optimization, and how to eliminate flakiness in production-grade mobile automation.Master Maestro at scale. Learn architecture, reusable flows, CI/CD optimization, and how to eliminate flakiness in production-grade mobile automation.

Scroll for more
View all articles