condensate

Context windows and memory

How Condensate keeps long tasks inside the model's context window.

On this page

Every model call has a finite context window, and a long task outgrows it. Condensate cuts what the model sees on its next call, and never rewrites the thread's record.

The log stays. The next model input changes.
Durable history
RequestReadsToolsDecisionsRecent work
Recorded events remain available to inspect.
↓ model-facing projection ↓
Next model input
RequestReadsToolsDecisionsRecent work

Earlier messages compete with new work for a finite context budget.

Conceptual example, not a token measurement. A summary is one reduction strategy; the planner also supports cheaper tool-result reductions.

History and context

A thread's history is everything that happened in it. Its context is the part the model sees on its next call. A window is one cut that shortens the context and leaves the history intact, because the thread log is append-only. Each window is recorded as an event that says where the cut is, and the view the model gets is rebuilt from the log on each call. A large file read stays in the history after a window drops it from the context, and the agent can read the file again when it needs the details.

Windows run on the claude, codex and pi engines. The condensate engine does not shorten its conversation yet; engines says what that means for a long task.

When a window is taken

A window is planned before a model call when the next prompt would pass the session's working ceiling. The ceiling sits below the model's own window because every call resends the whole prompt, and a long prompt answers slowly. By default it is 40 percent of the window for Codex and the pi engine, capped at 120,000 tokens, and 75 percent for Claude Code, capped at 200,000. It is never below 48,000 unless the model's window is smaller. A Claude id ending in [1m] on Claude Code, and a gpt-6 model on the pi engine, use the model's whole window. A start request can set its own ceiling, up to the model's window. CONDENSATE_WINDOW_CEILING_CLAUDE, CONDENSATE_WINDOW_CEILING_PI (which covers Codex too) and CONDENSATE_WINDOW_CEILING can lower it, never raise it.

Condensate tries three kinds of window, cheapest first. microcompact clears older tool results the model can read again, such as file reads, searches and diffs. collapse also clears older action results, such as commands and edits, and leaves a short record that each one happened. summary replaces an older part of the conversation with one summary and keeps the most recent part verbatim. If a cheap kind frees less than 10 percent of the context, or the prompt still lands over the ceiling, Condensate moves to the next. The cheap kinds never clear the five most recent tool results, small results, or memory and control results.

Two conditions hold a window back. When the system prompt and skills take up most of the ceiling, Condensate raises the ceiling so they use at most three quarters of it, up to the model's own window. When a delegated child thread has not been joined yet, the spawn and everything after it stay verbatim so the child's result is not lost. When windows come too often, three within three turns or three summaries within ten minutes, Condensate stops windowing and writes a system line saying so. If no kind can cut and the next prompt would still be over the ceiling, the turn stops with a stated reason.

Who writes a summary

The agent can write it. When an agent answers a compaction request with its own summary, Condensate uses that text as written.

Otherwise the context summarizer writes it in one model call with no tools. It runs first on a fast model set by CONDENSATE_CURATOR_MODEL, then CONDENSATE_CURATOR_FALLBACK_MODEL, then the thread's own model. It keeps every failed tool call with its error text, and every human message, verbatim, because failures are the history a resumed agent needs most. When a memory service is configured through CONDENSATE_HINDSIGHT_URL, the summarizer asks it for reference notes and waits one and a half seconds; a slow or failed recall costs the summary nothing.

The summarizer has 180 seconds plus 10 seconds per 10,000 tokens in use, or the value of CONDENSATE_WINDOW_DEADLINE_MS. If it misses that while there is still room, the turn goes on uncut. If the provider has already refused the prompt, Condensate drops the earlier messages without a summary, tells the model that happened, and asks it to reread the brief and any file before relying on it.

Lead agents

A lead agent plans the work and hands tasks to other agents, so it is cut later than other agents. Its line is the model's own window, less the reply reserve and room for one more tool result. On the pi engine a lead agent is compacted automatically when its prompt crosses that line. On Claude Code and Codex, the runtime asks the lead agent to compact and waits three minutes. If nobody answers by then, the runtime cuts on a summary it writes itself.

GET /threads/:id/compact shows the pending ask and a preview of what a cut would remove. POST /threads/:id/compact answers it with mode set to summary, microcompact or decline. With nothing pending, a summary or microcompact answer queues a compaction for the next tool boundary, and a decline is refused with nothing-pending. A thread with more than one session needs the seat field, or the call is refused with seat-required.

Inspect a window

Each window is an event in the log. It carries the cut point, where the kept range begins, the kind, the summary, its author, and the numbers that triggered it. To read the full history behind the windows, add history=1:

export THREAD_ID='replace-with-an-existing-thread-id'
curl -fsS \
  "http://127.0.0.1:4741/threads/$THREAD_ID/tail?after=0&limit=100&history=1"

Page through nextAfter while hasMore is true, as threads and the runtime describes.

How each engine applies a window

On the pi engine the check runs before every model call. If the provider still refuses a prompt as too large, the loop takes one forced window, clears the largest kept tool results until the prompt fits, and calls again.

On Claude Code the check runs after tool use. When a window is due, Condensate forks the Claude session at its first safe point and starts the fork with the rendered window as its first message. When a fork would only rebuild a prompt the provider has already refused, Condensate starts a fresh Claude Code session instead. A Claude subagent has its own context, which the check does not see, so it is not windowed.

On Codex the check runs after each completed turn. When a window is due, Condensate interrupts the turn, waits for running tools to finish, and starts a fresh Codex thread with the same persona, tools and permissions, with the window as one historical-context message. Codex can still compact on its own when a prompt overflows; Condensate then records a notice. Set CONDENSATE_CODEX_WINDOWING=0 and restart the session to hand compaction back to Codex.

Limits

A summary is shorter than what it replaced, so the model may need to reread a file or an earlier result after a window. The log keeps the material; it does not put every earlier detail back into the next call.