# Repository Briefing: cortexkit/magic-context
> Source: https://repoforai.com/repo/cortexkit/magic-context (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/cortexkit/magic-context
- **Official Docs / Website**: https://discord.gg/DSa65w8wuf
- **Category**: Coding, Skills & MCP (AI 编程 / Skills / MCP)
- **Primary Language**: TypeScript
- **License**: MIT
- **Engineering Health**: A+ (90/100 · Maintenance 35/35 · Adoption 15/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v0.49.104 (2026-12-03) — https://github.com/cortexkit/magic-context/releases
- **Review Snapshot**: 2026-12-02 (Note: v0.49.104 on 2026-12-03 shipped after this review; verify latest release notes)
- **Deployment / Stack Signals**: CLI
- **Momentum**: 2,588 ★ total (+6 24h / +24 7d) · 153 forks
- **Topics**: `agent-framework`, `agent-memory`, `ai`, `ai-agents`, `ai-context`, `ai-memory`, `cache-aware`, `context-engineering`, `context-management`, `langchain`, `memory`, `opencode`
- **When to Use**: Best for: Teams running long-lived OpenCode, Pi, or Oh My Pi sessions that want to preserve prompt-cache reuse and recover past decisions without reloading entire transcripts. Skip if: Work is mostly short and independent, the host's native compaction is sufficient, or project policy prohibits persistent transcripts or background model calls.

## Overview
```text
### Architecture & Core Mechanics
Magic Context is a host-integrated extension, not a standalone MCP service. OpenCode 1.x and 2.x adapt their different plugin APIs to the same TypeScript core in `packages/plugin`; `packages/pi-plugin` imports that core for Pi and Oh My Pi. The Rust `ck-mc` module runs the context transform and historian inside the `subc` daemon for sessions hosted in a runner rather than a plugin host. The source workspace declares Bun >=1.4.0 and includes a Cargo workspace.

The historian converts older conversation into chronological, importance-scored summaries and extracts durable facts into project memory in the same pass. The prompt transform renders older summaries at progressively lower detail using deterministic rules. Reductions requested through `ctx_reduce` are queued and applied at cache-safe points rather than immediately rewriting the prompt prefix. OpenCode and Pi share a database for memories and embeddings.

### Key Capabilities & Differentiators
Active project memories and compacted history are injected each turn. `ctx_search` queries project memory, raw conversations, indexed Git commits, notes, and primers with semantic retrieval and a full-text fallback; `ctx_expand` restores exact transcript text when a summary is insufficient. `ctx_memory` explicitly writes or deletes categorized facts. Embeddings default to local `Xenova/all-MiniLM-L6-v2`; disabling them leaves keyword retrieval and context management in place.

The optional dreamer runs maintenance in ephemeral child sessions: it can map memories to source files, verify and deduplicate them, refresh primers, and update `ARCHITECTURE.md` and `STRUCTURE.md`. `/ctx-dream` triggers a run on demand. Historian and dreamer model settings are host-specific. If Oh My Pi has no setting block for either component, it uses that component's Pi block; an explicit OMP block takes precedence even if it omits a model.

### Trade-offs & Limitations
Compared with built-in compaction, Magic Context gives teams more control over when the prompt changes and what remains retrievable across turns and sessions. In return, it takes over a host responsibility: leaving native compaction enabled can cause double compression and interfere with deferred reductions. The model window is still finite, summaries can omit details, and the value of preserving the prefix depends on the provider's cache behavior. Validate cache reuse and recovery from raw history on representative sessions before switching a team over.

A smaller historian can keep auxiliary inference separate from the primary coding model, but local inference competes for workstation resources while hosted inference adds cost and may send project text outside the machine. The optional dreamer adds ongoing maintenance work and can update project documentation, so decide whether that belongs in your workflow before enabling it. MIT permits commercial use, but it does not resolve provider data-handling terms or determine who should have access to persisted history.

### Hardware & Deployment Guide
Run `npx @cortexkit/magic-context@latest setup` to detect and configure installed hosts, or target one via `--harness opencode`, `--harness pi`, or `--harness omp`. Pi requires >=0.74.0 and Oh My Pi >=17.1.7. Restart the host after setup. For manual OpenCode setup, register `@cortexkit/opencode-magic-context`, disable both `compaction.auto` and `compaction.prune`, and set `historian.opencode.model` in `magic-context.jsonc`. Project config at `.cortexkit/magic-context.jsonc` overlays user config under `~/.config/cortexkit/` unless the user config location has been redirected.

Historian and dreamer models can run locally or use hosted inference; actual resources depend on model choice and concurrent background work. Docker appears in the test scripts, not as a requirement for normal host installation. v0.49.95 extended search and expansion to messages removed from the live prompt. v0.49.96 fixed OpenCode 2 behavior after `/compact` and in the session list, improved long-message ranking, and added a `doctor` warning for a known host SQLite fault.
```

## Key Capabilities
```text
- Host adapters: OpenCode 1.x and 2.x use different plugin APIs over one core; Pi and Oh My Pi reuse that core.
- Prompt-cache preservation: `ctx_reduce` queues removals for cache-safe points; deterministic decay controls how much detail older summaries contribute.
- Shared project memory: OpenCode and Pi pool memories and embeddings in the same database, and `ctx_memory` provides explicit writes and deletes.
- Retrieval: `ctx_search` spans memories, conversations, indexed Git commits, notes, and primers; `ctx_expand` recovers original transcript text.
- Model routing: Historian and dreamer settings are per host, and Oh My Pi falls back to Pi settings only when its own block is absent.
- Release v0.49.96: Long messages are ranked by the matching passage, and `doctor` flags a known SQLite fault in a host runtime.
```

## Quick Start / Clone
```bash
npx @cortexkit/magic-context@latest setup
```
