AI Development

Cursor Rules Files: How to Train Your AI Coding Assistant

Learn how to use .cursorrules files to teach your AI coding assistant your project's style, patterns, and preferences — so every suggestion it makes actually fits your codebase.

Scroll to start

What Are Cursor Rules Files?

Imagine you have a teammate who joins every project you work on — but every time they start, you have to explain from scratch who you are, how your code is organized, and what you like. That would be exhausting. Cursor Rules Files fix that.

A .cursorrules file is a special configuration file you add to your project. Inside it, you write plain-language instructions about your project: the programming language you use, how you like your code styled, what libraries are included, and even rules like "always write tests before committing." Once you add this file, Cursor AI reads it automatically every time it helps you — and it follows your rules without you having to repeat yourself.

Think of it like writing a training manual for your AI assistant. Instead of telling it "remember we use TypeScript with strict mode" every single conversation, you write it once in the rules file and it just knows.

One Set of Rules, Every File

Without rules files, AI coding assistants can feel inconsistent. They might suggest code in a different style than your project uses, forget about your preferred testing setup, or suggest libraries you don't actually use. You end up fixing the AI's work almost as much as you would have spent writing it yourself.

Rules files change this. Once your rules are defined, every file Cursor helps you with — every new component, every bug fix, every new feature — follows the same standards automatically. It means less time cleaning up AI output and more time actually building.

💡 Key Insight

A good .cursorrules file doesn't just tell the AI what to do — it tells the AI who you are as a developer. Your preferences, your patterns, your project conventions. The better you communicate these, the more the AI becomes a true extension of how you think, not just an autocomplete engine.

Writing Rules That Actually Work

Creating a .cursorrules file is simple — you just create a file named .cursorrules in the root folder of your project and start writing. There's no special format required, but good rules files tend to cover a few common areas:

  • Project overview — what your project does and what it's built with
  • Tech stack — programming language, framework, key libraries
  • Coding style — naming conventions, formatting preferences, file organization
  • Testing expectations — do you require tests? What framework do you use?
  • Special rules — anything specific to your project (security rules, accessibility standards, etc.)

You write everything in plain English. Cursor's AI reads the whole file before generating any code for your project, so it understands the context before it starts typing.

A .cursorrules File in Action

Here's what a simple but effective .cursorrules file looks like for a React + TypeScript project:

.cursorrules
# Project: Task Manager Web App
# Stack: React, TypeScript, Tailwind CSS, Jest

## Project Overview
This is a task management app that lets users create,
organize, and complete to-do items. It's a single-page
React application backed by a simple REST API.

## Tech Stack
- Language: TypeScript (strict mode)
- Framework: React 18
- Styling: Tailwind CSS utility classes
- Testing: Jest with React Testing Library
- Build: Vite

## Coding Style
- Use functional components with hooks. No class components.
- Name files using PascalCase for components (TaskList.tsx)
  and camelCase for utilities (dateUtils.ts).
- Prefer const over let. Never use var.
- Add TypeScript types for all function parameters and return values.
- Keep components focused — one component should do one thing.

## Testing Rules
- Every new component needs a test file: ComponentName.test.tsx
- Write tests using React Testing Library.
- Aim for readable tests that describe behavior, not implementation.

## Accessibility
- Always include aria-label on icon-only buttons.
- Use semantic HTML elements (button, nav, main) over divs where possible.

Now, every time you ask Cursor to add a feature — a new form, a new component, a new utility — it reads these rules and generates code that matches your project's style automatically. You get consistent, well-structured code without having to guide the AI step by step.

Knowledge Check

Test what you learned with this quick quiz.

Quick Quiz — 3 Questions

Question 1
Where should you put a .cursorrules file in your project?
Question 2
What is the main benefit of writing rules for your AI coding assistant?
Question 3
What kind of information should you NOT include in a .cursorrules file?
🏆

You crushed it!

Perfect score on this module.