Magic Context plugin

A long-term memory plugin for OpenCode and Pi: a background historian compresses chat history, a nightly agent curates memory.

  • 2,510 ★ on the repository
  • Last commit
  • MIT
Plugin

Extended access

Why this level

  • The plugin stores conversation history and project memory on disk, and background models receive parts of the conversation.
All reasons and checks

cortexkit/magic-context

Install

Works in

Manual install

npx @cortexkit/magic-context@latest setup

The first Quick start command in the README: the wizard detects OpenCode, Pi or OMP and registers the plugin.

Access and checks

How we review

Extended accessThe tool runs code or makes network calls and only reads external data.

  • The plugin stores conversation history and project memory on disk, and background models receive parts of the conversation.

This is third-party code. Review the repository files before installing.

What it does

Magic Context takes over context management for a coding agent. A background historian compresses old conversation into chronological summaries with importance scores, while decisions, constraints and conventions move into project memory. Overnight, dreamer agents verify entries against the codebase and remove duplicates and stale items. During work the agent searches memories, past conversations and git history with `ctx_search`. The host's built-in compaction is switched off, so there are no compaction pauses. State lives in a local SQLite database.

Who it is for. Developers on OpenCode, Pi or OMP who keep one project going for weeks and are tired of re-explaining it in every new session.

Good fit when

  • A long session keeps hitting context compaction and losing detail.
  • A decision from a month ago must resurface without manual notes.
  • OpenCode and Pi share one memory inside the same repository.
  • The historian runs on a cheap or local model while the main agent stays strong.

Not a fit when

  • You work in Claude Code or Cursor: the plugin targets OpenCode, Pi and OMP.
  • Conversation history cannot be stored on disk, even locally.
  • The task is one-off and memory between sessions adds nothing.

Example request

Use ctx_search to find why we chose this caching scheme and recall the constraints recorded back then.

Limitations

History compaction requires a historian model in `magic-context.jsonc`; without it compression does not run. The host's built-in compaction has to be disabled or it interferes. Local embeddings download a model of about 90 MB on first use, and `embedding.provider` can turn that off. The database holding memory and history must persist across restarts, so mount it on a persistent volume in throwaway containers. Historian and dreamer calls spend tokens on the chosen models.

How to disable. Remove the plugin from `opencode.jsonc` or Pi settings and restore the host's built-in compaction. The database in `~/.local/share/cortexkit/magic-context/` stays on disk, delete it separately.

FAQ

Which hosts are supported?

OpenCode, Pi (version 0.74.0 or newer) and OMP. The setup wizard detects which of them are installed.

Where is memory stored?

In the local SQLite database `~/.local/share/cortexkit/magic-context/context.db`. Memory is keyed to a stable project identity, so it follows the project across clones and worktrees.

How do I trigger the nightly cleanup by hand?

Run `/ctx-dream`. The dreamer verifies memory against the code, removes duplicates and promotes what recurs.

Can I avoid downloading the embedding model?

Yes. Set `embedding.provider: "off"` or point to a remote `openai_compatible` or `ollama` backend. Keyword search and context management keep working.

What tools does the agent get?

The main one is `ctx_search`: one query across project memory, past conversations, git commits, notes and primers. Commands such as `/ctx-dream` and `/ctx-embed` are run by the user.

Discussion

No questions or reviews yet.

Plugins

An OpenCode plugin that keeps project decisions and agreements across context compactions and sessions with no extra model calls.

PluginExtended access199Repository stars

Coding memory across sessions, machines and teammates: decisions and dead ends flow into later prompts on their own.

PluginExtended access82Repository stars

A long-term memory plugin and server for Claude Code and Codex: decisions and handoffs move between sessions and agents

PluginBroad access1.6KRepository stars

A plugin with memory of past chats: it searches by meaning for decisions and reasons across Claude Code, Codex, Cursor and opencode sessions over MCP

PluginExtended access499Repository stars

Memory for the Pi agent: facts and lessons persist, past chats are searched via SQLite and API keys never reach memory.

PluginExtended access529Repository stars

README in short

The README covers three phases: capture, nightly consolidation and recall on demand. It details historian and dreamer models, embedding setup, commands and data storage.

README badge

Report a problem