Share your thoughts, 1 month free Claude Pro on usSee more
WorkDL logo mark

SWE-Pruner: Self-Adaptive Context Pruning for Coding Agents

About

LLM agents have demonstrated remarkable capabilities in software development, but their performance is hampered by long interaction contexts, which incur high API costs and latency. While various context compression approaches such as LongLLMLingua have emerged to tackle this challenge, they typically rely on fixed metrics such as PPL, ignoring the task-specific nature of code understanding. As a result, they frequently disrupt syntactic and logical structure and fail to retain critical implementation details. In this paper, we propose SWE-Pruner, a self-adaptive context pruning framework tailored for coding agents. Drawing inspiration from how human programmers "selectively skim" source code during development and debugging, SWE-Pruner performs task-aware adaptive pruning for long contexts. Given the current task, the agent formulates an explicit goal (e.g., "focus on error handling") as a hint to guide the pruning targets. A lightweight neural skimmer (0.6B parameters) is trained to dynamically select relevant lines from the surrounding context given the goal. Evaluations across four benchmarks and multiple models validate SWE-Pruner's effectiveness in various scenarios, achieving 23-54% token reduction on agent tasks like SWE-Bench Verified while even improving success rates, and up to 14.84x compression on single-turn tasks like LongCodeQA with minimal performance impact.

Yuhang Wang, Yuling Shi, Mo Yang, Rongrui Zhang, Shilin He, Heng Lian, Yuting Chen, Siyu Ye, Kai Cai, Xiaodong Gu• 2026

Related benchmarks

TaskDatasetResultRank
Long Code QALongCodeQA 4× Constraint
Accuracy59.46
8
Long Code QALongCodeQA 8× Constraint
Accuracy58.71
8
Long Code CompletionLCC 8× Constraint
Edit Similarity (ES)57.58
8
Long Code CompletionLCC 4× Constraint
Edit Similarity (ES)58.63
8
Software Engineering Question AnsweringSWE-QA Reflex
Overall Score8.14
6
Software Engineering Question AnsweringSWE-QA Streamlink
Score8.6
6
Software Engineering Question AnsweringSWE-QA Conan
Score8.61
6
Showing 7 of 7 rows

Other info

GitHub

Follow for update