Repo of the Day
aerovato/magic-compact
Published: Aug 28, 2026
Open repository ↗Lossless context compression plugin for OpenCode
Summary
Magic Compact is a TypeScript plugin that performs lossless context compression for OpenCode and Claude Code coding agents. Instead of replacing a long conversation with a single generic summary like the built-in compaction, it condenses each old assistant turn into its own summary while preserving user messages, tool call structure, and access to the original tool output. The README notes that development has been paused in favor of the successor project Operator Memory, though Magic Compact "remains fully functional."
What it is useful for
Magic Compact helps engineers working in long agentic coding sessions where the conversation outgrows the model's context window. The built-in compaction flattens the assistant's reasoning, decisions, and tool calls into a generic recap, which can leave the agent reconstructing its working state from an abstraction. Magic Compact keeps the conversation skeleton intact: user commands stay verbatim, tool call structure is preserved, and old assistant turns become per-turn summaries the model can still reason about.
It is also useful for token and cost control without sacrificing context quality. Tool I/O is pruned aggressively, with completed outputs over 128 words or 1024 characters replaced by an omission notice that points to a cached copy. The agent can call the registered read_omitted_content tool using a Content ID like omitted-001 to fetch the original output on demand. Compaction is one-shot and user-driven rather than a continuous background process, and the session can be recompacted later as new turns accumulate.
How engineers can use it
For Claude Code, the README documents:
/plugin marketplace add aerovato/magic-compact
/plugin install claude-magic-compact@magic-compact
For OpenCode:
opencode plugin magic-compact --global
After installation, run /reload-plugins if Claude Code is already open. Inside a session, run /magic-compact to summarize all old assistant turns, or /magic-compact 3 to keep the three most recent turns intact and summarize the rest. A backup session is created first, so a failed compaction returns to the original. On OpenCode, /magic-trim applies only the tool I/O pruning rules without summarizing text, and /magic-stats reports tokens pruned, cached tokens saved, and an estimated money figure.
Documented limitations: Claude Code has reduced feature support — there is no /magic-stats, and compaction creates a new session you must resume with /resume <new-session-id> instead of rewriting the current one. /magic-trim is OpenCode-only and marked experimental. Special tool handling differs between hosts — for example, OpenCode's read always omits output, while Claude Code's Read does the same for files, notebooks, images, and PDFs. Pending, running, and errored tool calls are always preserved as-is.