Unleashing AI Power with Rules Files: Utilize 100% of Cursor and Windsurf

M.F.M Fazrin
4 min readDec 16, 2024

--

Rules files, although named differently across various coding platforms, are a powerful tool to enhance your AI coding experience. These files allow you to provide explicit context that’s automatically included in all your AI interactions.

Whether you’re using a code composer, chat interface, or a code editor, rules files help AI become deeply familiar with:

  1. Project Context: Understanding the project’s purpose and broad objectives.
  2. Code Style and Structure: Knowing your coding preferences and conventions.
  3. Tech Stack: Identifying the programming languages and tools you’re utilizing.

These files might be stored under different names (e.g., .github/copilot-instructions.md, .cursorrules, .windsurfrules), but they all operate on the same fundamental principle: providing context for your AI assistant.

A Practical Example of Rules in Action

Imagine a project where you have a rules file defined as follows:

# VisaReady Appointment System  ## Project Context
Every time you choose to apply a rule(s), explicitly state the rule(s) in the output. You can abbreviate the rule description to a single word or phrase.
# Project Context
Server and Chrome extension for automating visa application slot booking process that
- auto fills the visa application form
- auto checks for appointment availability
- auto books the appointment
# Code Style and Structure
- Write concise, technical TypeScript code with accurate examples
- Use functional and declarative programming patterns; avoid classes
- Prefer iteration and modularization over code duplication
- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError)
- Structure repository files as follows:
server/
src/
components/ # Shared React components
hooks/ # Custom React hooks
utils/ # Helper functions
types/ # TypeScript types
lib/ # Shared Libraries
extension/
src/
background/ # Service worker scripts
content/ # Content scripts
popup/ # Extension popup UI
options/ # Extension options page
components/ # Shared React components
hooks/ # Custom React hooks
lib/ # Shared Libraries
types/ # Chrome storage utilities
shared/
src/
types/ # TypeScript types, only used for shared types between server and extension
utils/ # Helper functions, only used for shared functions between server and extension

This file specifies the project’s purpose, the required code style, and structure. To further illustrate how the rules file is being used, you could add a rule like “Say HOHOHO at the beginning of the output”. This clearly shows the effect of the rules file on the AI’s output.

With this rules file in place, any interaction with the AI will now begin with “HOHOHO”, demonstrating that the context is being seamlessly applied.

Why Rules Files Are So Effective

The key to the effectiveness of rules files lies in a rule similar to: “Every time you choose to apply a rule(s), explicitly state the rule(s) in the output. You can abbreviate the rule description to a single word or phrase.”

This simple rule drastically improves the transparency of the AI’s decision-making. By requiring the AI to report the rules it’s following, you gain a clear understanding of its process, reducing the “black box” effect.

Here are key benefits of using Rules Files:

  1. Transparency: The explicit reporting of used rules acts as a real-time sanity check. You can directly see which rules are influencing the AI’s suggestions.
  2. Purpose-Driven Output: The context provided allows the AI to understand the “why” behind the project, moving beyond generic responses to more targeted solutions.
  3. Code Consistency: Rules files enforce project-specific code styles and conventions, ensuring consistency across a codebase, especially beneficial for teams.
  4. Tech Stack Awareness: The rules file guides the AI to use appropriate technology, preventing unwanted dependencies and maintaining a coherent stack.

The Evolving Future of Rules Files

The future of rules files is bright. Imagine being able to automatically trigger different sets of rules based on the type of code you’re working on (e.g., database-related code).

By continuously working with and updating your rules file, the AI will adapt to your personal coding style, providing more and more consistent code generations over time.

Principles for Maintaining Effective Rules Files

Here are two key principles to follow:

  1. Keep it concise: Avoid clutter. Concise files are more effective, easier to maintain, and less confusing for the AI.
  2. Continuously update: Rules files should be treated as living documents. When the AI makes consistent mistakes, update the file with rules to address them.

Rules files greatly improve the effectiveness of your AI coding partner by providing an explicit framework for understanding your project’s needs, style, and technology.

By implementing these principles, you can enhance your development workflow and get the most out of your AI coding assistant.

--

--

M.F.M Fazrin
M.F.M Fazrin

Written by M.F.M Fazrin

Senior Software Development Specialist @ Primary Health Care Corporation (Qatar)

Responses (1)