Manuscript Offprint

arXiv:2610.34425

CTXAgent - Self-Controlled Context Management of LLM Agents

Matthias Busch, Marius Tacke, Roland C. Aydin, Christian Feiler, Christian J. Cyron

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Agent harnesses keep long sessions inside the context window by compacting the history when a token threshold is crossed. We study an alternative in which the model manages its own context: it decides when to compact, what to keep and what to write as the hand-off, given two tools and one paragraph of guidance. Since earlier work found that open-weight models cannot manage their own context without scaffolding, we compare seven frontier models under identical conditions, with and without the context tools, on token cost and benchmark score, and we compare our harness with three widely used harnesses on two of these models. The benchmark is assembled from existing ones: coding exercises, multi-step SciCode problems and SWE-bench Pro and Terminal-Bench 4.0 tasks are interleaved with planted facts, ephemeral observations and standing instructions, all checked deterministically, in sessions of 35–212 turns that resemble a user working through different tasks in one chat. Most of the strongest models manage their context: they compact and curate regularly, the live context of the mixed sessions stays mostly below 100k tokens, and their benchmark scores mostly do not drop significantly. For the models that manage their context well, the cost reduction is substantial but varies between models, because some models compact so often that other costs increase. With Claude Opus 5.5, the self-managed harness matches Claude Code on task success at 34 % lower cost than its explicit 200k-window configuration and 49 % lower than its default, with no context window to choose. We release the agent, the benchmark and all result rows.

Keywords: large language models · LLM agents · context management · context compaction · prompt caching · agent harnesses

*Corresponding authors: matthias.busch@tuhh.de, christian.cyron@hereon.de

1 Introduction

The dominant cost of a long agent session is the prefix re-sent with every request, and the dominant risk is that the prefix stops fitting or stops being useful, either because the window overflows or because the information that matters is buried among tokens that no longer matter. Production harnesses therefore compact: Claude Code trims old tool results, offloads large ones and, close to the window, replaces the history by a structured summary [3, 4]; Codex compacts server-side at a configured limit and keeps the most recent user messages [31, 32]; OpenCode compacts when its configured window is reached [2]. In their default configurations the moment of compaction is a token threshold and its content is a fixed recipe. The model, which is the only party that knows that a task has just finished and that the files read for it are no longer needed, is not consulted, and the operator has to choose a window that suits every task at once.

Whether the model can take over this decision has been examined for open-weight models. Li et al. [22] gave such models a compaction tool and found that, unprompted, they do not recognise when their own context has degraded; they added a rubric probed at fixed intervals, admission gates and a forced backstop, and noted that frontier models with stronger metacognition may not need them. This paper tests that conjecture on seven current models and separates it from the question it raises next: if a model can manage its context, what does a harness built on that ability change compared with a harness built on a threshold? Model-decided compaction has been proposed in several forms, trained into coding agents [12, 25, 50], scaffolded with a rubric [22], or elicited by exposing the context as a file [38].

In this study, we add a prompt-only variant of model-managed context: two tools and one paragraph of guidance, without training or scaffolding, in a local agent, CTXAGENT. We run seven current models under this identical instruction, with and without the tools, on a benchmark that interleaves coding exercises, multi-step SciCode problems and, in a harder family, SWE-bench Pro and Terminal-Bench 4.0 tasks with planted facts, ephemeral observations and standing rules, so that information lost to compaction can become a task failure. We further run the same model through Claude Code, Codex, OpenCode and CTXAGENT on byte-identical sessions of 35–212 turns behind one accounting proxy, so that dollar cost with prompt-cache accounting can be compared across harnesses at their own windows. The paper reports which models manage their context and how, what the management costs and saves on each provider's price list, which losses it causes, and what the harness changes for a model that manages its context well.

References (41)