
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
@cortexkit/pi-magic-context
Advanced tools
Pi coding agent extension for Magic Context — cross-session memory and context management
Cross-session memory and context management for Pi coding agent. Shares the same SQLite database as the OpenCode plugin, so memories, embeddings, dreamer state, and project knowledge follow you across both harnesses.
⚠️ Beta release. The Pi extension is newer than the OpenCode plugin and is published as beta. Core flows (tagging, historian, memories, dreamer,
/ctx-aug) are validated end-to-end on interactivepisessions andpi --print --mode jsonsubagents. Please report issues — every Pi-side rough edge is fixable.
Requires @earendil-works/pi-coding-agent and @earendil-works/pi-tui >= 0.71.0.
Magic Context is a context engine that keeps long Pi sessions productive by:
| Feature | What it does |
|---|---|
| Tagging + drops | Tags every assistant/user/tool message with §N§ so you can drop specific turns later via ctx_reduce |
| Historian | Background subagent compresses old conversation into compartments + facts at threshold pressure or commit boundaries |
<session-history> injection | Prepends compressed history into the system prompt every turn so the agent never loses context |
| Project memories | Persistent cross-session knowledge store with embedding-based semantic search |
| Dreamer | Scheduled background subagent that consolidates, verifies, archives, and improves stored memories |
/ctx-aug | On-demand sidekick that augments the next turn with relevant memories |
| Auto-search hint | When user prompts mention previously-discussed topics, appends a compact memory hint |
| Note nudges | Surface deferred intentions at natural work boundaries (commit, todo completion, historian publication) |
| Cross-harness sharing | Memories written from OpenCode appear in Pi (and vice versa) for the same project |
The fastest path is the unified Magic Context CLI — --harness pi selects the Pi-specific setup pipeline (registers the extension with Pi, writes a sensible magic-context.jsonc, and verifies your model picks):
npx @cortexkit/magic-context@latest setup --harness pi
This handles everything for you:
npm:@cortexkit/pi-magic-context to Pi's packages array in ~/.pi/agent/settings.json (the same place pi install writes to)~/.pi/agent/magic-context.jsonc with defaultsthinking_level)If you'd rather register the Pi extension package directly with Pi (skipping the wizard), use Pi's own installer:
pi install npm:@cortexkit/pi-magic-context
This adds the extension to ~/.pi/agent/settings.json but won't write magic-context.jsonc for you — you'll need to create it manually (see Configuration below).
To check installation health later:
npx @cortexkit/magic-context@latest doctor --harness pi
Magic Context reads two config files (in this priority order):
$cwd/.pi/magic-context.jsonc (project-level overrides)~/.pi/agent/magic-context.jsonc (user-level defaults)Both are merged through a Zod schema. Invalid fields fall back to defaults — bad config never disables the plugin entirely.
{
"$schema": "https://raw.githubusercontent.com/cortexkit/magic-context/master/assets/magic-context.schema.json",
"enabled": true,
"historian": {
"model": "anthropic/claude-haiku-4-5"
},
"embedding": {
"provider": "local"
}
}
For the full configuration reference (including dreamer, sidekick, auto-search, and experimental features), see CONFIGURATION.md in the main repository — the schema is shared between both plugins.
All commands trigger triggerTurn: false (never sent to the LLM):
| Command | What it does |
|---|---|
/ctx-status | Live token breakdown + queued ops + cache state |
/ctx-flush | Force-process pending ops queue |
/ctx-recomp | Rebuild compartments from raw history (heavy operation) |
/ctx-dream | Trigger a dream run on demand |
/ctx-aug | Augment your next prompt with sidekick-retrieved memories |
Magic Context stores everything in a single shared SQLite database at:
~/.local/share/cortexkit/magic-context/context.db
This is the same database the OpenCode plugin uses. Tables are scoped by:
harness column ('pi' or 'opencode') for session-scoped data (tags, compartments, facts, notes)project_path (resolved git root) for project-scoped data (memories, embeddings, dreamer runs)So memories and dreamer state are shared across both harnesses for the same project; per-session tagging stays correctly attributed.
Storage failures are fatal — Magic Context will refuse to register hooks rather than run with ephemeral state, since that would let context grow unbounded across restarts.
For semantic search to work across harnesses, both plugins must use the same embedding model. Magic Context detects mismatch on Pi startup and warns:
WARN embedding model mismatch detected for project ...:
stored vectors use "openai-compatible:Qwen/Qwen3-Embedding-8B" but Pi is configured with "local:Xenova/all-MiniLM-L6-v2".
Cross-harness search will return zero results until vectors are re-embedded.
Easiest fix: configure embedding once in ~/.pi/agent/magic-context.jsonc (Pi) and ~/.config/opencode/magic-context.jsonc (OpenCode) with identical settings.
| Tool | Action set | Purpose |
|---|---|---|
ctx_search | n/a | Search memories + raw session history; returns ranked results with previews |
ctx_memory | write, delete | Manage project memories explicitly (most writes happen via dreamer instead) |
ctx_note | read, write, update, dismiss | Defer intentions for later — surfaced via note nudges at work boundaries |
ctx_expand and ctx_reduce from the OpenCode plugin are intentionally not exposed on Pi — they depend on raw OpenCode message ordinals, while Pi has its own message identity model. Drops still happen automatically via threshold-driven historian; you don't need an explicit ctx_reduce to trigger reduction.
This package is part of the magic-context monorepo. The Pi extension shares the core implementation with the OpenCode plugin via the @magic-context/core workspace dependency, exposing only the Pi-specific adapter layer:
| Pi-specific module | Responsibility |
|---|---|
context-handler.ts | Pi pi.on("context", ...) adapter — tags, drops, runs nudges and auto-search |
subagent-runner.ts | Spawns pi --print --mode json --no-extensions --extension <lean-entry> ... for historian/sidekick/dreamer subagents, with a 2-second drain after the terminal message_end so child processes don't keep the parent waiting |
tools/ | Pi pi.registerTool wrappers around the shared tool implementations |
commands/ | Pi pi.registerCommand wrappers for the five /ctx-* slash commands |
dreamer/ | Pi-side adapter for the shared dreamer scheduler |
system-prompt.ts | Pi before_agent_start injector for <session-history>, <project-memory>, <project-docs> |
config/ | Pi-convention config loader ($cwd/.pi/magic-context.jsonc + ~/.pi/agent/magic-context.jsonc) |
The CLI lives in the unified @cortexkit/magic-context package — setup --harness pi and doctor --harness pi route to the Pi-specific code paths in packages/cli/src/commands/.
For deeper architectural detail, see the main repo's ARCHITECTURE.md.
MIT — see LICENSE.
FAQs
Pi coding agent extension for Magic Context — cross-session memory and context management
The npm package @cortexkit/pi-magic-context receives a total of 38 weekly downloads. As such, @cortexkit/pi-magic-context popularity was classified as not popular.
We found that @cortexkit/pi-magic-context demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.