cursor-rules-writing
Create Cursor IDE rules in .mdc format with proper frontmatter, glob patterns, and cross-references. Covers rule structure, file organization, triggering mechanisms, and quality standards. Use when creating or modifying Cursor rules for context injection.
Best use case
cursor-rules-writing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Create Cursor IDE rules in .mdc format with proper frontmatter, glob patterns, and cross-references. Covers rule structure, file organization, triggering mechanisms, and quality standards. Use when creating or modifying Cursor rules for context injection.
Teams using cursor-rules-writing should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/cursor-rules-writing/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How cursor-rules-writing Compares
| Feature / Agent | cursor-rules-writing | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Create Cursor IDE rules in .mdc format with proper frontmatter, glob patterns, and cross-references. Covers rule structure, file organization, triggering mechanisms, and quality standards. Use when creating or modifying Cursor rules for context injection.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Cursor Rules Writing
## Purpose
Guide the creation of Cursor IDE rules in .mdc format following best practices for optimal AI context injection and maintainability.
## When NOT to Use This Skill
- Writing general documentation (use regular .md files)
- Creating Claude Code skills (use skill-writing skill instead)
- Configuring Cursor IDE settings (not rules)
- Writing code comments or inline documentation
## Quick Start Workflow
### Step 1: Identify the Context Need
**Ask:** What specific knowledge does Cursor need for this project?
```bash
# Evaluate the gap:
# - What domain knowledge is unique to this project?
# - Which files/patterns need special context?
# - What are developers repeatedly explaining to Cursor?
```
**Only create a rule if:**
- ✅ Context is project-specific and non-obvious
- ✅ Applies to multiple files or scenarios
- ✅ Reduces repetitive prompting
- ❌ General programming knowledge (Cursor already knows)
- ❌ One-time context (use chat instead)
### Step 2: Choose Rule Type and Trigger
**Determine how rule should be applied:**
```yaml
# Always Apply (use sparingly)
alwaysApply: true # Loaded in every chat session
# File-based triggering (most common)
globs: ["**/*.yaml"] # Applies when matching files are referenced
alwaysApply: false
# Manual application
# No globs, no alwaysApply # User invokes with @rule-name.mdc
```
### Step 3: Create MDC File with Frontmatter
```bash
# Create rule file in .cursor/rules/ directory
touch .cursor/rules/my-rule.mdc
```
**Start with frontmatter template:**
```yaml
---
description: Brief description of what this rule provides. Include what context it covers and when it applies. Keep under 200 characters for clarity.
globs: ["**/*.ts", "**/*.tsx"] # Optional: file patterns
alwaysApply: false # Optional: default false
---
```
### Step 4: Write Focused Content
**Keep under 500 lines for optimal performance**
```markdown
# Rule Title
## Overview
One paragraph explaining what context this rule provides.
**Related rules:** See @other-rule.mdc for related context.
---
## Key Concepts
Core information Cursor needs to know.
---
## Examples
Concrete examples with ✅/❌ patterns.
---
## Resources
Links to relevant documentation.
```
### Step 5: Test and Refine
```bash
# Test rule application:
# 1. Open file matching glob pattern
# 2. Start Cursor chat
# 3. Verify rule context is loaded
# 4. Check @-mentions work correctly
```
## MDC File Format
### Frontmatter Structure
**YAML frontmatter with 3 possible fields:**
```yaml
---
description: Clear, concise description of rule context and when to apply it.
globs: ["pattern1", "pattern2"] # Optional: array of glob patterns
alwaysApply: false # Optional: boolean (default: false)
---
```
**Field Descriptions:**
| Field | Required | Type | Description |
|-------|----------|------|-------------|
| `description` | Yes | String | Used by Agent to determine relevance. Be specific about what context is provided and when to use the rule. |
| `globs` | No | Array | File patterns for automatic rule application. Omit for manual-only rules. |
| `alwaysApply` | No | Boolean | If true, rule loads in every chat. Use sparingly - causes context bloat. |
**Frontmatter Rules:**
- ✅ Description must be clear and specific
- ✅ Use globs for file-based triggering
- ✅ Avoid alwaysApply unless truly universal
- ❌ Don't include title/name field (file name is the identifier)
- ❌ Don't use first or second person in description
### Good vs Bad Frontmatter
```yaml
# ❌ Bad - Vague description, no trigger info
---
description: Helper for working with files.
alwaysApply: true
---
# ❌ Bad - Too broad, will cause context pollution
---
description: Contains all project documentation and guidelines.
alwaysApply: true
---
# ✅ Good - Specific, clear when to apply
---
description: Core guidance for writing production-ready Helm charts including Chart.yaml structure, values.yaml patterns, and template helpers. Apply when creating or modifying Helm chart files.
globs: ["**/Chart.yaml", "**/values*.yaml", "**/templates/**/*.yaml"]
alwaysApply: false
---
# ✅ Good - Manual-only rule, no triggers
---
description: Advanced debugging techniques for React rendering performance issues. Use when diagnosing slow re-renders or unnecessary updates.
---
```
## Glob Patterns
### Pattern Syntax
**Cursor uses standard glob patterns:**
```yaml
globs:
- "*.ts" # All .ts files in any directory
- "**/*.tsx" # All .tsx files recursively
- "**/tests/**/*" # All files in tests directories
- "src/components/*.tsx" # .tsx files in specific directory
- "**/{Chart,values}.yaml" # Multiple specific filenames
```
**Pattern Matching:**
- `*` - Matches any characters except `/`
- `**` - Matches any characters including `/` (recursive)
- `?` - Matches single character
- `[abc]` - Matches a, b, or c
- `{a,b}` - Matches pattern a or pattern b
### Effective Glob Patterns
```yaml
# ✅ Good - Specific to chart files
globs: ["**/Chart.yaml", "**/values*.yaml", "**/templates/**/*.yaml"]
# ✅ Good - TypeScript components
globs: ["**/components/**/*.tsx", "**/hooks/**/*.ts"]
# ✅ Good - Configuration files
globs: ["**/*.config.{js,ts}", "**/.*rc", "**/.*rc.json"]
# ❌ Too broad - matches everything
globs: ["**/*"]
# ❌ Too narrow - misses common cases
globs: ["Chart.yaml"] # Only root, misses nested charts
```
### Testing Glob Patterns
```bash
# Use shell glob expansion to test patterns
echo .cursor/rules/*.mdc
# Find files matching pattern
find . -path "**/Chart.yaml"
# Test specific pattern
ls **/values*.yaml
```
## Cross-References
### Referencing Other Rules
**Use `@filename.mdc` syntax to reference related rules:**
```markdown
**Related rules:** See @helm-chart-writing.mdc for chart creation, @helm-chart-review.mdc for quality checks, @helm-argocd-gitops.mdc for GitOps integration.
```
**Cross-reference benefits:**
- ✅ Keeps rules focused and modular
- ✅ Allows rule composition
- ✅ Reduces duplication
- ✅ User can manually load related context
**Best practices:**
- Reference related rules at the top (Overview section)
- Use descriptive text: "See @X for Y" not just "@X"
- Don't create circular references
- Test that referenced rules exist
## Content Organization
### Structure Pattern
```markdown
---
# Frontmatter
---
# Rule Title
## Overview
Brief introduction paragraph.
**Related rules:** Cross-references here.
---
## Section 1: Core Concepts
Main content with examples.
---
## Section 2: Patterns
Common patterns and anti-patterns.
---
## Resources
External links and documentation.
---
**Maintenance note at bottom**
```
### Section Guidelines
**Overview (Required):**
- 1-2 sentences explaining rule purpose
- Cross-references to related rules
- Sets expectations for what follows
**Core Content (Required):**
- Organized into logical sections
- Use `---` to separate major sections
- Include concrete examples
- Show good vs bad patterns (✅/❌)
**Examples (Highly Recommended):**
- Real-world, project-specific examples
- Before/after comparisons
- Common mistakes to avoid
**Resources (Optional):**
- Links to official documentation
- Internal wiki pages
- Related project files
### Content Best Practices
```markdown
# ✅ Good - Concrete examples
## API Error Handling
All API routes must handle errors consistently:
\`\`\`typescript
// ✅ Good - Proper error handling
app.get('/api/users', async (req, res) => {
try {
const users = await db.users.findAll();
res.json({ data: users });
} catch (error) {
logger.error('Failed to fetch users', { error });
res.status(500).json({ error: 'Internal server error' });
}
});
// ❌ Bad - No error handling
app.get('/api/users', async (req, res) => {
const users = await db.users.findAll();
res.json(users);
});
\`\`\`
# ❌ Bad - Vague instructions
## Error Handling
Make sure to handle errors properly in your code. Always catch exceptions and return appropriate status codes.
```
## File Length Management
### 500-Line Target
**Keep rules under 500 lines for optimal performance:**
```
Rule Size Guide:
├─ Under 300 lines: Ideal (fast loading)
├─ 300-500 lines: Good (acceptable)
├─ 500-700 lines: Consider splitting
└─ Over 700 lines: Must split into multiple rules
```
### Splitting Strategies
**Option 1: By topic**
```
helm-expert-skill.mdc (overview, always loaded)
├─ @helm-chart-writing.mdc (creation patterns)
├─ @helm-chart-review.mdc (quality checks)
├─ @helm-argocd-gitops.mdc (GitOps patterns)
└─ @helm-production-patterns.mdc (deployment strategies)
```
**Option 2: By file type**
```
typescript-patterns.mdc
├─ globs: ["**/*.ts"]
├─ Content: General TypeScript patterns
react-components.mdc
├─ globs: ["**/*.tsx"]
├─ Content: React-specific patterns
```
**Option 3: By scenario**
```
database-migrations.mdc
├─ globs: ["**/migrations/**/*"]
├─ Content: Migration patterns
api-testing.mdc
├─ globs: ["**/tests/api/**/*"]
├─ Content: API test patterns
```
## Triggering Mechanisms
### Always Apply Rules
```yaml
---
description: Project architecture and core patterns used across all code.
alwaysApply: true
---
```
**Use when:**
- Universal context needed in every chat
- Core architecture principles
- Project-wide conventions
**Avoid when:**
- Context is file-specific
- Only needed occasionally
- Rule is large (causes bloat)
### File-Based Triggering
```yaml
---
description: Helm chart best practices for Chart.yaml and values.yaml.
globs: ["**/Chart.yaml", "**/values*.yaml"]
alwaysApply: false
---
```
**Use when (most common):**
- Context applies to specific file types
- Patterns for certain directories
- Language/framework-specific guidance
### Manual Application
```yaml
---
description: Advanced performance optimization techniques. Use when debugging performance issues.
---
```
**Use when:**
- Context only needed on-demand
- Specialized troubleshooting
- Reference documentation
- Rarely needed context
## Common Pitfalls
### Pitfall 1: Overly Broad Rules
```yaml
# ❌ Bad - Too much context loaded always
---
description: Everything about the project including architecture, patterns, deployment, testing, and documentation.
alwaysApply: true
---
```
**Solution:** Split into focused rules with specific globs.
### Pitfall 2: Missing Glob Patterns
```yaml
# ❌ Bad - Only matches root Chart.yaml
---
globs: ["Chart.yaml"]
---
```
**Solution:** Use recursive patterns: `["**/Chart.yaml"]`
### Pitfall 3: Duplicate Context
```yaml
# ❌ Bad - Same content in multiple rules
# both-rules.mdc and api-patterns.mdc contain identical API guidelines
```
**Solution:** Single source of truth, cross-reference with @.
### Pitfall 4: Vague Descriptions
```yaml
# ❌ Bad
description: Helper for working with files.
# ✅ Good
description: File upload validation patterns including size limits, type checking, and virus scanning. Apply when implementing file upload endpoints.
```
### Pitfall 5: Too Long
```markdown
# ❌ Bad - 1200 line rule file
# Single file with all project context
```
**Solution:** Split into multiple composable rules under 500 lines each.
## Quality Checklist
### Frontmatter Quality
- [ ] Description is clear and specific
- [ ] Description explains WHAT context is provided
- [ ] Description explains WHEN to apply the rule
- [ ] Globs use recursive patterns (**/) where appropriate
- [ ] alwaysApply is false unless truly universal
- [ ] No unnecessary frontmatter fields
### Content Quality
- [ ] Under 500 lines (or justified if longer)
- [ ] Organized into logical sections with `---` separators
- [ ] Includes concrete, project-specific examples
- [ ] Shows good vs bad patterns (✅/❌)
- [ ] Cross-references related rules with @filename.mdc
- [ ] No duplicate content from other rules
- [ ] Examples use real project code patterns
### File Organization
- [ ] File stored in .cursor/rules/ directory
- [ ] Filename is descriptive and kebab-case
- [ ] Filename ends with .mdc extension
- [ ] Overview section at top
- [ ] Related rules referenced early
- [ ] Resources section at bottom
### Testing
- [ ] Rule loads when expected (check glob patterns)
- [ ] @-mention works in chat
- [ ] No conflicts with other rules
- [ ] Context is relevant and helpful
- [ ] File size is reasonable (<500 lines ideal)
## Resources
- [Cursor Rules Documentation](https://cursor.com/docs/context/rules)
- [Glob Pattern Documentation](https://en.wikipedia.org/wiki/Glob_(programming))
- skill-writing skill (for Claude Code skills, not Cursor rules)
## Quick Reference
```bash
# Create new rule
mkdir -p .cursor/rules
touch .cursor/rules/my-rule.mdc
# Rule template
cat > .cursor/rules/my-rule.mdc << 'EOF'
---
description: Brief description of what this rule provides and when to use it.
globs: ["**/*.ext"]
alwaysApply: false
---
# Rule Title
## Overview
Brief introduction.
**Related rules:** See @other-rule.mdc for related context.
---
## Key Content
Concrete examples and patterns.
---
## Resources
- [Link to docs](https://example.com)
EOF
# Test glob pattern
find . -path "**/Chart.yaml"
# List all rules
ls -la .cursor/rules/*.mdc
```
---
**This skill follows the skill-writing meta skill best practices and should be reviewed quarterly for updates.**Related Skills
cursor-rules
This skill should be used when creating or editing Cursor rules files (.mdc format) in the .cursor/rules directory. Provides guidance on rule types, frontmatter configuration, effective rule writing patterns, and best practices for structuring AI instructions for Cursor IDE.
creating-cursor-rules-skill
Expert guidance for creating effective Cursor IDE rules with best practices, patterns, and examples
create-rules
Create or update Cursor Rules (.mdc files) and Skills (SKILL.md). Use when creating rules, adding coding standards, setting up conventions, updating .cursor/rules/, or converting rules to skills. Defines standard format, naming, frontmatter, token budget.
crafting-rules
Use when creating or modifying OpenCode rules (.md/.mdc files) that customize agent behavior. Helps extract patterns from conversation history, analyze project conventions (AGENTS.md, linters, package.json), and draft well-formatted rules with appropriate globs/keywords. Trigger when user wants to create a rule, codify repeated instructions, persist guidance across sessions, or customize agent behavior for specific files or topics.
containerization-rules
Rules for creating and maintaining Dockerfiles.
common-rules
Tüm skill'ler için ortak kurallar ve standartlar. Git workflow, code style, documentation ve performance best practices içerir.
checkstyle-rules
Use when applying Checkstyle built-in checks for Java code including naming conventions, code metrics, and suppressions.
assistant-behavior-rules
AI assistant behavior rules including response formatting and interaction patterns
anti-ai-writing
Transform AI-assisted drafts into authentic, human-sounding content. This skill provides patterns to detect and eliminate AI tells, frameworks for natural writing, and techniques for creating prose that reads as genuinely human. Use when reviewing any AI-generated content or when writing content that must not appear AI-assisted.
ameba-custom-rules
Use when creating custom Ameba rules for Crystal code analysis including rule development, AST traversal, issue reporting, and rule testing.
alpine-js-usage-rules
Guidelines for using Alpine.js for declarative JavaScript functionality.
agp-router-rules
Rules for using the Agp Router.