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:
- Memory - Store and retrieve facts, preferences, and context across sessions
- 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:
- All conversations are archived - Every discussion saved as markdown
- Memories accumulate - Preferences, context, and knowledge build over time
- Historical search - Browse and search past conversations by topic
- 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...
-
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
-
Append new interactions to today's file using the
edittool. 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:
- Search memory for relevant context
- Respond naturally to the user
- Use
writeoredittools to archive the interaction to today's markdown file - Update keywords if new topics emerged
- 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
-
Memory Layer - Semantic storage for facts and knowledge
- Vector-based similarity search
- Filter by categories and metadata
- Automatic expiration for time-sensitive info
-
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7b0c372c582c62571c5ea9bb5e6efc84b77fd2110d66e20d562653679be9b27
|
|
| MD5 |
237d52c2e0c50215751cc03eb297f9f8
|
|
| BLAKE2b-256 |
47762ac050c45863e8aab06e1b04b46a0b5f621159da4505fa7e52057853facf
|
Provenance
The following attestation bundles were made for opencode_memory-0.2.tar.gz:
Publisher:
release.yml on Mickael-Roger/opencode-memory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opencode_memory-0.2.tar.gz -
Subject digest:
b7b0c372c582c62571c5ea9bb5e6efc84b77fd2110d66e20d562653679be9b27 - Sigstore transparency entry: 975132416
- Sigstore integration time:
-
Permalink:
Mickael-Roger/opencode-memory@d679c0b0a0e28341ce0544992814584ef4ff3cb6 -
Branch / Tag:
refs/tags/v0.2 - Owner: https://github.com/Mickael-Roger
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d679c0b0a0e28341ce0544992814584ef4ff3cb6 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e24f33ce57a6af8f7abd814eb2dc6bbdfe1790925da65e2ea0ab4bdb9c5d1f02
|
|
| MD5 |
4034b1919243e0e7fc27d64a294da659
|
|
| BLAKE2b-256 |
d9c21cdd9115faff30f0e5255792e56dd76d58dc912a50d20187490229a744e2
|
Provenance
The following attestation bundles were made for opencode_memory-0.2-py3-none-any.whl:
Publisher:
release.yml on Mickael-Roger/opencode-memory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opencode_memory-0.2-py3-none-any.whl -
Subject digest:
e24f33ce57a6af8f7abd814eb2dc6bbdfe1790925da65e2ea0ab4bdb9c5d1f02 - Sigstore transparency entry: 975132418
- Sigstore integration time:
-
Permalink:
Mickael-Roger/opencode-memory@d679c0b0a0e28341ce0544992814584ef4ff3cb6 -
Branch / Tag:
refs/tags/v0.2 - Owner: https://github.com/Mickael-Roger
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d679c0b0a0e28341ce0544992814584ef4ff3cb6 -
Trigger Event:
push
-
Statement type: