格 千格 KiloCell

Cursor Rules guide:
Collaboration to establish “rule of law” standards for AI

What's Cursor Rules?

Cursor Rules is the Cursor Editor's rule-configuration system for specifying AI Specific norms and standards to be followed in code generation, project analysis and dialogue. It essentially built a set of "AI" for your project. Constitution”. You can effectively reduce AI by defining project background, code specifications, library preferences, etc. And the illusions that make sure that the code they generate is highly compatible with your project needs.

Core values

The first time I've been able to get a job with a guy, and then I'm gonna have to go to the hospital. Context Floating 。 Even if you had emphasized norms in the dialogue, AI could easily forget after several conversations. Rules It is a permanent constraint, and each dialogue is automatically mounted.

Rule type: User vs Project

Cursor provides two levels of rule configuration that meet generic preferences and project-specific norms, respectively.

Type Configure Location Apply scene
User Rules Cursor Settings > Rules Global: e.g., output language (Chinese), response simplicity, common code indentation, etc.
Project Rules .cursor/rules/ Table of contents Specific to the project: Technical Bar (Next.js 14), Catalogue Structure, API Encapsulation Code, etc.

Detailed format of the.mdc file

From the end of 2024, Cursor introduced a whole new one. .mdc (MarkdownConfig) Format, which supports automatic triggers based on Glob mode.

.cursor/rules/react-style.mdc
---
description: React Component Preparation Code
globs: **/*.tsx, **/*.jsx
alwaysApply: false
---

# React CodingNormative

## ComponentStructure
- 优FirstUseFunctions式Component (RFC)。
- Use TypeScript 接口Definitions Props。
- Logical较HeavyIt's... Hook I have to.抽RemovePresent. `hooks/` Contents.

## StylesNormative
- 仅允Hsui.Use Tailwind CSS。
- Tight禁UseInner association style attribute.

Pass. globs , you can let the specified rules only apply when handling a React or Python file, avoiding irrelevant rules interfering with AI And the judgement, and thus saving Token and increasing the speed of generation.

Field Vision: Addressing Specific Problems

Scenario one: maintaining coherence in large structures

Question: In multi-module projects, AI often introduces third-party libraries or error module references that do not conform to the project agreement.
Solutions: Create a `architecure.mdc ' , set `alwaysApply: true ' , which expressly prohibits the use of a library (e.g., prohibits the use of a library) axios, use a packaged version of the http module that is enclosed in a setch). This way AI will automatically comply with this restriction in any conversation.

Scenario 2: Accompanied new members entering the site (Onboarding)

Question: When a new developer (or AI) takes over the project, you are not familiar with the complex directory structure and script instructions.
Solutions: Create `onboarding.mdc ' with details of the meaning of the catalogue tree, the commonly used `npm run ' commands and the pre-subscript code Checkbox。 When AI tries to change the item, it automatically checks itself on this document.

Scenario III: Eradicating the low-level error caused by the AI hallucination

Question: AI may generate obsolete API (e.g. an old version of the Next.js 13 navigation).
Solutions: In `textjs.mdc ', it is specified that `text/navigation ' is used instead of `text/router ' . By force AI The knowledge base is locked in your project version.

2025 Template for best practices

Here's a mature Next.js-based proposal. .cursorrules Global configuration template:

.cursorrules
# Baseline role-setting
You.Yes.One.Synchronising folder资深It's...All栈Architect,精All Next.js 14, TypeScript and Tailwind CSS。

# Technology preferences
- 框架: Next.js 14 (App Router)
- Component: Shadcn/ui + Lucide Icons
- StatusPipeRy.: Zustand (仅Yes.跨PageTimeUse)
- Database: Prisma + PostgreSQL

# Code of conduct
- AlwaysChinese回答, butin codeVariable Name、Comment、SubmitInformationI have to.UseEnglish。
- ModifyCodeFront,FirstJane.Yes.NotesYou.It's...思Road。
- Generate React ComponentTimeDefaultUse 'use client',Divide非I'm...MingYes.Yes.求Use Server Components。
- Tight禁DeleteCurrentYes.It's...ErrorProcessingLogical.