
外部記憶があると Claude Code の /compact はほぼ要らないThis article explains how integrating external memory via MCP allows Claude…
匿名の公開いいねです。記事の保存・お気に入りではなく、Featured、Top 3、重要度、掲載順位には影響しません。仕組みとプライバシーAnonymous public likes are reactions, not saved articles or bookmarks. They do not affect Featured, Top 3, importance, or listing order.How it works and privacy
- MCPを通じた外部記憶の導入により、Claude Codeのコンテキスト圧縮コマンド /compact を使わずとも長期的な作業状態を保持できることを解説した記事。
- コンテキスト管理の手間を減らし、開発効率の向上が期待できる。
This article explains how integrating external memory via MCP allows Claude Code to retain long-term session context without relying on the /compact command, reducing manual context management overhead and improving development workflow efficiency.
本ページの本文と要約は AI による自動生成です。日本語版と英語版は言語ごとに独立して生成されるため、表現や詳しさが異なる場合があります。正確性は元記事 (zenn.dev) をご確認ください。The body and summaries are AI-generated independently for each language, so wording and detail may differ. Verify accuracy at the original source (zenn.dev).
要約と収集メタデータに基づく AI 解説。元記事全文の転載・翻訳ではありません。AI explainer based on the summaries and collected metadata, not a copy or translation of the full source article.
外部記憶への退避
Claude Codeでは、自然な区切りで作業状態を外部記憶へ退避できるなら、/compactに頼らず文脈の継続性を保てると説明されている。重要な決定とセッション全体の要約を保存したうえで、/clearによってコンテキスト窓を空にし、次の作業へ移る方法だ。
筆者は、作業終了時に重要な決定を外部記憶へ保存し、セッション全体も要約していた。その直後に/compactを実行したことで、同じ情報を二重要約していることに気づいたという。
/compactの実体
/compactは、会話履歴を単純に短く畳むだけの処理ではない。その時点のコンテキスト全量を入力として、フラッグシップモデルを呼び出して要約する。200Kのコンテキスト窓では、auto-compactが発火する頃に約150〜180kトークンが入力されるとされる。
生成された要約ブロブは、次のコンテキスト窓の先頭へ固定注入される。その窓も埋まれば同じ処理が再び行われるため、長いセッションでは、窓の大部分を読ませて要約し、次の窓へ持ち越す処理が繰り返される。作業途中の細かな状態まで引き継げる一方、現在の窓にある記憶を次の窓向けに一時的に詰め直す仕組みと捉えられる。
CPersonaとMCP
筆者は外部記憶MCP serverとして自作の「CPersona」を使用している。ただし中心となるのは製品固有の機能ではなく、記憶をコンテキスト窓の外へ保存し、後から検索できる構造だ。同じ役割を持つmemory MCP serverでも、基本的な構造は変わらないという。
archive_episodeへ渡すsummaryとkeywordsは、より安価なサブエージェントのSonnetに前計算させている。これにより、必要な情報を外部へ残しつつ、次の作業では空のコンテキスト窓から再開できる。
External memory via MCP
Integrating external memory through MCP can let Claude Code preserve long-term working context without relying on /compact. This matters because decisions and session summaries can be stored outside the context window, reducing manual context management while retaining continuity between sessions.
The author’s workflow saves important decisions to external memory and summarizes the full session when work ends. Instead of immediately summarizing the same information again with /compact, the session can be cleared with /clear. At the next natural stage of work, the stored information remains available for retrieval.
The /compact command
The article describes /compact as more than a lightweight operation that simply shortens the conversation history. It is a summarization call to a flagship model, using the full context available at that point as input.
With a 200K context window, around 150–180k tokens may be supplied when auto-compact activates. The resulting summary blob is then inserted at the beginning of the next window. If that window also fills, the process happens again. A long-running session can therefore repeatedly summarize most of one window and carry the result into another.
This approach can preserve fine-grained intermediate state. In practical terms, however, /compact repackages memory from the current window into a temporary form that can be used in the next one.
Context window
External memory changes where that continuity is kept. If relevant information is moved out at a natural stopping point, /clear can reset the context window completely while the saved decisions and session summary remain searchable.
The author uses a self-built external-memory MCP server called CPersona. The central pattern is not specific to that server: information is stored outside the context window and retrieved when needed. A memory MCP server serving the same role can follow the same basic structure.
Summary and keywords
In the described setup, the summary and keywords passed to archive_episode are precomputed by the less expensive Sonnet subagent. This separates preparation of the stored memory from repeatedly compacting a large active context.
The result is an alternative flow: archive the important state externally, clear the current window, and retrieve the saved memory for later work.
ポコとTECHガイドPoko & TECH Guide
ポコと当サイトのTECHガイドが、記事の要約と収集した情報から読みどころを語るAI生成の対話です。Poko and TECH Dashboard's own TECH Guide discuss the article's highlights in an AI-generated conversation based on its summary and collected source details.
- ポコPoko200Kの窓で、/compactが約150〜180kトークンを読むの? これって大きいこと?In a 200K window, /compact may read around 150–180k tokens? Is that a big deal?
- TECHガイドTECH Guideかなり広い範囲を入力して要約する処理だね。長いセッションでは、それを次の窓へ持ち越すたびに繰り返すんだ。That means summarizing most of the window. In a long session, the process repeats whenever that summary is carried into the next window.
- ポコPoko/compactって、会話をちょっと短くするだけじゃないの?So /compact doesn’t just trim the conversation a little?
- TECHガイドTECH Guideここでは、窓の中の記憶を要約し、次の窓でも使える形に詰め直す処理なんだ。その要約は次の窓の先頭に入るよ。Here, it summarizes the current window’s memory and repackages it for the next one. That summary is then placed at the start of the new window.
- ポコPokoぼくなら、区切りごとに決定や要約を外へしまって、次は/clearでまっさらから始めたいな。I’d save decisions and summaries externally at each natural stopping point, then use /clear and start fresh next time.
- TECHガイドTECH Guideそれなら、自然な区切りで保存でき、あとから検索できる外部記憶が前提だね。作業途中の細かな状態には/compactの強みもあるよ。That works if external memory can save things at natural breaks and retrieve them later. /compact still has an advantage when you need to preserve fine-grained, in-progress state.




