---
title: コンパクションの概要
url: https://platform.claude.com/docs/ja/build-with-claude/compaction
description: コンパクションの機能、オンデマンドコンパクションとトークンしきい値でのコンパクションの違い、そしてタスクに応じて参照すべきページについて説明します。
---

「compaction」（コンパクション）は、会話の古いターンを、Claudeがサーバー上で作成した要約に置き換えます。そのため、独自の要約コードは必要ありません。コンパクションにより、長い会話やエージェントタスクを「context window」（コンテキストウィンドウ）内に収められます。また、会話が長くなるにつれて応答品質が低下するため、アクティブなコンテキストを小さく保つ役割も果たします。

この概要を読み飛ばしたい場合は、[オンデマンドコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand)から始めて、アプリケーションにコンパクションを追加してください。オンデマンドコンパクションと[トークンしきい値でのコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-threshold)はどちらもベータ版ですが、より一般的なユースケースに対応しているのはオンデマンドコンパクションです。古いツール結果や古い思考ブロックを、要約せずにルールに基づいてクリアするには、[コンテキスト編集](https://platform.claude.com/docs/ja/build-with-claude/context-editing)を参照してください。

## コンパクション方法の選択

オンデマンドコンパクションが利用可能な場合は、常にそちらを使用してください。

|                                                                                                                     | [オンデマンドコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand)                                                                         | [トークンしきい値でのコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-threshold)                                                                                                              | 独自の要約機能（[クライアント側でのコンパクション](https://platform.claude.com/docs/ja/build-with-claude/preserved-thinking#custom-compaction-on-the-client)） |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| **タイミングを決めるのは誰か**                                                                                                   | あなた（リクエストを送信することで）                                                                                                                                                  | API（入力トークンが設定したトリガーに達したとき）                                                                                                                                                                                   | あなた                                                                                                                                   |
| **記述するコード**                                                                                                         | 要約をリクエストして差し替える[コンパクションループ](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#compact-in-a-loop)                                           | 通常のリクエストに1つのパラメータを追加                                                                                                                                                                                         | 要約の呼び出し、そのプロンプト、および履歴の書き換え                                                                                                            |
| **その後に送り返すもの**                                                                                                      | 返されたブロックを、それが要約するメッセージの代わりに`messages`の先頭に配置                                                                                                                         | 通常どおり追加された応答。APIはブロックより前の内容を破棄します                                                                                                                                                                            | 独自のメッセージとしての要約                                                                                                                        |
| **最近のターンがそのまま保持される**                                                                                                | はい：[最近のターンを保持するコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-keep-recent-turns)                                                         | はい（[コンパクション後の一時停止](https://platform.claude.com/docs/ja/build-with-claude/compaction-threshold#pausing-after-compaction)を行い、それらを再挿入することで）                                                                     | はい                                                                                                                                    |
| **バックグラウンドで実行される**                                                                                                  | はい：[バックグラウンドでのコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-background)                                                                 | いいえ：しきい値に達したリクエスト内で実行されます                                                                                                                                                                                    | はい（独自のコード内で）                                                                                                                          |
| **保持したターンが思考を維持する**（[保持された思考](https://platform.claude.com/docs/ja/build-with-claude/preserved-thinking)に対応するモデルの場合） | はい（[コンパクションと思考の保持](https://platform.claude.com/docs/ja/build-with-claude/compaction-thinking-blocks)に記載の条件下で）                                                       | いいえ：Claude Fable 5.1、Claude Opus 5.5、Claude Sonnet 5.5、Claude Haiku 5.5では、再挿入するターンの思考を削除または破棄してください（[しきい値コンパクションの例](https://platform.claude.com/docs/ja/build-with-claude/compaction-threshold#examples)を参照） | いいえ：その思考は[チェックに失敗します](https://platform.claude.com/docs/ja/build-with-claude/preserved-thinking#keep-tail-compaction)                  |
| **ベータヘッダー、パラメータ、プラットフォーム**                                                                                          | `compact-2026-09-04`とトップレベルの`compaction`パラメータ。プラットフォーム：[オンデマンドの互換性リスト](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#compatibility)を参照 | [しきい値の互換性リスト](https://platform.claude.com/docs/ja/build-with-claude/compaction-threshold#compatibility)と[基本的な使い方](https://platform.claude.com/docs/ja/build-with-claude/compaction-threshold#basic-usage)を参照 | なし。独自のコード内で実行されます                                                                                                                     |
| **選択すべき場合**                                                                                                         | アプリケーションがコンパクションのタイミングを制御する必要がある場合、要約の作成中に一時停止できない場合、または最近のターンとその思考を保持する必要がある場合                                                                                     | 通常のリクエスト内でAPIにコンテキストを管理させたい場合                                                                                                                                                                                | すでに独自の要約機能を実行しており、それが履歴全体を要約に置き換える場合                                                                                                  |

## オンデマンドコンパクションのオプション

[オンデマンドコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand)では、アプリケーションが待機している間に会話全体を要約するループを紹介しています。このリストの最初の2つのページは、そのループの実行方法を変更するもので、組み合わせて使用できます。3つ目のページは、思考ブロックを送り返し、かつそのいずれかを行う場合に該当します。

* [直近のターンを保持するコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-keep-recent-turns)：最後の数ターンを一字一句そのままClaudeに渡す必要がある場合。要約の対象は古いターンのみになります。
* [バックグラウンドでのコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-background)：要約のために会話を一時停止できない場合。作業を続けている間にリクエストが実行され、ブロックが届いた時点で差し替えます。
* [コンパクションと思考の保持](https://platform.claude.com/docs/ja/build-with-claude/compaction-thinking-blocks)：思考の保持に対応したモデルで思考ブロックを送り返し、かつ直近のターンを保持するか、バックグラウンドでコンパクションを行う場合。それ以外の場合は読み飛ばしてください。
* [独自の要約プロンプトを作成する](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#write-your-own-summarization-prompt)：デフォルトの要約では、後のターンで必要な情報が失われる場合。独自のプロンプトがデフォルトのプロンプトに置き換わります。
* [再度コンパクションする](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#compact-again)：すでにコンパクションブロックで始まっている会話が、再び長くなった場合。

以下のトピックは他のページにあります：

* [要約をリクエストする](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#request-a-summary)は、オンデマンドコンパクションのページにあります。
* [要約から続ける](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#continue-from-the-summary)は、オンデマンドコンパクションのページにあります。保持するターンで思考を有効に保つための条件は、[コンパクションと思考の保持](https://platform.claude.com/docs/ja/build-with-claude/compaction-thinking-blocks)にあります。
* 要約が返されない場合：オンデマンドコンパクションのページにある[要約が返されない場合やエラーを処理する](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#when-no-summary-comes-back)を参照してください。
* APIの他の機能との関係：オンデマンドコンパクションのページにある[制限と他の機能との相互作用](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#how-it-fits-with-the-rest-of-the-api)を参照してください。
* 使用量の理解：オンデマンドコンパクションについては[コンパクションの使用量をカウントする](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#understanding-usage)を、しきい値コンパクションについては[使用量の理解](https://platform.claude.com/docs/ja/build-with-claude/compaction-threshold#understanding-usage)を参照してください。
* 互換性：それぞれの種類に独自のベータヘッダーがあるため、各ページに個別のリストがあります。[オンデマンドの互換性リスト](https://platform.claude.com/docs/ja/build-with-claude/compaction-on-demand#compatibility)または[しきい値の互換性リスト](https://platform.claude.com/docs/ja/build-with-claude/compaction-threshold#compatibility)を参照してください。

しきい値コンパクションには専用のページがあります：[トークンしきい値でのコンパクション](https://platform.claude.com/docs/ja/build-with-claude/compaction-threshold)。
