# How do I compress context?

> Cube Agent 2.4.1 Release (Build 2004105) User Guide.
> Category: Chat. Content baseline: 2026-12-05.
> Web page: https://cubeagent.app/en/docs/context_compression/

## How to compress context

Open the chat screen's top-right More menu and select **Compress context**, or enter from the **Context usage** panel. The selected middle span of messages is turned into a summary, while original messages on both sides continue entering subsequent requests in their original order; all original messages and images remain fully viewable in your chat history.

Three synchronized ways to pick the compression range:

- **Exact message numbers and fine-tuning**: Type message numbers directly into **Start message** / **End message**, or tap the **− / +** buttons beside them to adjust one message at a time without dragging handles in long chats. When a “Context cleared” divider exists, numbering aligns automatically to actual message positions after the divider.
- **Quick range presets**: Switch in one tap between **Smart pick**, **Keep last 10**, **Keep last 20**, and **All**. Conversations with 6 or more messages also offer **First half** (which automatically changes to **Continue first half** once an earlier summary exists, selecting the first half of the remaining uncompressed range in one tap).
- **Dual-slider drag**: Drag the two handles below to fine-tune the span; the track endpoints show the earliest and latest compressible message numbers.

Below the card, single-line previews of the selected start and end messages (**Start #N** / **End #M**) and **Estimated post-compression usage** update live so you can double-check boundaries without leaving the panel. **Estimated post-compression usage** includes uncompressed messages on both sides, the summary, and fixed prompts; actual usage still depends on summary length, attachments, and the provider's tokenization. Very long chats support **segmented compression**: even if compressing one segment leaves total usage above the trigger threshold, it completes and saves immediately; when you later select further forward or tap **Continue first half**, Cube automatically reuses and merges the existing summary and sends only newly added messages to the model rather than resending already-compressed content. If compression fails, narrow the range and compress in stages; if the selected range still exceeds the compression model's window, pick a larger-window model under **Advanced** for that run.

Whenever the assistant needs to verify details, it can search and read the compressed original messages on demand.

## Clear context

To continue chatting from a specific point in the current conversation, open that message's More menu and choose **Clear up to here**. A “Context cleared” divider appears beneath it, and subsequent sends include only turns below that divider. To start fresh from the end of the session, select **Clear context** from the chat screen's top-right More menu. Messages above the divider remain readable, searchable, and copyable. You can clear multiple times; the latest divider determines the active starting point.

Tap **Undo** on the divider to restore prior context. If messages already exist below the divider, Cube asks to confirm before undoing; when the divider sits at the end, you can also undo directly from the top-right More menu. Regenerating an older reply above the divider still uses its original context at that time; regenerating a user message above the divider restarts the chat from that message and removes the divider along with later messages. Compressing after clearing applies only to messages below the divider.

## Auto-compression and trigger thresholds

Turn on **Auto-compress context** in **Settings → App Settings → General** (off by default); each conversation can also toggle it individually in the **Context usage** panel. When enabled, Cube compresses automatically near the trigger threshold before sending or between tool steps, then continues without redoing already-executed actions. During pre-send compression you can tap **Skip and send now** to skip just once. Tapping Stop halts the entire send while keeping your message in the input box. If auto-compression does not complete, the send proceeds with the original context and will not auto-compress again for that turn.

Auto-compression thresholds support two levels of control — **global default** and **per-model override**:

- **Global compression trigger**: In **Settings → App Settings → General → Compression trigger**, choose **Auto** (~80% of the model's real context window), **By percentage (%)** (30%–95%, scaled dynamically to each model's window and bounded automatically by usable capacity), or **By usage (K)** (32K–2000K — e.g. 200K or 500K — triggering when context reaches that size and keeping post-compression usage below it; falls back to Auto if set higher than the model's automatic trigger point).
- **Per-model trigger threshold (optional)**: Open **Settings → Models & usage → Provider Management → choose provider → edit chat model → Auto-compression trigger threshold**, or tap the **Trigger threshold** row in the chat's **Context usage** panel to jump straight to that model's editor. Three modes are available: **Follow global** (default, keeps existing behavior), **By percentage (%)** (30%–95%, with quick presets at 60%/70%/80%/85%/90% calculated against the model's actual context window), or **By tokens** (at least 8K; supports values like 64K, 200K, 800K, 1M, or exact integers, along with recommended presets for the current window).
- **Priority and safety ceiling**: When a per-model trigger threshold is set, that model follows its own setting first instead of the global trigger. Whether set by percentage or tokens, the actual trigger is automatically capped within the model's usable capacity after reserving reply space and a safety margin, with a live preview bar in the model editor. If system prompts, Knowledge Bases, and tool definitions already occupy a large share of the window, setting the trigger too low may prevent meaningful reduction — raise the threshold in that case.
- **Inspect the active value**: Check the active trigger threshold and its source badge (**Model override** / **Global ratio** / **Global cap** / **Window default**) inside the auto-compression section of **Context usage**; when auto-compression is enabled, the window progress bar also marks the trigger position.

When auto-compression is off, Cube only reminds you: suggesting compression at 70% usage and reminding again when approaching the space needed to run compression. Models without a reliable context window do not auto-compress — fill in the window size in model settings or compress manually.

## Context usage and token units

In the **Context usage** panel, see how much of the window is currently estimated for conversation turns, tools, images, and attachments. Any portion of actual input usage that cannot yet be categorized is shown separately. When one reply runs multiple tool-calling rounds, each round's usage counts toward actual consumption. Check current window usage to gauge how much more content fits.

Context window capacity in the model editor accepts exact integers as well as K/M units: **1K = 1,000 and 1M = 1,000,000 tokens** (such as 272K, 1M, or 1.048576M). The exact integer is stored — an existing `1,048,576` will not change into another number just because it displays as `1.05M`, and editing other fields like the model name will not overwrite capacity. Enter the provider's real total window rather than the max output limit.

The Context usage panel also displays the last request's complete JSON payload size, image count, and inline encoded image size (failed requests included). This differs from the token window and updates on the next send after compression.

When a request payload is too large (HTTP 413 or exceeding the local single-request size cap), the app automatically runs a silent two-step recovery so you do not have to manually pick images to delete: first, it omits pixel data from earlier historical images in this request (keeping the current turn's new images while leaving original images and chat history untouched; if the **Read image** tool is enabled, placeholders include resource references so the model can view them again on demand) and retries while tightening the future historical image budget for this conversation; if no earlier historical images remain to drop and the request is still over the limit, the second step automatically reduces the resolution and size of current images and retries once more. When a compression request itself hits HTTP 413 or a size limit, Cube performs bounded convergence within a single request (retrying first with text-only history without images; if default or auto compression still exceeds the limit, retrying once with only the target span to compress — never silently splitting into multiple uncached background requests). If it still exceeds the provider's limit, tap **Compress context** right on the error card and compress in stages using **First half / Continue first half** or smaller start/end ranges so every step stays a single controlled request; alternatively, open a new conversation to process in batches. Changing models under the same provider does not necessarily raise its payload size limit.

## Per-conversation compression instructions

Expand **Compression instructions** in the compression panel (optional; leave blank to use default rules) to note details that should be preserved first — such as character relationships, emotional shifts, or code specifics — up to 2,000 characters. Tap **Save instructions** to save separately; tapping **Start compression** also saves first. Closing the panel without saving discards unsubmitted edits.

Instructions apply only to the current conversation, remain intact after switching models under **Advanced**, and carry forward to later compressions; clearing and saving restores defaults. Edits affect only the next compression — they do not rewrite existing summaries and cannot recover details omitted from previous summaries. Custom instructions add preservation priorities without replacing foundational rules like staying faithful to original messages and never fabricating facts.

## Viewing summaries and interruptions

While compression is running, progress appears above the input box and you are free to chat elsewhere; once complete, tap **View summary** in the prompt, or open **top-right More menu → View context summary** anytime later. The summary condenses prior context for subsequent turns and may omit fine details — if you need to verify something, simply ask the assistant and it can inspect the original messages on demand.

If most context usage sits outside chat history (for example, large mounted Knowledge Bases or many tools) and compression frees little space, Cube lets you choose **Keep anyway** or **Discard this summary**. Discarding leaves context untouched, though token usage from the attempt still counts.

Failures or cancellations never overwrite existing context with an incomplete summary; check the error prompt and retry. If the OS terminates the app process, an in-flight cloud request is not guaranteed to be canceled, and background execution is governed by OS limits.

## Models and costs

By default, compression uses the current chat's model and reasoning effort to maximize provider cache reuse. Switch to **Custom model** in **Settings → Default Models → Context compression** to pick a specific provider and model; the **Context usage** panel displays the active configuration. The custom model receives the history to summarize plus any existing summary, so configure it with a sufficiently large context window.

Once a custom model is selected, you can turn on **Retry with chat model if compression fails** below (off by default). If the custom model is unavailable, runs out of window, or fails, Cube retries once with the current chat model — sending the history to the chat model's provider and incurring actual request charges there. Total compression wait time is capped at **15 minutes**; when retry is enabled, the first attempt gets up to 12 minutes so time remains for the retry. Tapping Stop or Skip ends the attempt immediately, and existing chat data stays stored locally.

## History message count limit

If you set a **Context message count** cap in assistant settings, outgoing turns (including tool-calling chats) truncate older history to that cap; auto-compression will not re-include earlier messages already excluded by the cap, respecting the sending scope you configured.

For manual compression, expand **Advanced** at the bottom of the panel to pick a different model and reasoning effort for that run only. Using another model follows that provider's pricing and caching behavior. Compression always keeps original messages intact. The manual entry may be unavailable while a reply is generating, another compression job is active, or there is nothing eligible to compress.
