Skip to main content

A Python MCP stdio instance for adding memory to AI coding agents

Project description

OpenCode Memory

Give your AI coding agent persistent memory and conversation archiving.

What It Does

OpenCode Memory provides two capabilities to AI coding agents like opencode:

  1. Memory - Store and retrieve facts, preferences, and context across sessions
  2. Conversation Archiving - Save full conversations as readable markdown files

Your AI agent remembers who you are, what you're working on, and can browse past discussions.

Why It Matters

Without memory:

  • You repeat your preferences every session
  • Project context is lost between conversations
  • Important decisions get forgotten
  • Past discussions are inaccessible

OpenCode Memory solves this by providing persistent storage your AI agent can access in every conversation.

Installation

uv tool install opencode-memory

Or run directly without installing:

uvx opencode-memory --stdio

Configure for OpenCode

Add to your MCP configuration file (typically ~/.config/opencode/config.json):

{
  "mcpServers": {
    "memory": {
      "command": "uvx",
      "args": ["opencode-memory", "--stdio"],
      "env": {
        "OPENAI_API_KEY": "sk-your-api-key",
        "OPENCODE_MEM_FAISS_DIRECTORY": "$HOME/.opencode/memory/faiss"
      }
    }
  }
}

Environment Variables

Variable Required Description
OPENAI_API_KEY Yes For embedding generation
OPENCODE_MEM_FAISS_DIRECTORY Yes Where vector index is stored
OPENCODE_MEM_EMBEDDING_MODEL No Default: text-embedding-3-large

Usage Recommendation: Dedicated Chat Agent

Recommended approach: Create a dedicated opencode agent that acts as a ChatGPT-like interface.

Why a Dedicated Agent?

When you use opencode primarily for conversation rather than code editing:

  1. All conversations are archived - Every discussion saved as markdown
  2. Memories accumulate - Preferences, context, and knowledge build over time
  3. Historical search - Browse and search past conversations by topic
  4. Session continuity - Pick up where you left off in previous sessions

How to Create a Dedicated Agent

Create the agent file at ~/.config/opencode/agent/Chat.md:

# Chat Agent

A conversational agent with memory and conversation archiving capabilities.

## Behavior

You are a helpful conversational assistant, similar to ChatGPT. Your role is to engage in natural conversation while maintaining persistent memory and archiving all interactions.

## Memory

You have access to memory tools. Use them to:
- Store user preferences (coding style, tools, workflows)
- Remember important information the user shares
- Track ongoing topics and interests
- Save useful context for future sessions

Before responding, search your memory for relevant context. Store meaningful facts after conversations.

## Conversation Archiving

**CRITICAL: Archive every interaction using opencode's native file tools.**

After each user request followed by your response (one interaction):

1. Use the `write` or `edit` tool to append the interaction to a markdown file named `YYYY-MM-DD.md` in a directory of your choice (e.g., `~/.opencode/memory/history/2026-02-20.md`)

2. The file must start with a keywords header:

```markdown
keywords: python, async, asyncio, error-handling
---

## User
[timestamp] Your question here...

## Assistant
[timestamp] Your response here...
  1. Keywords act as hashtags for finding conversations. They should:

    • Be broad enough to categorize the topic
    • Include technologies, concepts, or themes discussed
    • Be updated after each interaction if new topics emerge
  2. Append new interactions to today's file using the edit tool. Update the keywords line if the conversation covers new topics.

Example

After discussing Python async functions:

keywords: python, async, asyncio, error-handling, concurrency

## User
[2026-02-20 14:30] How do I handle exceptions in asyncio.gather?

## Assistant
[2026-02-20 14:30] You can use return_exceptions=True parameter...

## User
[2026-02-20 14:35] What about timeout handling?

## Assistant
[2026-02-20 14:35] For timeouts, use asyncio.wait_for()...

Workflow

For each message:

  1. Search memory for relevant context
  2. Respond naturally to the user
  3. Use write or edit tools to archive the interaction to today's markdown file
  4. Update keywords if new topics emerged
  5. Store any important facts as memories

### Using the Agent

```bash
mkdir -p ~/chat
cd ~/chat
opencode --agent Chat

The agent will automatically:

  • Archive every interaction to daily markdown files
  • Build a searchable conversation history
  • Remember your preferences and context
  • Update keywords as topics evolve

What You Get

With a dedicated memory-enabled agent:

  • Preferences remembered - "I use dark theme" is stored and recalled
  • Project context - "Working on FastAPI backend" persists across sessions
  • Conversation history - Browse ~/.opencode/memory/history/ for past discussions
  • Topic search - Use opencode's grep to find conversations about specific topics

How Memory Works

Two Storage Layers

  1. Memory Layer - Semantic storage for facts and knowledge

    • Vector-based similarity search
    • Filter by categories and metadata
    • Automatic expiration for time-sensitive info
  2. Conversation Layer - Markdown files for complete discussion history

    • Human-readable format
    • Searchable with standard tools (grep, opencode search)
    • Version control friendly

Available Tools

Your AI agent has access to MCP tools

Tool Purpose
add_memory Store a fact or preference
search_memory Find relevant memories by meaning
get_all_memories Retrieve all stored memories
update_memory Modify an existing memory
delete_memory Remove a memory

See API.md for detailed tool documentation.

Example Usage Patterns

Remembering Preferences

You: "I always use 2-space indentation for Python"

AI: [Stores: "User prefers 2-space indentation for Python" 
     Categories: preferences, python]

Future sessions recall this automatically.

Tracking Current Work

AI: [Stores: "Currently implementing OAuth2 authentication"
     Categories: current-focus
     Expires: end of sprint]

Archiving Discussions

Use opencode's write or edit tools to save conversations:

AI: [Uses write tool to create: 2026-02-20.md]
     Content: keywords, timestamps, and full conversation

Later, opencode can grep through archived conversations:

# Find conversations about database design
opencode grep "database" ~/.opencode/memory/history/

Documentation

  • API.md - Complete MCP tool reference with examples
  • DESIGN.md - Architecture decisions and rationale

Requirements

  • Python 3.10+
  • OpenAI API key (for embeddings)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencode_memory-0.2.tar.gz (133.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opencode_memory-0.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file opencode_memory-0.2.tar.gz.

File metadata

  • Download URL: opencode_memory-0.2.tar.gz
  • Upload date:
  • Size: 133.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for opencode_memory-0.2.tar.gz
Algorithm Hash digest
SHA256 b7b0c372c582c62571c5ea9bb5e6efc84b77fd2110d66e20d562653679be9b27
MD5 237d52c2e0c50215751cc03eb297f9f8
BLAKE2b-256 47762ac050c45863e8aab06e1b04b46a0b5f621159da4505fa7e52057853facf

See more details on using hashes here.

Provenance

The following attestation bundles were made for opencode_memory-0.2.tar.gz:

Publisher: release.yml on Mickael-Roger/opencode-memory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opencode_memory-0.2-py3-none-any.whl.

File metadata

  • Download URL: opencode_memory-0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for opencode_memory-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e24f33ce57a6af8f7abd814eb2dc6bbdfe1790925da65e2ea0ab4bdb9c5d1f02
MD5 4034b1919243e0e7fc27d64a294da659
BLAKE2b-256 d9c21cdd9115faff30f0e5255792e56dd76d58dc912a50d20187490229a744e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for opencode_memory-0.2-py3-none-any.whl:

Publisher: release.yml on Mickael-Roger/opencode-memory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page