Cursor rules for adding memory to your app

This rule defines how the AI agent should manage and utilize memory improve coding consistency.
Back to rules
Type
Integration
Stats
490 views
61 copies
33 downloads
Author
Elie Steinbock
Elie Steinbock
memory.mdc
---
description: This rule defines how the AI agent should manage and utilize memory improve coding consistency.
globs: *
alwaysApply: false
---

# AI Memory Rule

This rule defines how the AI should manage and utilize its "memory" regarding this specific project, including user preferences, learned facts, and project-specific conventions.

## Purpose

The AI's memory helps maintain consistency and adapt to specific project needs or user preferences discovered during interactions. It prevents the AI from repeatedly asking for the same information or making suggestions contrary to established patterns.

## Storage

All learned project-specific knowledge and preferences should be stored and referenced in the `learned-memories.mdc` file located in `.cursor/rules`.

## Updating Memory

When new information relevant to the project's conventions, user preferences, or specific technical details is learned (either explicitly told by the user or inferred through conversation), the AI should:

1.  **Identify Key Information:** Determine the core piece of knowledge to be stored.
2.  **Check Existing Memory:** Review `learned-memories.mdc` to see if this information contradicts or updates existing entries.
3.  **Propose Update:** Suggest an edit to `learned-memories.mdc` to add or modify the relevant information. Keep entries concise and clear.

## Using Memory

Before proposing solutions, code changes, or answering questions, the AI should consult `learned-memories.mdc` to ensure its response aligns with the recorded knowledge and preferences.

## Example Scenario

**User:** "We've decided to use Tailwind v4 for this project, not v3."

**AI Action:**

1.  Recognize this as a project-specific technical decision.
2.  Check `learned-memories.mdc` for existing Tailwind version information.
3.  Propose adding or updating an entry in `learned-memories.mdc`:
    ```markdown
    ## Technical Decisions

    *   **CSS Framework:** Tailwind v4 is used. Ensure usage aligns with v4 documentation and practices, noting differences from v3.
    ```
4.  In subsequent interactions involving Tailwind, the AI will refer to this entry and consult v4 documentation if necessary.

## Memory File (`.cursor/rules/learned-memories.mdc`)

The basic structure:

```markdown
# Project Memory

This file stores project-specific knowledge, conventions, and user preferences learned by the AI assistant.

## User Preferences

-   [Preference 1]
-   [Preference 2]

## Technical Decisions

-   [Decision 1]
-   [Decision 2]

## Project Conventions

-   [Convention 1]
-   [Convention 2]
```

The Memory rule in Cursor helps maintain consistency and context in your coding projects by storing and utilizing information about your preferences, project conventions, and technical decisions. This persistent memory allows the AI to provide more relevant assistance without repeatedly asking you for the same information.

What this rule does

The Memory rule establishes a system for the AI to:

  1. Record and maintain project-specific knowledge
  2. Store user preferences learned during interactions
  3. Remember technical decisions and conventions
  4. Reference this stored knowledge when providing assistance

This functionality helps the AI adapt to your specific project needs while ensuring its suggestions remain consistent with previously established patterns and preferences.

How memory works in Cursor

Storage mechanism

The rule creates and maintains a dedicated markdown file called learned-memories.mdc located in the .cursor/rules directory of your project. This file serves as the central repository for all project knowledge and follows a structured format:

# Project Memory

This file stores project-specific knowledge, conventions, and user preferences learned by the AI assistant.

## User Preferences

  [Preference 1]
  [Preference 2]

## Technical Decisions

  [Decision 1]
  [Decision 2]

## Project Conventions

  [Convention 1]
  [Convention 2]

Memory update process

The AI updates its memory through a systematic process:

  1. It identifies key information that should be remembered
  2. Reviews the existing learned-memories.mdc file for contradictions or updates
  3. Proposes appropriate additions or modifications to the file
  4. Uses this stored knowledge in future interactions

Example scenario

Consider this interaction with the AI:

You: "We've decided to use Tailwind v4 for this project, not v3."

AI's response and actions:

  1. Recognizes this as an important technical decision
  2. Checks if any existing Tailwind information is stored
  3. Proposes updating the memory file with:
## Technical Decisions

*   **CSS Framework:** Tailwind v4 is used. Ensure usage aligns with v4 documentation and practices, noting differences from v3.

In subsequent interactions involving Tailwind CSS, the AI will reference this memory to ensure its suggestions align with version 4 requirements.

Using Memory in Cursor

The Memory rule is stored as memory.mdc in your project's .cursor/rules directory. Based on its glob pattern (*), this is an "Auto Attached" rule that applies to all files in your project, meaning the AI will consistently maintain and reference its memory across your entire codebase.

To leverage this rule effectively:

  1. Make sure the .cursor/rules directory exists in your project
  2. Ensure the memory.mdc file is present in that directory
  3. Create the initial learned-memories.mdc file or let the AI create it when needed

Since this rule is automatically applied, you don't need to manually invoke it. The AI will naturally begin tracking important information during your conversations and suggest updates to the memory file when appropriate.

Usage tips

Be explicit about preferences

While the AI can infer some preferences, being explicit helps build a more accurate memory. Statements like "I prefer using arrow functions instead of function declarations" or "We follow the Airbnb style guide for this project" provide clear information for the AI to store.

Review memory updates

When the AI suggests updating the memory file, review the changes to ensure they accurately reflect your intentions. This helps prevent misunderstandings from being stored as "facts" about your project.

Reference specific memories

If you want the AI to specifically consider a certain preference or decision, you can directly reference it: "Remember that we're using Tailwind v4 for this project when suggesting CSS solutions."

Periodically review the memory file

Occasionally review the learned-memories.mdc file to remove outdated information or clarify ambiguous entries. This ensures the AI continues to provide relevant assistance based on current project requirements.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later