Problem: Inconsistent AI Assistance Across Your Team
Your team uses Cursor AI, but everyone gets different code suggestions. Junior devs receive unsafe patterns, seniors fight with formatting preferences, and code reviews become arguments about "what the AI suggested."
You'll learn:
- How to create team-wide Cursor rules
- Version control strategies for .cursorrules
- Testing rules before rollout
Time: 20 min | Level: Intermediate
Why This Happens
Cursor uses .cursorrules files to customize AI behavior, but without team standards:
Common symptoms:
- Different developers get conflicting suggestions
- AI generates code that fails CI/CD checks
- New team members adopt bad patterns from AI
- No enforcement of architectural decisions
Solution
Step 1: Create a Base .cursorrules File
Start with team-wide standards in your repo root:
# In your project root
touch .cursorrules
Expected: Empty file ready for configuration
Step 2: Define Core Team Rules
# .cursorrules - Team Standards
## Language & Framework
- TypeScript 5.5+ with strict mode
- React 19 with Server Components
- No class components (use hooks)
## Code Style
- Max line length: 100 characters
- Use named exports (not default)
- Prefer const assertions over enums
## Architecture
- Feature-based folder structure (/features/auth/...)
- Separate business logic from UI (use custom hooks)
- API calls only in /lib/api/* files
## Forbidden Patterns
- NO any types (use unknown)
- NO var declarations
- NO .then() chains (use async/await)
- NO inline styles in JSX
## Testing Requirements
- Every component needs a .test.tsx file
- Use React Testing Library (not Enzyme)
- Mock external APIs, never hit real endpoints
## Comments
- Explain WHY, not WHAT
- Add JSDoc for public functions
- No commented-out code in PRs
## Dependencies
- Check package.json before suggesting new deps
- Prefer standard library over lodash
- Security: no packages with known vulnerabilities
Why this works: Cursor reads these rules before generating code, enforcing standards automatically.
If it fails:
- AI ignores rules: Be more specific ("use arrow functions" → "ALL functions must use arrow syntax: const fn = () => {}")
- Too restrictive: Start minimal, add rules as issues arise
Step 3: Add Project-Specific Context
## Project Context
- E-commerce platform, PCI-DSS compliant
- Never log payment data (card numbers, CVV)
- All monetary values use Decimal.js (not Number)
## API Integration
- Backend is /api/v2/* (v1 deprecated)
- Always include Authorization header
- Retry failed requests 3 times with exponential backoff
## Performance
- Images via next/image with priority prop
- Lazy load below-fold components
- Bundle size: warn at 100KB, fail at 150KB
Step 4: Version Control Strategy
Add to your .gitignore:
# Local Cursor overrides
.cursorrules.local
Team workflow:
# 1. Team rules (committed)
/.cursorrules
# 2. Personal overrides (not committed)
/.cursorrules.local
Create .cursorrules.local for individual preferences:
# Personal .cursorrules.local
## My Preferences
- Add verbose comments (learning phase)
- Suggest performance optimizations
- Prefer functional programming patterns
Cursor merges both files: Team rules + your local additions.
Step 5: Test Before Rolling Out
Create a test file:
// test-cursor-rules.ts - Deliberately break rules
export default function TestComponent() { // Should suggest named export
var count = 0; // Should suggest const
const data: any = {}; // Should suggest unknown
return <div style={{color: 'red'}}>{count}</div>; // Should flag inline style
}
Expected: Cursor should warn about all violations before you even ask.
If it fails:
- Rules are too vague (add examples)
- File isn't in repo root (Cursor reads from project root up)
Step 6: Automate Rule Validation
Add a pre-commit hook:
# .husky/pre-commit
#!/bin/sh
# Check if .cursorrules changed
if git diff --cached --name-only | grep -q "^.cursorrules$"; then
echo "✅ .cursorrules updated - notify team in Slack"
# Optional: Post to Slack/Discord
fi
Why: Team knows when rules change, avoids surprise CI failures.
Verification
Test it:
- Open Cursor in your project
- Ask: "Create a new React component for user login"
- Check generated code follows your rules
You should see:
- Named export (not default)
- TypeScript with strict types
- No inline styles
- Proper file structure
What You Learned
.cursorrulesin repo root = team standards.cursorrules.local= personal overrides (gitignored)- Be specific in rules ("no X" → "use Y instead")
- Test with intentionally bad code
Limitations:
- Cursor may still suggest rule violations (it's AI, not a linter)
- Complex architectural rules need human review
- Rules don't replace code reviews
Advanced: Role-Based Rules
For larger teams, create role-specific rule files:
.cursorrules # Base rules
.cursorrules.backend # API development
.cursorrules.frontend # UI components
.cursorrules.data # Analytics/ML
Load based on directory:
# In .cursorrules
- If working in /apps/api/*, also read .cursorrules.backend
- If working in /apps/web/*, also read .cursorrules.frontend
Team Rollout Checklist
- Create base
.cursorruleswith 5-10 core rules - Test with intentionally bad code
- Add to repo root and commit
- Document in README how to add personal rules
- Add
.cursorrules.localto.gitignore - Notify team in Slack/standup
- Review AI suggestions in first week
- Refine rules based on feedback
Common Team Rules Library
- Never hardcode API keys (use env vars)
- Sanitize user input before DB queries
- Use parameterized queries (no string concatenation)
Performance:
- Database queries: add LIMIT clause
- Use pagination for lists >100 items
- Memoize expensive calculations
Accessibility:
- All images need alt text
- Buttons need aria-labels
- Forms need proper label associations
Git:
- Commit messages: type(scope): description
- Branch names: feature/TICKET-123-description
- No force push to main/develop
Tested with Cursor 0.41+, works with VS Code Cursor fork
Pro tip: Start minimal (10 rules max), add more as team identifies patterns worth enforcing. Too many rules = AI gets confused.