Skip to content

Feature Request: Model-Agnostic Memory Layer (Global & Per-Project) #8043

Closed as not planned

Description

@jphpme

Problem
When using OpenCode across multiple LLM providers (Claude, Gemini, Kimi, OpenRouter, etc.), there's no persistent memory between sessions or across models. Each conversation starts fresh, losing valuable context about:

  • User preferences and coding style
  • Project-specific decisions and architecture
  • Previously solved problems and their solutions
  • Domain knowledge accumulated over time
    Proposed Solution
    Add a model-agnostic memory layer to OpenCode that works transparently regardless of which LLM provider is being used.
    Key Features
  1. Two memory scopes:
    • Global memory (~/.opencode/memory/) - Personal preferences, cross-project knowledge
    • Project memory (.opencode/memory/) - Codebase-specific context, architecture decisions
  2. Provider independence:
    • Use local embedding model (e.g., Qwen3-Embedding-0.6B) - no API dependency
    • Local vector storage (LanceDB, SQLite, or similar)
      • Optional: configurable "memory LLM" separate from main model (could be a cheap/fast model)
  3. Transparent operation:
    • Automatically extract relevant facts from conversations
    • Inject relevant context before each LLM call
    • Works the same whether using Claude, Gemini, Kimi, or any other provider
      Example Architecture
      User Query
      │
      ▼
      ┌──────────────────────┐
      │ Memory Retrieval │ ◄── Local embeddings + vector search
      │ (relevant context) │
      └──────────┬───────────┘
      │
      ▼
      ┌──────────────────────┐
      │ Context Injection │ ◄── Prepend relevant memories to prompt
      └──────────┬───────────┘
      │
      ▼
      ┌──────────────────────┐
      │ LLM Call (any) │ ◄── Claude, Gemini, Kimi, etc.
      └──────────┬───────────┘
      │
      ▼
      ┌──────────────────────┐
      │ Memory Extraction │ ◄── Extract facts from response (async)
      │ (background task) │
      └──────────────────────┘

Use Cases

  1. Preference persistence: "I prefer functional style" remembered across all projects and models
  2. Project context: Architecture decisions stay available even when switching models mid-project
  3. Cross-session continuity: Resume work without re-explaining context
  4. Knowledge accumulation: Build up domain expertise over time

Configuration (example)

# opencode.toml
[memory]
enabled = true
global_enabled = true
project_enabled = true
# Optional: dedicated model for memory operations (cheap/fast)
extraction_model = "openai/gpt-4.1-mini"
# Local embedding model (no API needed)
embedding_model = "Qwen/Qwen3-Embedding-0.6B"
Prior Art / Inspiration
- SimpleMem (https://github.com/aiming-lab/SimpleMem) - Efficient lifelong memory for LLM agents using semantic compression
- Mem0 (https://github.com/mem0ai/mem0) - Memory layer for AI applications
Additional Context
This would be especially valuable for users who:
- Switch between providers based on task (coding vs reasoning vs speed)
- Work on multiple projects with different contexts
- Want continuity without provider lock-in

Activity

  1. paperplane123 commented on Jan 15, 2026

    @paperplane123

    I need it very very much

  2. ilyazub commented on Feb 17, 2026

    @ilyazub

    Have someone tested topoteretes/cognee with OpenCode across multiple sessions on multiple projects?

  3. 1cmasson commented on Mar 26, 2026

    @1cmasson

    Github Copilot CLI actually has a pretty good example of this. They manage their session state locally. I personally like to use an agent to jot up a really good plan and then give that same plan to the next agent to work on it with fresh context.

  4. github-actions commented on May 26, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions