Plan-guided history pruning for long-horizon coding agents
October 10, 2026
Coding agents now run for hundreds of steps and use far more tokens than a single model call (Bai et al., 2026). Every file read, search and test log stays in the context, so each new call re-reads all of it, and longer context hurts performance on its own (Du et al., 2025). I propose plan-guided history pruning, a training-free, agent-driven context management method for long-horizon agents. At each plan-step boundary, the agent self-prunes stale tool observations from its own trajectory while keeping its action history intact, with no auxiliary summarizer or judge model. The result is a compact working context and fewer input tokens at the same resolve rate.
This is one SWE-bench Verified task that both versions solved. With full history, the context only grows: by the last step the model is reading about 45k tokens on every call. With pruning, each finished plan step is followed by a drop. The first cleanup removed 12 outputs (about 4,900 tokens) and the second removed 13 more (about 3,600). The pruned run also finished in fewer steps, 77 instead of 87, and read 27% fewer input tokens over the whole task, counting the cleanup calls.
Methodology
Plan checkpoints
The agent keeps a short plan with a plan tool, planctl, with one step active at a time.
When it marks a step completed, the harness pauses it for one cleanup turn.
Pruning
In that turn the agent calls a single tool, prune_observations, on the outputs it no
longer needs. Each one is replaced with [Earlier command output omitted.], while the
commands stay, so the agent still knows what it ran. The same model decides, with no second judge.
The cleanup turn is then erased and the agent continues with a smaller context.
Cleanup prompt
You have completed part of your plan. Pause coding for this response and review what you have worked on. Decide which command outputs you no longer need for the remaining work and the overall task. … There is no required amount to delete.
Setup
- Benchmark
- SWE-bench Verified, graded with the official SWE-bench Docker harness.
- Model
- Qwen3.5-27B with thinking, served with vLLM on Texas A&M's Grace cluster.
- Harness
- mini-SWE-agent, extended with the plan tool and the pruning hook.
- Baseline
- The same agent and plan, keeping its full history.
- Runs
- A paired batch of 25 issues, with both versions run on the same issues.
Results
I ran both versions on the same 25 SWE-bench Verified issues, and they solved exactly the same 15.
Each dot is one of the 25 tasks, placed at the largest context the model had to read during that task. The median task peaked at 28.5k tokens with full history and 23.8k with pruning, 17% lower, and 17 of the 25 tasks peaked lower. A lower peak means the same agent fits in a smaller context window. The two pruned dots far to the right are tasks neither version solved, where the pruned agent ran more than twice as many steps.
| Version | Input tokens | Total |
|---|---|---|
| Full history | 12.1M | |
| With pruning | 8.6M |
Each cleanup turn is an extra model call that reads the full context, so I count those tokens too. On the 15 tasks both versions solved, full history read 12.1M input tokens. With pruning, the coding steps read 8.3M and the cleanup calls added 0.35M, about 3% of the full-history total, for 8.6M overall: 29% fewer input tokens with the same tasks solved.
Next
I'm scaling the experiment up to the full 500-issue SWE-bench Verified set, with repeated runs across seeds, more model sizes and model families, and longer-horizon benchmarks where the context grows even faster. I'm also comparing against observation masking and LLM summarization at the same token budget (Lindenbauer et al., 2025).
Thanks
I ran these experiments on Texas A&M's Grace cluster. Thank you to Maria Teleki and to my advisor, Prof. James Caverlee, for the guidance and feedback along the way.