magic-compact

作者 aerovato已验证

Lossless context compression plugin for Claude Code & OpenCode.

129
Stars
8
Forks
TypeScript
语言
2026/8/23
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

# Add to your Claude Code skills
git clone https://github.com/aerovato/magic-compact

快速入门

使用 magic-compact 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "status": "PASSED",
  "issues": []
}

README.md

Magic Compact

English | 中文

[!IMPORTANT] Magic Compact development has been paused in favor of Operator Memory, its successor. Magic Compact focuses on context compression; Operator already provides durable memory and documentation, and will gain context-management features over time. Install and follow Operator for future development.

Lossless context compression for OpenCode and Claude Code.

Magic Compact Preview

Built with Operator Memory

Why

OpenCode and Claude Code's built-in compaction replaces an entire conversation with one summary blob. The user messages, the assistant's reasoning, tool calls, design decisions, and workflow are all flattened into a generic template (Goal, Progress, Key Decisions...). The agent wakes up with amnesia, forced to reconstruct its working state from an abstraction that captured a fraction of what mattered.

Magic Compact takes a different approach: preserve the conversation skeleton, condense each old assistant turn into its own summary, prune bulky tool I/O, and keep everything retrievable. The agent retains its memory of what it did, why, and what comes next.

How

Instead of collapsing an entire session into a single generic summary, Magic Compact replaces old assistant turns with high-fidelity summaries while leaving user messages and tool calls in place.

The assistant's thought process, decisions, and actions remain in context along with all your commands while unnecessary bloat is stripped away. Long tool calls are aggressively pruned but can be retrieved via a custom read_omitted_content tool.

Compaction Comparison

Features

  • Lossless context compression — Fully preserve working memory instead of flattening history into one recap.
  • Zero compaction overhead — Compaction happens once on your command rather than during the agentic loop. Maximum token savings, minimal cache invalidations.
  • Preserved user messages — Exact requirements and guidance remain visible to the agent, verbatim.
  • Smart tool call pruning — Bulky completed tool I/O is replaced with omission notices, with original content cached and retrievable on demand via read_omitted_content.
  • Recompactable — Run /magic-compact again later to compact new turns while preserving prior summaries.
  • Trim without summarizing — OpenCode can prune historical tool I/O with /magic-trim while preserving assistant responses.

Installation

Magic Compact works flawlessly on Claude Code, but OpenCode will have more features + first class support as OpenCode exposes more functionality to plugins.

Claude Code

Install from this repository's first-party plugin marketplace:

/plugin marketplace add aerovato/magic-compact
/plugin install claude-magic-compact@magic-compact

After installation, run /reload-plugins if Claude Code is already open.

OpenCode

Install from the CLI:

rm -rf ~/.cache/opencode/packages/magic-compact*

opencode plugin magic-compact --global

# If you are encountering "No versions available":
NPM_CONFIG_MIN_RELEASE_AGE=0 opencode plugin magic-compact --global

This installs the package and adds it to your global OpenCode config.

Usage

/magic-compact

To compact, run /magic-compact [N] with an optional argument indicating how many turns to preserve.

  • N is the number of recent assistant turns to preserve as-is. Default: 0 (summarize everything).
  • A backup session is created before the current conversation is compacted. If compaction fails, you will return to the backup.

Examples:

  • /magic-compact — summarize all old assistant turns.
  • /magic-compact 3 — keep the 3 most recent assistant turns, summarize the rest.

/magic-trim (OpenCode Exclusive) (Experimental)

Run /magic-trim [N] to apply the same tool I/O pruning rules without summarizing or deleting ordinary user and assistant content.

  • N preserves tool I/O in the most recent assistant turns. Default: 0 (trim all eligible turns).
  • Trimming does not call an LLM or create a compaction boundary.
  • A backup session is created before trimming.
  • Token reductions are included in /magic-stats.

Examples:

  • /magic-trim — trim eligible tool I/O throughout the session.
  • /magic-trim 3 — preserve tool I/O in the 3 most recent assistant turns.

/magic-stats (OpenCode Exclusive)

Run /magic-stats to show cumulative token savings for the current conversation: tokens pruned, cached tokens saved, estimated money saved, among other statistics.

The Omitted Content Tool

Magic Compact registers a read_omitted_content tool that the agent can call to retrieve any tool input or output that was pruned during compaction or trimming.

Each omission notice in the conversation includes a Content ID (e.g. omitted-001). The agent uses that ID to fetch the original content when it needs stale information that cannot be reproduced via a new tool call.

Claude Code

Claude Code does not expose as much capability to plugins vs OpenCode. Therefore, certain differences are present when using Magic Compact for Claude Code:

  • Magic Compact will create a compacted destintaion sesion instead of compacting in place.
    • Claude Code does not allow us to modify the current session's message transcript
  • After compaction, Claude Code will tell you to run /resume <new-session-id> to enter the compacted session
    • Simply copy and paste that command and run it
  • /magic-stats is not implemented for Claude Code

Pruning Rules

During /magic-compact, pruning applies only to summarized turns. On OpenCode, /magic-trim [N] applies only the tool I/O rules to turns outside the preserved tail.

Kept:

  • User messages (verbatim)
  • Per-turn summaries
  • Tool calls (structure preserved)
  • Selected high-value synthetic messages (shell wrappers, background task results, working-directory change reminders)

Removed or condensed:

  • Assistant reasoning, text, and step markers — replaced by the per-turn summary
  • Most synthetic/injected messages (file expansions, plan reminders, prior compaction notices, etc.)
  • Bulky completed tool I/O — replaced with an omission notice pointing to the cache

Tool I/O Rules

Completed tool outputs over 128 words or 1024 characters are omitted by default. A few tools have special handling.

OpenCode

  • read — output always omitted (stale file contents are reloadable)
  • write / edit / apply_patch — large file content omitted
  • bash — commands over 1024 characters are truncated
  • task — output omitted above a higher threshold (512 words / 4096 characters)
  • question — input and output preserved
  • todowrite / skill — output discarded without caching (redundant or reloadable)

Claude Code

  • Read / NotebookEdit — output always omitted (file text, notebook JSON, images, PDFs are reloadable)
  • Bash.command — commands over 512 characters truncated; full command cached with an omission ID
  • Agent / TaskOutput — output omitted above a higher threshold (512 words / 4096 characters)
  • AskUserQuestion — input and output preserved (captures explicit user decisions)
  • Skill — output discarded without caching (reloadable by re-invoking the skill)

Pending, running, and errored tool calls are always preserved as-is.

Completed tool calls processed by pruning are marked so later trim and compaction operations do not trim them again.

Vs DCP Plugin (OpenCode)

OpenCode-DCP is a runtime context management system that rewrites messages when requested by the model. Magic Compact takes a different approach.

Magic Compact Offers:

  • Simplicity — One command, zero configuration.
  • Lossless quality — Turn-by-turn flow stays intact. All user commands are preserved. All past tool calls are preserved.
  • Maximum token savings — The entire conversation is summarized with one request. Long tool calls are aggressively pruned.
  • No cache churn — Compaction happens once and is cache friendly, whereas DCP may invalidate entire conversations multiple times within one request.
  • Zero assistant overhead — No prompt injections asking the assistant to compact. Your assistant stay focused on its task.

If you want model-driven compaction with increased cache invalidations and token burn, consider using DCP instead.

Vs Magic Context (OpenCode)

Magic Context is a much broader runtime context-management system: it runs background historian and dreamer processes, maintains project memory, and injects recalled memories and history back into the prompt on an ongoing basis. That makes it powerful, but also much heavier in tokens and cache churn.

Magic Compact Offers:

  • Efficiency — One explicit compaction command, no background summarization loop, no always-on memory RAG, and no recurring prompt injections.
  • Lower token burn — Context reduction happens once on demand instead of continuously consuming tokens across every turn.
  • Fewer cache invalidations — The session is rewritten once, then stays stable, instead of repeatedly re-rendering volatile background state.
  • Lossless conversation shape — User messages stay verbatim, tool structure is preserved, and summarized assistant turns remain retrievable.
  • Focused compaction — The plugin does one job: compress the conversation without turning the runtime into a memory subsystem.

If you want a lightweight, user-driven compaction tool with minimal ongoing overhead, Magic Compact is the better fit. If you want a full long-term memory system with background maintenance, Magic Context is the heavier alternative.

Development

See .operator-shared/operator.md for setup and maintenance commands.

Built with Operator

This repository is maintained with Operator Memory — durable, agent-maintained documentation that lets AI agents work on the project with full context across sessions. The published brain lives in .operator-shared/.

常见问题

What is magic-compact?

magic-compact is an open-source ide extensions skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by aerovato. Lossless context compression plugin for Claude Code & OpenCode. It has 129 GitHub stars.

Is magic-compact safe to use?

Yes. magic-compact passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.

How do I install magic-compact?

Clone the repository with "git clone https://github.com/aerovato/magic-compact" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is magic-compact written in?

magic-compact is primarily written in TypeScript. It is open-source under aerovato on GitHub, so you can review or fork the full source.

Are there alternatives to magic-compact?

Yes. SkillsLLM lists many other IDE Extensions skills you can browse and compare side by side. Open the IDE Extensions category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh magic-compact against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

claudian

by YishenTu

An Obsidian plugin that embeds Claude Code/Codex as an AI collaborator in your vault

14,921972TypeScript
IDE 扩展
查看详情

OpenMythos

by kyegomez

A theoretical reconstruction of the Claude Mythos architecture, built from first principles using the available research literature.

14,8003,292Python
IDE 扩展
查看详情

cursor-hooks

by cursor

5

通过 Hooks 自动化 Cursor Agent 事件相关行为。

12,500890TypeScript
IDE 扩展claude-codeai-tools
查看详情

arscontexta

by agenticnotetaking

Claude Code plugin that generates individualized knowledge systems from conversation. You describe how you think and work, have a conversation and get a complete second brain as markdown files you own.

3,479220Shell
IDE 扩展
查看详情

开发者还喜欢

基于喜欢此 Skill 的开发者投票和收藏

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情