You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenCode plugin that gives coding agents persistent memory using a local vector database (SQLite + usearch). No cloud services required — all data stays on your machine.
Installation
npm install opencode-mem0
Requires Bun >= 1.0.0 (Linux/macOS) for native bun:sqlite, or Node.js >= 20.0.0 (any platform including Windows) via better-sqlite3 fallback.
Quick Start
Install the plugin in your OpenCode project:
npm install opencode-mem0
Enable the plugin in your opencode.json config:
{
"plugin": ["opencode-mem0"]
}
Configure a memory provider for auto-capture (e.g., a cheap OpenAI-compatible endpoint):
Start OpenCode — the plugin warms up automatically, the Web UI launches at http://127.0.0.1:4747, and memories are captured from your sessions.
Recommended: Use a cheap model (e.g., gpt-4o-mini) for memory extraction — it's cost-effective and avoids taxing your main chat model. memoryProvider supports openai-chat (any OpenAI-compatible API), openai-responses, anthropic, and google-gemini. Alternatively, opencodeProvider + opencodeModel reuses your OpenCode-connected provider (uses your main model). Without a provider, auto-capture silently skips with a log warning.
Usage
Memories are captured automatically from conversations via auto-capture (enabled by default). The agent tool below is for explicit memory operations — most users never need to invoke it manually.
Agent Tool — Memory Commands
The plugin exposes a memory tool to the OpenCode agent with six modes:
Agent: memory mode=add content="API base URL is https://api.example.com/v2" tags="api,config"
→ {"success":true,"message":"Memory added","id":"def456","tags":["api","config"]}
Programmatic API
importpluginModulefrom"opencode-mem0/server";// pluginModule = { id: "opencode-mem0", server: OpenCodeMemPlugin }// OpenCode loads this automatically when the plugin is enabled in opencode.json
Key Features
7-Factor Memory Scoring — recency, frequency, importance, utility, novelty, confidence, and interference combine into a single strength score that drives lifecycle decisions.
STM/LTM Dual-Store Lifecycle — short-term memories decay via Ebbinghaus curves; high-strength memories auto-promote to long-term store; low-strength memories archive after inactivity.
Intelligent Conflict Resolution — detects contradictions between memories (e.g., "auth uses cookies" vs. "auth uses JWT") using LLM + heuristic analysis and resolves them.
Override which model to use from the connected provider
Web UI
Setting
Default
Description
webServerEnabled
true
Enable the memory explorer Web UI
webServerPort
4747
Web UI port
webServerHost
127.0.0.1
Web UI bind address
webServerApiKey
—
API key required for Web UI access
Auto-Capture
Setting
Default
Description
autoCaptureEnabled
true
Auto-extract memories from idle sessions
autoCaptureMaxIterations
5
Max capture iterations per idle session
autoCaptureIterationTimeout
30000
Timeout (ms) per capture iteration
autoCaptureLanguage
—
Language hint for auto-capture (e.g., en, de, zh)
Memory Scoring
Setting
Default
Description
memoryScoring.enabled
true
Enable 7-factor scoring recalculation
memoryScoring.recalculationIntervalMinutes
60
How often (min) to recalculate memory scores
memoryScoring.recencyHalfLifeDays
7
Half-life for recency factor decay
memoryScoring.utilityHalfLifeDays
3
Half-life for utility factor decay
Memory Lifecycle
Setting
Default
Description
memoryLifecycle.stmDecayDays
7
Short-term memory decay period
memoryLifecycle.ltmDecayDays
90
Long-term memory decay period
memoryLifecycle.promotionThreshold
0.7
Strength score threshold for STM → LTM promotion (0–1)
memoryLifecycle.archiveThreshold
0.2
Strength score threshold for archiving (0–1)
memoryLifecycle.archiveAfterDays
30
Days of inactivity before archival
memoryLifecycle.checkIntervalMinutes
60
How often (min) to run lifecycle maintenance
Chat Message Injection
Setting
Default
Description
chatMessage.enabled
true
Inject relevant memories into chat messages
chatMessage.maxMemories
3
Max memories injected per chat message
chatMessage.excludeCurrentSession
true
Exclude memories from the current session
chatMessage.maxAgeDays
—
Only inject memories newer than this many days
chatMessage.injectOn
first
When to inject: first (first user message) or always
chatMessage.mode
relevant
Injection mode: relevant (search-based) or fast (list-based)
Retrieval & Injection
Setting
Default
Description
retrieval.maxResults
20
Max search results from retrieval
retrieval.diversityThreshold
0.9
Diversity filter threshold (0–1)
retrieval.contextBoost
1.5
Context similarity boost multiplier
injection.tokenBudget
4000
Max tokens for injected memory context
injection.format
plain
Output format: plain, xml, or yaml
injection.queryAwareFiltering
true
Filter memories by relevance to the current query
injection.relevanceThreshold
0.3
Minimum relevance score for injected memories (0–1)
Contextual Decay
Setting
Default
Description
contextualDecay.enabled
true
Enable context-aware memory decay
contextualDecay.baseDecayRate
0.05
Base decay rate per cycle (0–1)
contextualDecay.strengthBoostFactor
0.5
Strength boost factor (0–1)
contextualDecay.accessBoostFactor
0.3
Access boost factor (0–1)
contextualDecay.minDecayRate
0.005
Minimum decay rate (0–1)
contextualDecay.maxDecayRate
0.15
Maximum decay rate (0–1)
Compaction Recovery
Setting
Default
Description
compaction.enabled
true
Re-inject memories after session compaction
compaction.memoryLimit
10
Max memories to re-inject per compaction event
Transcript Storage
Setting
Default
Description
transcriptStorage.enabled
true
Store session transcripts for search
transcriptStorage.maxAgeDays
30
Maximum age (days) before transcripts are pruned
Deduplication
Setting
Default
Description
deduplicationEnabled
true
Enable deduplication of similar memories
deduplicationSimilarityThreshold
0.9
Similarity threshold for merge (0–1)
deduplicationIngestEnabled
true
Run deduplication at ingest time
Auto-Cleanup
Setting
Default
Description
autoCleanupEnabled
true
Automatically clean up stale data
autoCleanupRetentionDays
30
Days to retain before cleanup
User Profiles
Setting
Default
Description
injectProfile
true
Inject user profile into agent context
maxProfileItems
5
Max profile items injected
userProfileAnalysisInterval
10
Sessions between profile re-analysis
userProfileMaxPreferences
20
Max stored user preferences
userProfileMaxPatterns
15
Max stored behavioral patterns
userProfileMaxWorkflows
10
Max stored workflow descriptions
userProfileConfidenceDecayDays
30
Days before profile confidence decays
userProfileChangelogRetentionCount
5
Max profile changelog entries retained
userEmailOverride
—
Override user email for profile identity
userNameOverride
—
Override user name for profile identity
AI Session & Toasts
Setting
Default
Description
aiSessionRetentionDays
7
Days to retain AI provider sessions
showAutoCaptureToasts
true
Show toast when auto-capture runs
showUserProfileToasts
true
Show toast when profile is updated
showErrorToasts
true
Show toast on memory system errors
OpenCode-Mem0 is a cognitive enhancement fork of tickernelz/opencode-mem, featuring 7-factor memory scoring, STM/LTM dual-store lifecycle, intelligent conflict resolution, hybrid search, transcript storage, and more. Active development ongoing.