> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bsyncs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cursor Setup

> Give Cursor persistent memory across coding sessions using the Atlas SDK.

Cursor is an AI-first code editor. By wiring Atlas into it, you can have Cursor **remember architectural decisions, project conventions, past bugs, and team preferences** across sessions — even across different projects.

***

## Prerequisites

* Cursor installed and configured
* Atlas API key from [atlas.bsyncs.com](https://atlas.bsyncs.com)
* Python 3.9+

***

## Step 1 — Install the SDK

Open Cursor's integrated terminal and run:

```bash theme={null}
pip install atlas-mem
```

***

## Step 2 — Create the memory helper script

Create a file called `atlas_memory.py` in your project root. Cursor's AI features can call this directly.

```python theme={null}
# atlas_memory.py
"""
Atlas memory helper for Cursor sessions.
Usage:
  python atlas_memory.py add "We decided to use Postgres over MySQL for ACID compliance."
  python atlas_memory.py search "database choice"
  python atlas_memory.py ask "Why did we choose Postgres?"
"""

import sys
import os
from atlas_mem import AtlasMem

brain = AtlasMem(
    api_key=os.environ["ATLAS_API_KEY"],
    base_url="https://api.bsyncs.com",
    user_id=os.environ.get("ATLAS_USER_ID", "cursor-dev"),
    persona=os.environ.get("ATLAS_PERSONA", "shared"),
    session_id=os.environ.get("ATLAS_SESSION_ID"),
)

def main():
    if len(sys.argv) < 3:
        print("Usage: python atlas_memory.py [add|search|ask] <text>")
        sys.exit(1)

    command = sys.argv[1]
    text = " ".join(sys.argv[2:])

    if command == "add":
        result = brain.add(text, source="user")
        print(f"Stored: {result.entities_extracted} entities, {result.triples_extracted} relations")

    elif command == "search":
        results = brain.search(text, k=5)
        print(results.format())

    elif command == "ask":
        answer = brain.ask(text, max_hops=3)
        print(answer)

    else:
        print(f"Unknown command: {command}")

if __name__ == "__main__":
    main()
```

***

## Step 3 — Set environment variables

Add these to your shell profile (`~/.zshrc` or `~/.bashrc`) or a `.env` file in your project:

```bash theme={null}
export ATLAS_API_KEY="atlas_your_key_here"
export ATLAS_USER_ID="your-name"           # your personal namespace
export ATLAS_SESSION_ID="cursor-session"   # optional working memory
```

<Warning>
  Add `.env` to your `.gitignore`. Never commit API keys.
</Warning>

***

## Step 4 — Create a Cursor Rule

Go to **Cursor Settings → Rules for AI** and add the following rule. This teaches Cursor to consult Atlas before and after each significant response.

```text theme={null}
You have access to a long-term memory system called Atlas.

BEFORE answering architectural, technical, or project-specific questions, run:
  python atlas_memory.py search "<summary of the question>"
and include the retrieved context in your response.

AFTER making an important architectural decision, design choice, or discovering a non-obvious bug fix, run:
  python atlas_memory.py add "<concise fact about the decision>"

Facts worth storing:
- Technology choices and their rationale ("We use gRPC over REST for internal services because...")
- Non-obvious bug fixes ("The race condition in payment_service.py was caused by...")
- Team conventions ("All API responses use snake_case, never camelCase")
- Performance findings ("Redis pipeline batching reduced latency by 40% for bulk writes")
- Dependency notes ("Do not upgrade langchain-core above 0.2.40 — breaks graph transformer")
```

***

## Step 5 — Test it

In Cursor's terminal:

```bash theme={null}
# Store your first architectural decision
python atlas_memory.py add "We use PostgreSQL as the primary database. Chose it over MySQL for better JSONB support and ACID compliance on complex transactions."

# Ask a question
python atlas_memory.py ask "Why do we use PostgreSQL?"
```

Now open Cursor's chat and ask: *"What database are we using and why?"* — Cursor will retrieve and surface the answer from Atlas.

***

## Tips for Cursor + Atlas

<AccordionGroup>
  <Accordion title="Store decisions immediately">
    The best habit is to store a fact right after Cursor makes a recommendation you accept. Say: *"Store this decision in Atlas"* and Cursor will run `atlas_memory.py add` for you.
  </Accordion>

  <Accordion title="Use project-specific personas">
    Set `ATLAS_PERSONA=<project-name>` so memories from different projects stay separated, even under the same user namespace.
  </Accordion>

  <Accordion title="Search before asking">
    Before asking Cursor a question about an existing system, prompt it with: *"Search Atlas for context on X, then answer."* This ensures it uses your stored knowledge before hallucinating.
  </Accordion>
</AccordionGroup>
