ChatShell Download
All posts

Long Conversations That Don't Forget: Compacting Context as Images

ChatShell Team,

Every model has a context window, and a long enough conversation fills it. An agent that searches the web, reads files, and runs commands fills it fast, because every tool result lands in the context too.

When that happens, an app has three choices: fail, quietly drop old messages, or compress them. ChatShell compresses them. This post is about how, because the obvious way to do it turns out to be one of the worst.

Summaries shred facts

The standard approach is to ask the model to summarize the older part of the conversation, then replace it with the summary. It sounds reasonable. The problem is what a summary keeps.

A summary keeps the gist: what you were working on, what was decided. It drops the details: the exact figure from the page you fetched an hour ago, the file path, the error message, the name in the third paragraph. Those details are usually the reason you’re still in the same conversation.

Can Bölük measured this in Snapcompact: SoTA compaction. He compressed about 150,000 characters of context in different ways and then asked reading-comprehension questions (SQuAD) about the compressed part. A few results, scored as F1 where 1.0 is perfect:

How old context was carriedClaude Fable 5Claude Opus 4.8
Full text (the ceiling)0.9040.911
Handoff document0.5400.248
LLM summary0.4060.000
Text rendered as images0.8820.601

The summary scored zero on one frontier model. The rendered images came within a few points of keeping the full text on another.

Text as pictures

The idea behind snapcompact is simple to state. Vision models are good at reading text in images, and providers bill images by size, not by how much text they contain. So instead of summarizing old history, render it, word for word, into dense images of small pixel-font text, and give those images to the model.

The article reports that a 1568×1568 image holds about 40,000 characters, roughly 10,000 text tokens, and is billed at about 3,300 image tokens on Anthropic. The model gets a near-verbatim copy of the old history for about a third of the price.

It isn’t free. Models think harder when reading dense images, so the first turn after compaction costs extra output tokens. But that happens once per compaction, not every turn. And how well a model reads these images is a property of that model’s vision system, so it has to be checked per model rather than assumed.

How ChatShell does it

ChatShell’s compaction is adapted from the open-source oh-my-pi project (MIT), which is where snapcompact comes from. Here’s the flow.

1. Decide when. After each turn, ChatShell estimates the size of the conversation’s context. Compaction starts when it reaches the model’s window minus a reserve: 15% of the window, or 16,384 tokens, whichever is larger. If the model’s window is unknown, ChatShell assumes 128k. Window sizes come from the model capabilities database ChatShell already uses.

2. Decide where to cut. The most recent 20,000 tokens or so are always kept as they are. The cut only falls on a boundary before one of your messages, so a tool call is never separated from its result. Splitting them would confuse the model about what it had done.

3. Compress the older part. This depends on the model:

  • Models that can see: the older history is rendered into up to eight bitmap frames. The text right at the start and end of the compacted part is also kept as plain text, so the transition reads smoothly. Tool noise is drawn in a dimmer ink, so the model can tell the conversation from the plumbing.
  • Text-only models: an LLM summary, with a structured handoff format. If you’ve set a tiny model, it writes the summary instead of your main model, so the work is cheap.

If rendering frames fails for any reason, ChatShell falls back to the summary. A conversation always gets one or the other.

4. Rebuild the context. On the next request, everything before the cut is replaced with the compacted version, followed by the recent messages in full.

Compacting again later doesn’t stack summaries of summaries. The frames are rendered from the original text each time, so the older history keeps the same quality as it ages.

Chinese, Japanese, and Korean

Pixel fonts for this job usually only cover Latin text. Our first version rendered CJK characters as question marks, which we only caught by testing with real mixed-language history. ChatShell now falls back to a TrueType font for missing glyphs, gives wide characters two cells, and wraps lines with that in mind. In our read-back test, a model transcribed a mixed Chinese and English line from the rendered frames exactly.

What you see

Nothing, mostly. That’s the goal.

  • Your history is never trimmed. The transcript in the app stays complete, on this device and in sync. Compaction only changes what the model is sent.
  • There’s no setting to configure. It triggers per conversation, based on each model’s actual window.
  • Synced and stored efficiently. A compaction record stores the source text, not the images. Frames are re-rendered on demand, which keeps each record at tens of kilobytes instead of more than a megabyte.

Limits

  • Frame quality is capped at eight images per compaction. That is far below oh-my-pi’s own limit, and deliberate: ChatShell’s typical context windows are smaller, and compaction records sync between your devices.
  • Context size is estimated locally, at about four characters per token, rather than read from the provider. It’s accurate enough to decide when to compact, but it’s an estimate.
  • How well a model reads the frames varies by model. On text-only models you get the summary, which keeps the gist but not every detail.

Compaction shipped in ChatShell 0.8 and has been refined since. The details are in the Context Compaction docs. Thanks to Can Bölük and the oh-my-pi contributors for the research and the renderer this builds on.