Study: cutting coding-agent tokens with compaction can make runs 20–80% slower
A ~35,000-run arXiv study finds token-saving context compaction can slow coding agents. For anyone tuning Claude Code, OpenCode or Codex compaction.
Picture a two-person consultancy that runs coding agents overnight against client repos. A typical job is a long terminal session: upgrade a build, chase a failing test suite, patch it. The engineer who owns the harness watches one number, tokens per task, because that is what shows up on the invoice. So she tightens compaction. It triggers earlier, removes more history and summarizes harder. Token counts drop, and she counts it as a win.
Then the overnight runs start finishing later. A few tasks that used to pass now fail. Nobody connects either change to the compaction tweak, because the dashboard only plots tokens.
A new arXiv paper, Beyond Token Savings: A Systematic Study of Context Compression in LLM Agents (submitted 2026-09-26), puts numbers on that blind spot. Across nearly 35,000 agent runs, the authors report that "fewer tokens need not mean faster or cheaper execution." On Terminal-Bench with Qwen, policies using roughly one-third as many tokens can take 20–80% longer than the uncompressed agent. This is a measurement study, not a product. What you take from it is a different metric to track.
What it is
The paper splits a compression policy into three decisions that existing harnesses usually bundle together: how to compress, when to trigger it and how much to remove. It then varies each one separately across three open-weight models on SWE-bench Verified and Terminal-Bench 1.0. For each run it measures task success, token use, end-to-end latency and estimated cost (abstract).
Here is how the reported findings map to the pain in the lede:
- Token count is the wrong proxy for speed. This is the Qwen/Terminal-Bench result above. A policy that looks better on a token dashboard can be slower on the clock.
- Aggregate pass rates hide churn. Policies with similar overall success can solve different tasks. A tweak that keeps your pass rate flat can still break the specific jobs you care about.
- Policies don't transfer across models. The same policy can perform quite differently from one model to the next. The authors conclude that compression should be judged by its effects on execution and tuned to the task, model and workload.
The full HTML text groups mechanisms into two kinds. One kind discards older interactions. The other summarizes them with extra LLM calls, which the authors note "can themselves add token and latency overheads." The paper also cites a trace of 13 million GitHub Copilot sessions from separate prior work (Liu et al., 2026). In that trace, sessions that needed compaction accounted for 44.2% of tokens served, and the median compaction event removed 72.8% of the existing context. Those figures belong to the cited study, not to this paper's experiments.
The most detailed public summary so far is from @omarsar0, who attributes the work to UT Austin. He reports two comparisons:
- Step-triggered policies cut the most tokens per step but need 10–27% more model calls.
- Threshold-triggered policies cut tokens by 22–55%, with call counts close to full context.
He also says a policy that works well for Qwen drops Devstral to 38.7% and makes it slower. We could not confirm these per-policy figures in the fetched text, so treat them as his reading.
The knobs you actually have today, each described from its own source:
- Claude Code auto-compact. It clears older tool outputs first, then summarizes if it still needs room, at a window you can move (Taku). Trade-off: the trigger is token-based, and summarization loses specifics such as exact error messages and variable names (ClaudeFast).
- OpenCode. It hides messages non-destructively using timestamps and pairs that with a 5-heading LLM summary (justin3go). Trade-off: the hiding step resembles the paper's rule-based clearing, with no extra LLM call for that step (our analysis), but hidden content is still out of the model's view.
- Codex CLI. It writes a single handoff summary that replaces the history. This can run locally against any provider or remotely through an OpenAI endpoint (justin3go). Trade-off: the remote path is OpenAI-only.
- Hook-based re-injection. In Claude Code, SessionStart hooks matching
compactrun after compaction, and their output is added to the compacted context (Taku). Trade-off: you keep critical details outside the summary, but you have to build and maintain the hook.
Who it's for
Pick this up if any of these apply:
- You run long agent sessions where wall-clock time matters, such as CI jobs, overnight batches or billable client hours.
- You have changed compaction thresholds and judged the change by token count.
- You run open-weight models in your own harness, which is the setting the study tested.
Skip it if any of these apply:
- Your sessions are short and interactive and rarely hit compaction.
- You want a recommended setting to paste in. The paper's conclusion is that no single policy wins. You tune per model and workload.
Before and after
Before:
- Notice the agent bill or context warnings.
- Lower the compaction threshold or make it more aggressive.
- Check that tokens per task dropped.
- Ship the setting.
After (the paper's suggested approach, applied to your harness):
- Pick a small fixed set of real tasks from your own repos.
- Run them at your current setting and record tokens, wall-clock time, estimated cost and pass/fail per task.
- Change one decision at a time: trigger point, amount removed or mechanism.
- Compare per-task outcomes, not just the aggregate pass rate, because similar totals can hide different solved sets.
- Repeat when you switch models. The paper says results don't transfer reliably across models.
Try it
No code or data release was found, so you cannot rerun the paper's setup from the sources. The smallest real step is to instrument your own agent.
In Claude Code, according to Taku:
- See where tokens go.
/contextshows a breakdown of what is using the window. - See your current window. Running
/autocompactwith no value shows it. This needs v2.1.221 or later. - Change the window.
/autocompact 500ksets it for this session and later ones, and--autocompactoverrides it for a single run. - Watch for the environment-variable trap.
CLAUDE_CODE_AUTO_COMPACT_WINDOWtakes only a plain integer. Writing500kreads as 500 and clamps to the 100K minimum, so you can end up compacting constantly without realizing it. - Turn auto-compact off to choose the moment yourself. Use
DISABLE_AUTO_COMPACT=1or the setting in/config.
Run your fixed task set at two settings and time each run. The sources give no cost figure beyond your own API spend.
Where it breaks
- The evidence is thin. This is one paper with no independent replication. The only outside commentary we found is the @omarsar0 post.
- The models tested may not be yours. The abstract names only Qwen among the three open-weight models (the post also mentions Devstral). Whether results carry over to the hosted models you use is open, and the paper itself warns that policies behave differently across models.
- Benchmarks are not your repo. Results come from SWE-bench Verified and Terminal-Bench 1.0.
- The cause of the slowdown is unconfirmed. We could not verify whether the extra time comes from more steps, re-reading files or the summarization calls themselves. The call-count figures in the post hint at extra calls but are not confirmed here. Per-benchmark, per-model winners need a full read of the paper.
- Compaction itself can be slow. In one GitHub report, a recovery
/compactsent 632,140 input tokens and took about 13 minutes. That setup was Claude Code routed through a third-party gateway to a non-Anthropic model, so it is a single anecdote, not a benchmark. - The documentation drifts. ClaudeFast says raising
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEgives more usable context. Taku says values above the default are ignored. ClaudeFast also notes that a buffer change was not announced in the official changelog. Verify behavior on your own build before trusting either source.
Sources
- Beyond Token Savings: A Systematic Study of Context Compression in LLM Agents · arXiv.org
- Beyond Token Savings: A Systematic Study of Context Compression in LLM Agents · arxiv.org
- [Provider compatibility] Claude Code /compact gets stuck on 502 retries with native GPT-6.1 Sol · Issue #6504 · lidge-jun/opencodex · GitHub
- Claude Code Context Buffer: The 33K-45K Token Problem · Claude Fast
- Shedding Heavy Memories: Context Compaction in Codex, Claude Code, and OpenCode · justin3go.com
- Claude Code Auto-Compact: When It Runs, What Stays · Taku
- @omarsar0: Great overview of context compression in LLM Agents · @omarsar0