# Introducing the Mem0 Plugin for Pi Code

Deshraj Yadav  
June 24, 2026

Give Pi Code persistent, scoped, semantic memory across sessions and projects.

Pi Code is a terminal coding agent that can read your repo, make changes, run commands, and help you move through development tasks.

But like most coding agents, it should not have to start from zero every session. Project structure, preferences, prior decisions, migration patterns, and mistakes to avoid should carry forward.

Today, we are launching the Mem0 plugin for Pi Code: a Pi Agent extension that gives your coding agent long-term memory powered by Mem0.

Install it with:

```bash
pi install npm:@mem0/pi-agent-plugin
```

## What the plugin does

The Mem0 plugin gives Pi persistent semantic memory that works across sessions, projects, and devices. It can capture useful context from conversations, retrieve relevant memories by meaning, and help manage memory directly from the terminal.

The plugin includes:

- Automatic memory capture from user and assistant messages  
- Semantic search, so memories can be found by meaning instead of exact keywords  
- Project, session, and global memory scopes  
- Monorepo-aware project detection using the git root  
- Dream consolidation to merge duplicates, resolve contradictions, and prune stale entries  
- Eight slash commands for memory management  
- An agent-accessible `mem0_memory` tool for search, add, update, and delete actions

The goal is simple: Pi should not have to relearn your working context every time you start a new session.

## Setup

First, sign up for Mem0 and get an API key from the dashboard: [https://app.mem0.ai/](https://app.mem0.ai/)

Then install the plugin:

```bash
pi install npm:@mem0/pi-agent-plugin
```

Set your API key:

```bash
export MEM0_API_KEY="m0-your-key-here"
```

You can also configure the plugin with a local config file at:

`~/.pi/agent/mem0-config.json`

Example config:

```json
{
  "apiKey": "m0-your-key-here",
  "userId": "your-username",
  "autoCapture": true,
  "defaultScope": "project",
  "searchThreshold": 0.3,
  "dream": {
    "enabled": true,
    "auto": true,
    "minHours": 24,
    "minSessions": 5,
    "minMemories": 20
  }
}
```

Environment variables such as `MEM0_API_KEY` and `MEM0_USER_ID` override the config file.

## Memory scopes

The plugin supports three scopes:

| Scope   | Filters                   | Use case                       |
| ------- | ------------------------- | ------------------------------ |
| `project` | user + app_id            | Default. Project-specific knowledge |
| `session` | user + app_id + run_id   | Session-only context           |
| `global`  | user only                | Memories across projects       |

Project scope is the default. The plugin detects the project using:

```bash
git rev-parse --show-toplevel
```

That means subdirectories inside the same monorepo share the same project memory pool. If you work in multiple repos, their memories stay separated by default.

## Slash commands

The plugin gives you direct memory controls inside Pi:

| Command                        | What it does                                   |
|-------------------------------|------------------------------------------------| 
| `/mem0-remember <text>`      | Store a memory verbatim                        |
| `/mem0-search <query>`       | Search memories semantically                   |
| `/mem0-forget <query>`       | Search and delete memories, with confirmation  |
| `/mem0-tour [scope]`         | Browse memories grouped by category            |
| `/mem0-dream`                | Consolidate memories                           |
| `/mem0-pin <query>`          | Protect a memory from dream pruning            |
| `/mem0-scope <scope>`        | Change the default scope for the session      |
| `/mem0-status`               | Check connection health, identity, project, and memory count |

For example:

```bash
/mem0-remember "Use TypeScript instead of JavaScript for new files in this repo"
/mem0-search language preferences
/mem0-status
```

The plugin also registers a `mem0_memory` tool that Pi can use directly. The tool supports actions including `search`, `add`, `get_all`, `update`, `delete`, and `delete_all`.

## What Pi can remember

Memories are classified into ten general-purpose categories: identity, preferences, goals, projects, decisions, technical, relationships, routines, lessons, and work.

For coding workflows, the most useful memories are often technical decisions, project context, preferences, and lessons learned:

- Use Zod for request validation in API routes.
- This repo uses pnpm, not npm.
- Do not edit generated files in src/generated.
- The migration script must be idempotent.
- Prefer TypeScript for new projects.

Once saved, those memories can be searched later by meaning, not just by exact wording.

## Dream consolidation

Long-term memory is only useful if it stays clean.

The plugin includes a dream consolidation workflow that reviews memories and helps merge duplicates, resolve contradictions, and prune stale entries. You can trigger it manually:

```bash
/mem0-dream
```

The plugin can also run dream consolidation automatically when its configured gates are met. By default, the config enables automatic dream consolidation after minimum thresholds for time, sessions, and memory count.

If a memory is important and should be preserved, pin it:

```bash
/mem0-pin migration rules
```

Pinned memories are protected from dream pruning.

## Why this matters

The best coding-agent workflows are not only about larger context windows. They are about carrying forward the right context.

Pi can already help inside your repo. With Mem0, it can also remember the parts of your workflow that should survive beyond one session:

- how a project is structured
- which conventions the repo follows
- what decisions were already made
- what the user prefers
- what mistakes should not be repeated
- what technical context matters across sessions

That makes every new session less like starting over and more like continuing the same working relationship.

## Get started

To use the plugin, create a Mem0 account, get your API key, install the package, and export the key in your shell:

```bash
pi install npm:@mem0/pi-agent-plugin
export MEM0_API_KEY="m0-your-key-here"
```

Then start using memory directly in Pi:

```bash
/mem0-remember "Use TypeScript for new files in this repo"
/mem0-search language preferences
/mem0-status
```

Package: `@mem0/pi-agent-plugin`

GET TLDR from:
