When working with AI-powered code editors like Cursor, developers often experience the frustration of repeating the same instructions or watching their AI assistant make decisions that don't align with their project's architecture. What if there were a way to give the AI assistant a persistent memory and consistent instructions? Enter Cursor Rules and Memory Banks.
What Are Cursor Rules?
Cursor Rules are saved prompts that provide consistent instructions to the AI assistant. Think of them as system prompts that shape how the AI responds to requests. Though this article focuses on Cursor, similar features exist in editors like Windsurf and Cline.
Rules in Cursor are stored in the project’s .cursor/rules directory, where multiple rules can trigger at different times:
- Always: Applied to every request
- Auto: Let the AI decide when to use the rule
- Manual: Only used when explicitly referencing the rule
Creating Your First Rule
Let's start with a simple example. Rules can be created through Cursor's settings UI or by creating files directly in the .cursor/rules directory.
To create a rule through the UI:
- Open Cursor settings (top right)
- Navigate to Rules
- Click "Add new rule"
Here's a basic rule that prevents the AI from using excessive preamble:
---
rule_type: always
---
Never use phrases like "Certainly!", "Of course!", or "Great question!"
Just provide the answer directly without apologies or excessive politeness.
The Power of Project-Specific Context
One of the most valuable uses of rules is providing project-specific context. For example, when working with a specific GitHub repository, a rule can be defined to clarify which repository the AI should reference:
---
rule_type: always
---
When I mention "the repository" or "this repo", I'm referring to:
https://github.com/lullabot/project-name
Always use this URL when creating issues or accessing GitHub resources.
This eliminates the need to constantly specify which repository is used when working with GitHub-related MCP (Model Context Protocol) tools.
Introducing Memory Banks
While Rules guide how the AI thinks, Memory Banks allow it to remember. The Cursor Memory Bank is a community project that sets up a structured way to maintain project context across chat sessions.
Installing Memory Bank
Installation is incredibly simple. In the project directory, run:
npx cursor-bank init
This creates two essential rules:
- Core Rule: Implements plan/act modes to prevent runaway AI actions
- Memory Bank Rule: Sets up the memory structure
The Plan/Act Pattern
One of the most valuable patterns in Memory Bank is the plan/act mode. This mode separates planning from execution to avoid unintended changes.
- Plan Mode: The AI helps define a plan without making changes
- Act Mode: The AI executes the agreed-upon plan
Here's how it works in practice:
You: Plan: Add a new authentication system to the app
AI: [Provides detailed plan without making changes]
You: Looks good, act
AI: [Executes the plan]
This pattern has been transformative for many developers, preventing those "Wait, no, stop!" moments when the AI starts making unintended changes.
Memory Bank Structure
The Memory Bank creates several markdown files in a /memory_bank directory:
- projectbrief.md: High-level project overview
- techContext.md: Technologies, versions, and development setup
- systemPatterns.md: Architecture patterns and coding standards
- productContext.md: Feature descriptions and business logic
- activeContext.md: Current work focus and immediate tasks
- progress.md: Completed work and implementation history
The beauty of this system is that most of these files (like techContext and systemPatterns) remain relatively stable, while activeContext and progress update frequently while working.
Keeping Memory Updated
After completing features or making significant changes, it's crucial to update the memory bank:
You: Update memory bank
AI: [Reviews all memory files and updates relevant sections]
This ensures that your next chat session has access to the latest project state.
Real-World Benefits
Here are some practical benefits our team has experienced:
1. Consistent Technology Choices
AI assistants might suggest switching libraries when encountering minor issues without memory banks. With a documented tech stack in the memory bank, the AI stays consistent with architectural decisions.
2. Better Project Onboarding
Memory banks serve as living documentation. When exploring a new codebase, having the AI analyze and document undocumented features can reveal insights like authentication systems or API patterns that weren't obvious before.
3. Project Management Integration
Some team members use memory banks beyond coding—tracking tasks, storing meeting summaries, and maintaining stakeholder information. This creates a comprehensive project context that goes beyond just code.
Considerations and Best Practices
Model Selection
Not all AI models respect rules equally. Based on our experience:
- GPT-4o: Great for general use, follows instructions well
- Gemini 2.5 Pro: Excellent at instruction following, with thinking capabilities
- Claude 3.5 Sonnet: Creative but may occasionally ignore rules
When using "Auto" mode for model selection, be aware that it might not always pick up the rules, especially with less capable models.
Privacy and Repository Considerations
When deciding whether to commit memory banks to a repository, consider:
- Most memory bank files are essentially project documentation and are safe to commit
- Be cautious with activeContext.md if it contains sensitive work-in-progress information
- Never commit transcripts or meeting notes that might contain private conversations
- Consider using a separate private repository for sensitive memory bank content
Avoiding "Poisoned" Context
Review AI-generated memory bank content before accepting it. While rare, incorrect information in memory banks could affect future interactions. The plan/act pattern helps here by providing a chance to review before accepting changes.
Future Considerations
As AI-powered development tools evolve, similar memory concepts appear across different platforms. The challenge will be standardizing these formats to share memory and rules across different editors.
Some teams are already exploring:
- Shared rule libraries for common patterns
- Standardized memory bank formats
- Integration with CI/CD pipelines for automatic memory updates
Getting Started
Here’s a quick start guide to implementing rules and memory banks:
- Install Memory Bank: npx cursor-bank init
- Initialize memory: Tell the AI to "plan: initialize memory bank" and provide some initial context
- Review and approve the plan
- Execute with "act"
- Start using the plan/act mode for all development tasks
- Remember to "update memory bank" after completing features
Combining Cursor Rules and Memory Banks transforms AI-assisted development from a series of disconnected conversations into a continuous, context-aware collaboration. Give it a try to see how much more effective the AI pair programming becomes.