Use MemPalace as a local memory layer for OpenCode.
This template lets OpenCode search prior project context, chat exports, and earlier decisions through MemPalace's MCP server.
Community template. Not affiliated with the OpenCode team.
This template exists to help OpenCode users work with the upstream MemPalace project.
MemPalace itself is the work of its upstream author, listed in the project metadata as milla-jovovich, along with the broader MemPalace contributor community. If you are evaluating the memory system, benchmarking claims, implementation details, or filing upstream bugs and feature requests, use the original repository:
- Upstream repo:
https://github.com/MemPalace/mempalace - Upstream project page:
https://github.com/MemPalace/mempalace - Upstream author reference from package metadata:
milla-jovovich
This repo is only an OpenCode-oriented integration template and documentation layer around that upstream work.
README.md: setup and usage guideopencode.json: OpenCode MCP config for the MemPalace serverlaunch-mempalace.sh: validatesMEMPALACE_PYTHONand starts the MCP server.opencode/plugins/mempalace-autosave.js: incrementally builds full session transcripts and syncs them into MemPalacemempalace-autosave-sync.py: upserts stable per-session autosave drawers into MemPalacemempalace-autosave-mine.sh: manually re-sync the autosave spool if neededAGENTS.md: project instructions for when to use memory.env.example: environment variable templatesetup.sh: installs MemPalace, detects OS, and writes.env.local
- Mine project files into MemPalace
- Mine chat exports into MemPalace
- Expose MemPalace to OpenCode as a local MCP server
- Auto-save full OpenCode idle-session transcripts into a local spool and sync them into MemPalace
- Tell OpenCode to consult memory before making historical or architectural assumptions
OpenCode now exposes a plugin system with event hooks. This template uses a local plugin under .opencode/plugins/ to cache message events, flush the full session transcript on session.idle, and then sync that transcript into MemPalace with stable drawer IDs.
This is a practical local-first transcript exporter. It rewrites one transcript file per session and upserts only changed MemPalace drawers so repeat autosaves update the same conversation instead of accumulating duplicate snapshots.
Autosave files are written with restrictive permissions when the filesystem supports them, and .mempalace-autosave/ is ignored by git.
project files / chat exports / autosave spool
|
v
mempalace mine
|
v
local MemPalace index
|
v
launch-mempalace.sh
|
v
mempalace.mcp_server
|
v
OpenCode
|
v
plugin saves idle sessions to spool
Fastest path:
./setup.sh
. ./.env.localManual path:
python3 -m venv ~/.venvs/mempalace
~/.venvs/mempalace/bin/pip install --upgrade pip
~/.venvs/mempalace/bin/pip install mempalaceThe launcher script (launch-mempalace.sh) reads the MEMPALACE_PYTHON environment variable to find the Python that has MemPalace installed. If the variable is missing or points to a bad path, the launcher prints a clear error and exits.
setup.sh writes a .env.local file with the correct value, but that file only takes effect when you source it manually. To make the variable available every time you open a terminal, add it to your shell profile.
For Bash (~/.bashrc):
echo 'export MEMPALACE_PYTHON="$HOME/.venvs/mempalace/bin/python"' >> ~/.bashrc
source ~/.bashrcFor Zsh (~/.zshrc):
echo 'export MEMPALACE_PYTHON="$HOME/.venvs/mempalace/bin/python"' >> ~/.zshrc
source ~/.zshrcFor Fish (~/.config/fish/config.fish):
set -Ux MEMPALACE_PYTHON "$HOME/.venvs/mempalace/bin/python"If setup.sh detected a different path (for example on Windows), check .env.local for the actual value and use that instead.
You can verify the variable is set correctly by opening a new terminal and running:
echo $MEMPALACE_PYTHONIt should print the full path to the Python executable inside the MemPalace venv.
OpenCode loads config from multiple locations and merges them together. You have two choices for where to put the MemPalace MCP config:
| Location | Scope | Best for |
|---|---|---|
~/.config/opencode/opencode.json |
Every project you open | Most users. MemPalace memory is useful everywhere. |
<project>/opencode.json |
Only that one project | If you only want memory in specific repos. |
Recommended for beginners: use global config. This way MemPalace is available no matter which project you open in OpenCode.
Copy launch-mempalace.sh somewhere permanent and add the MCP block to your global config:
# Copy the launcher to a permanent location
cp launch-mempalace.sh ~/.config/opencode/launch-mempalace.sh
chmod +x ~/.config/opencode/launch-mempalace.shThen add the MCP block to ~/.config/opencode/opencode.json (create the file if it doesn't exist):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"mempalace": {
"type": "local",
"enabled": true,
"command": [
"/home/your-user/.config/opencode/launch-mempalace.sh"
]
}
}
}Replace /home/your-user with your actual home directory. The path must be absolute when used in global config.
You can also copy AGENTS.md into your global config directory so the memory instructions apply everywhere:
cp AGENTS.md ~/.config/opencode/agents/mempalace.mdIf you only want MemPalace in one project, copy opencode.json, launch-mempalace.sh, and AGENTS.md into that project's root. The relative path (./launch-mempalace.sh) works when the config is in the project directory.
OpenCode merges configs, so you only need to add the mcp block to your existing file. You do not need to replace the whole file.
~/.venvs/mempalace/bin/mempalace init ~/projects/myapp
~/.venvs/mempalace/bin/mempalace mine ~/projects/myapp
~/.venvs/mempalace/bin/mempalace mine ~/chat-exports --mode convosIf your transcript exports contain many sessions in one file:
~/.venvs/mempalace/bin/mempalace split ~/chat-exports --dry-run
~/.venvs/mempalace/bin/mempalace split ~/chat-exportsopencodeIf the project has not been initialized for OpenCode yet, run:
/init
Examples:
Use MemPalace to find previous decisions about auth before changing the login flow.
Search memory for earlier discussions about retries and background jobs, then use that context in your plan.
What did we previously decide about Postgres indexes in this codebase? Use MemPalace if needed.
The included OpenCode plugin listens for session.idle events.
When a session becomes idle it:
- uses the incremental in-memory session cache, hydrating from OpenCode once after plugin startup if needed
- rewrites the full transcript at
.mempalace-autosave/sessions/<session-id>.txt - syncs only changed transcript chunks into MemPalace with stable per-session drawer IDs
- skips duplicate syncs when the transcript content has not changed
- omits raw tool output from the persisted transcript
If you want the autosave spool somewhere else, set:
export MEMPALACE_AUTOSAVE_DIR="$HOME/.local/share/opencode-mempalace"You can also re-sync the spool manually:
./mempalace-autosave-mine.shOr with an explicit path:
./mempalace-autosave-mine.sh /path/to/autosave-dirRegisters MemPalace as a local MCP server for OpenCode. This file can be placed either in ~/.config/opencode/ for global use or in a project root for per-project use. See step 3 for details.
It calls launch-mempalace.sh, which validates MEMPALACE_PYTHON and starts the server. It also loads AGENTS.md as a project instruction file.
Project-local OpenCode plugin. Hooks into session.idle, exports the full session transcript to .mempalace-autosave/sessions/<session-id>.txt, and invokes the sync script.
Reads autosave transcript files, chunks them like MemPalace conversation imports, and upserts stable drawers keyed by transcript path plus chunk index. Unchanged chunks are skipped and stale chunk IDs are deleted so later autosaves update the same session instead of creating duplicate history.
Helper script for manually re-syncing the autosave spool. Uses MEMPALACE_AUTOSAVE_DIR if set, otherwise defaults to .mempalace-autosave.
Validates that MEMPALACE_PYTHON is set and points to an executable Python, then starts mempalace.mcp_server. Provides clear error messages if the variable is missing or the path is wrong.
Tells OpenCode when it should consult memory first, especially for:
- earlier design decisions
- debugging history
- migrations
- project-specific conventions
- previous AI or team discussions
Shows the one environment variable the template expects:
MEMPALACE_PYTHON
This script:
- creates
~/.venvs/mempalaceby default - installs or upgrades
mempalace - detects the correct venv binary path (
bin/pythonon Unix,Scripts/python.exeon Windows) - writes
.env.localwith the resolved path - exports
MEMPALACE_PYTHONfor the script's shell
Optional overrides:
MEMPALACE_VENV_DIR="$HOME/.venvs/custom-mempalace" ./setup.sh
PYTHON_BIN=python3.11 ./setup.sh
ENV_FILE=.env.local ./setup.shRe-run mining whenever the underlying source material changes.
~/.venvs/mempalace/bin/mempalace mine ~/projects/myapp
~/.venvs/mempalace/bin/mempalace mine ~/chat-exports --mode convos~/.venvs/mempalace/bin/mempalace status
~/.venvs/mempalace/bin/mempalace search "why did we switch auth providers"This repo includes a minimal regression harness for the autosave integration.
./run-tests.shEquivalent individual commands:
node tests/test-mempalace-autosave-plugin.mjs
python3 -m unittest tests/test_mempalace_autosave_sync.pyIf OpenCode is not using MemPalace:
- Confirm
MEMPALACE_PYTHONpoints to the Python wheremempalaceis installed. - Run the launcher directly to check for errors:
./launch-mempalace.sh- Restart OpenCode after changing
opencode.jsonor environment variables. - Strengthen the guidance in
AGENTS.mdif the agent still guesses instead of searching. - If you used
./setup.sh, make sure you also loaded.env.localin the shell where you launch OpenCode.
If retrieval quality is weak:
- Re-run
mempalace mineon the relevant repo or export directory. - Use better search terms: feature names, migration names, people, project names, or exact terms from prior discussions.
- Split oversized transcript exports before mining.
- MemPalace's storage and retrieval are local-first.
- The benchmark headline in the upstream repo is based on raw mode, not AAAK compression mode.
- This template is intentionally minimal and OpenCode-specific.
- Credit for MemPalace belongs to the upstream project and its author/contributors, not to this template repo.
Before publishing this template, update:
- repository name and description
- any custom example paths in the README
- your preferred default
AGENTS.mdwording
- Core memory system: MemPalace
- Upstream repository:
MemPalace/mempalace - Upstream author reference in package metadata:
milla-jovovich - This repo: OpenCode integration template and docs only