with one click
cursor-usage
How to write and manage Cursor rules - invoke with @cursor-usage
Menu
How to write and manage Cursor rules - invoke with @cursor-usage
| name | cursor-usage |
| description | How to write and manage Cursor rules - invoke with @cursor-usage |
Source Cursor rule: .cursor/rules/cursor-usage.mdc.
Original file scope: .cursor/rules/*.mdc.
Original Cursor alwaysApply: false.
Cursor rules provide system-level instructions to the AI to maintain code consistency, quality, and adherence to project standards. They are stored in the .cursor/rules/ directory as .mdc (Markdown with frontmatter) files.
Each .mdc rule file consists of two parts:
---
description: Brief overview of what this rule enforces
globs: **/*.{ts,tsx}
alwaysApply: true
---
Frontmatter Fields:
description: A clear, concise explanation of the rule's purposeglobs: Glob pattern to match files where this rule should apply (plain string, no quotes or arrays)
**/*.tsx - All TSX files**/*.{ts,tsx} - All TS and TSX filesapps/*/components/**/*.tsx - All TSX files in any app's components directory**/trigger/**/*.ts - All TS files in trigger directoriesalwaysApply: Boolean indicating if the rule should always be active
true: Rule is always active when working on matching filesfalse: Rule can be selectively invoked with @rule-nameThe body of the rule file contains the actual guidelines, examples, and instructions written in Markdown format.
Rules with alwaysApply: true are automatically loaded when:
globs patternYou can reference specific rules in your prompts:
@design-system create a new button component
This explicitly tells Cursor to apply the design-system rule.
Always include:
// ✅ Good: Use semantic tokens
<div className="bg-background text-foreground">Content</div>
// ❌ Bad: Hardcoded colors
<div className="bg-white text-black">Content</div>
Organize content with descriptive headers:
## Core Principles
## Rules
## Examples
## Exceptions
## Common Mistakes
If there are cases where rules don't apply, state them clearly:
## Exceptions
The ONLY time you can pass className to a design system component is for:
1. Width utilities: `w-full`, `max-w-md`
2. Responsive display: `hidden`, `md:block`
Provide actionable checklists for validation:
## Code Review Checklist
Before committing:
- [ ] Uses semantic color tokens
- [ ] Works in both light and dark mode
- [ ] Fully responsive
.mdc file in .cursor/rules/.mdc fileRecommended structure:
.cursor/rules/
├── design-system.mdc # Component usage, variants, composition
├── code-standards.mdc # General code quality rules
├── typescript-rules.mdc # TypeScript type safety
├── react-code.mdc # React patterns and conventions
├── data-fetching.mdc # Server/client data patterns
└── cursor-usage.mdc # This file - how to use rules
# All TypeScript/TSX files
globs: **/*.{ts,tsx}
# Only TSX files (React components)
globs: **/*.tsx
# Only trigger task files
globs: **/trigger/**/*.ts
# Prisma schema files
globs: **/*.prisma
# All JSON and TypeScript files
globs: **/*.{ts,tsx,json}
** for recursive directory matching* for single-level wildcard{ts,tsx} for multiple extensionsglobs pattern matches your filealwaysApply is set appropriately@ruleNameglobsUse alwaysApply: false for rules that should only apply in specific contexts:
---
description: Performance optimization guidelines
globs: **/*.ts
alwaysApply: false
---
Invoke with: @performance-optimization refactor this component
More specific globs take precedence:
design-system.mdc with globs: **/*.tsx (broad)trigger.basic.mdc with globs: **/trigger/**/*.ts (specific)The specific rule will have more weight for trigger files.
touch .cursor/rules/my-new-rule.mdc
---
description: What this rule enforces
globs: **/*.{ts,tsx}
alwaysApply: true
---
# Rule Title
## Guidelines
- Point 1
- Point 2
globs pattern@my-new-rule in your promptglobs patternRemember: Rules are here to help, not hinder. If a rule doesn't make sense for a specific case, discuss with the team and update the rule accordingly.
The contract every new or modified API endpoint must follow so it is correct for the public OpenAPI spec, the MCP server (npm @trycompai/mcp-server), the ValidationPipe, and the docs. Triggers on "new endpoint", "add API", "new DTO", "@Body", "@RequirePermission", "MCP tool", "edit controller in apps/api", "OpenAPI", or whenever editing controllers under apps/api/src/.
MUST run after writing or modifying code — reviews changed files for verbose patterns, inconsistencies, and readability issues before considering work done
Use when changing Comp AI billing, Stripe products/prices, subscription checkout, org payment methods, entitlements, usage ledgers, invoices, or billing webhooks.
Audit & fix design system usage — migrate @trycompai/ui and lucide-react to @trycompai/design-system
Audit & fix hooks and API usage patterns — eliminate server actions, raw fetch, and stale patterns
Audit & fix RBAC and audit log compliance in API endpoints and frontend components