Chapter 4: Setting Up Rules for Vibe Coding
What Are Rules in Vibe Coding?
Rules in vibe coding tools are essentially system prompts that get included in every single interaction with your AI assistant. Think of them as permanent instructions that shape how your AI writes code, makes decisions, and follows workflows.
Unlike one-off prompts, rules are persistent guidelines that ensure consistency across your entire development process. They're like having a coding standards document that your AI automatically references every time it generates code.
Key benefits of rules:
- Maintain consistent coding patterns across projects
- Prevent repetitive issues you've encountered before
- Enforce best practices specific to your tech stack
- Customize AI behavior to match your development style
- Save time by not having to repeat the same instructions
Types of Rules: Global vs Workspace
Most vibe coding tools support two types of rules:
Global Rules
Apply to every project you work on
These are your universal coding preferences and workflows that should be consistent regardless of the specific project. Examples include:
- File organization preferences
- General coding standards (avoiding duplication, keeping functions short)
- Development workflow preferences (always restart servers after changes)
- Safety practices (environment-specific behaviors)
Workspace Rules
Apply only to the current project
These are project-specific guidelines that relate to the particular tech stack, architecture, or requirements of what you're building. Examples include:
- Framework-specific best practices (React patterns, Python FastAPI conventions)
- Project architecture decisions
- Specific libraries or tools being used
- Custom naming conventions for this project
Pro tip: Start with global rules for general workflow preferences, then add workspace rules as you encounter project-specific patterns you want to enforce.
Essential Workflow Rules
Based on common vibe coding experiences, here are the most impactful workflow rules to implement:
Server Management
Rule: "After making changes, always make sure to start up a new server so I can test it."
Why this matters: AI often makes changes but doesn't restart development servers, leaving you manually killing and restarting processes. This rule automates that workflow.
Code Evolution Over Recreation
Rule: "Always look for existing code to evolve or iterate on before writing completely new code. Do not drastically change existing patterns before trying to iterate on them first."
The problem it solves: AI assistants often write entirely new code instead of modifying existing functionality, leading to inconsistent patterns and duplicated logic.
Simplicity and Modularity
Rules:
- "Always prefer simple solutions"
- "Avoid duplication of code"
- "Keep files short (200-300 lines maximum)"
- "Break large functions into smaller, focused functions"
Impact: These rules maintain code quality and make it easier for AI to understand and modify code in future iterations.
Environment Awareness
Rule: "Write code that takes into account the different environments: dev, test, and prod."
What this means:
- Dev environment: Your local development setup (localhost)
- Test environment: Where automated tests run
- Production environment: What users actually see
Why it's crucial: Different environments need different configurations, data sources, and behaviors. AI needs explicit guidance about these distinctions.
Script Management
Rule: "Avoid writing scripts to files if possible, especially if the script is likely only to be run once. Run scripts in console or delete the file after completion."
The problem: AI often creates script files for one-time tasks, cluttering your project with files you'll never use again.
Language and Framework-Specific Rules
Beyond general workflow rules, you'll want rules specific to your tech stack. The open-source "Awesome Cursor Rules" repository on GitHub provides excellent starting points for various technologies.
Frontend Framework Rules (Example: React)
- Use functional components with hooks
- Prefer composition over inheritance
- Use TypeScript for type safety
- Follow consistent naming conventions for components
- Keep components small and focused
- Use proper state management patterns
Backend Framework Rules (Example: Python FastAPI)
- Use functional components for route handlers
- Use declarative route definitions
- Implement proper error handling for all endpoints
- Follow REST conventions for API design
- Use dependency injection for database connections
- Include proper input validation
Database Rules
- Use parameterized queries to prevent SQL injection
- Implement proper connection pooling
- Include database migration scripts for schema changes
- Use transactions for multi-step operations
- Follow consistent naming conventions for tables and columns
Setting Up Rules in Different Tools
Windsurf/Cascade
- Look for "Windsurf Settings" in the bottom right
- Click "Memories and Rules" → "Manage"
- Add rules under "User-defined rules"
- Choose between Global Rules (all projects) or Workspace Rules (current project only)
Cursor
- Open settings/preferences
- Navigate to "Rules" section
- Add global rules in your user settings
- Add project-specific rules in .cursorrules file in your project root
Cline
- Access settings through the extension panel
- Look for "Rules" or "System Prompt" configuration
- Add your rules in the designated text area
Format: Rules are typically written in plain markdown format using natural language - no special syntax required.
Iterative Rule Development
The most effective approach to building rules is iterative refinement based on actual coding experiences:
Step 1: Start with Basic Workflow Rules
Begin with fundamental workflow preferences:
- Server restart behavior
- File size limits
- Code evolution preferences
- Environment awareness
Step 2: Notice and Document Patterns
As you vibe code, pay attention to:
- Repetitive issues that keep occurring
- AI behaviors that don't match your preferences
- Code patterns you want to encourage or discourage
Step 3: Convert Observations to Rules
When you notice unwanted AI behavior, immediately add a rule to prevent it:
Example: "I noticed the AI keeps creating utility functions in the main component file instead of separating them. I'll add a rule: 'Create separate utility files for helper functions instead of including them in component files.'"
Step 4: Test and Refine
After adding new rules:
- Test them in real coding sessions
- Refine the wording if the AI misinterprets them
- Remove rules that don't actually improve outcomes
Did You Know? The most successful vibe coders treat their rules as living documents, constantly evolving based on real project experiences.
Advanced Rule Strategies
Conditional Rules
Write rules that apply in specific contexts:
"When working with user authentication:
- Always hash passwords before storing
- Implement proper session management
- Include rate limiting for login attempts
- Use HTTPS in production environments"
Priority Rules
When rules might conflict, establish priority:
"Priority order for code organization:
1. Security (never compromise security for convenience)
2. Maintainability (prefer readable code over clever solutions)
3. Performance (optimize only after profiling shows need)
4. Development speed (choose faster implementation when quality is equal)"
Anti-Pattern Rules
Explicitly prevent common mistakes:
"Never do the following:
- Hard-code API keys or passwords in source code
- Use global variables for state management
- Write functions longer than 50 lines without clear justification
- Ignore error handling in production code"
Context-Aware Rules
Rules that adapt to different project phases:
"During rapid prototyping phase:
- Prioritize functionality over perfect code structure
- Use placeholder data and mock services
- Focus on core user flows before edge cases
During production preparation:
- Implement comprehensive error handling
- Add logging and monitoring
- Optimize performance critical paths
- Include comprehensive tests"
Rule Maintenance and Organization
Categorize Your Rules
Organize rules into logical groups:
- Workflow Rules: Development process preferences
- Code Quality Rules: Standards for clean, maintainable code
- Security Rules: Safety and security practices
- Performance Rules: Optimization guidelines
- Framework Rules: Technology-specific best practices
Regular Review Process
Schedule periodic rule reviews:
- Weekly: Review new rules added during active development
- Monthly: Assess which rules are most/least effective
- Quarterly: Major cleanup and reorganization of rule sets
Version Control for Rules
Track changes to your rules:
- Keep rules in version control alongside your code
- Document why specific rules were added
- Note when rules are modified or removed
- Share effective rules with team members
Team Collaboration
For team projects:
- Establish shared global rules for consistency
- Allow individual workspace rules for personal preferences
- Regular team reviews of rule effectiveness
- Document team decisions about rule additions/changes
Common Rule Pitfalls to Avoid
Over-Specification
Problem: Rules that are too detailed or restrictive can limit AI creativity and problem-solving ability.
Solution: Focus on principles and outcomes rather than specific implementation details.
Bad: "Always use exactly 2 spaces for indentation and place opening braces on the same line" Good: "Follow consistent formatting and indentation throughout the project"
Conflicting Rules
Problem: Rules that contradict each other confuse the AI and lead to inconsistent behavior.
Solution: Regularly review rules for conflicts and establish clear priorities when conflicts arise.
Outdated Rules
Problem: Rules based on old project requirements or outdated best practices.
Solution: Regular rule maintenance and updates based on evolving project needs.
Too Many Rules
Problem: Overwhelming the AI with excessive rules can reduce performance and clarity.
Solution: Focus on the most impactful rules and combine related rules where possible.
Key Takeaways
Rules Are System Prompts: They're persistent instructions that guide every AI interaction, ensuring consistent behavior across your development process.
Start Simple, Iterate: Begin with basic workflow preferences, then add rules based on actual coding experiences and observed AI behavior patterns.
Global vs Workspace: Use global rules for universal preferences and workspace rules for project-specific requirements.
Language-Specific Rules Matter: Leverage existing rule sets from resources like "Awesome Cursor Rules" for your tech stack.
Maintenance Is Key: Regularly review, update, and refine your rules based on their effectiveness in real projects.
Quality Over Quantity: Focus on rules that solve actual problems you've encountered rather than trying to anticipate every possible scenario.
Rules transform vibe coding from ad-hoc interactions into a structured, consistent development workflow that maintains quality while preserving the creative flow that makes vibe coding powerful.