Skip to content

ContextSniper: AntTrail's Token-Efficient Code Memory for Repository-Level Program Repair

🕒 Published (v1): 2026-07-02 09:15 UTC · Source: Arxiv · link

Why this paper was selected

Token-efficient context memory for repo-level agent repair; practical harness insight

Ask a follow-up

Open an assistant pre-loaded with this paper's context.

💬 Ask ChatGPT✦ Ask Claude

TL;DR

ContextSniper is a context-access middleware inserted between a host coding agent and a repository that replaces raw file reads and shell outputs with compact, task-relevant evidence packets. On SWE-bench Lite it reduces total token use by 38.9–51.5% and logged/estimated cost by 27.3–36.4% across two host agents, at a cost of only 2 percentage points in submitted-resolution rate.

Problem

Repository-level LLM repair agents accumulate context through whole-file reads, broad grep/search commands, and verbose terminal outputs, mixing useful repair signals with irrelevant code, repeated stack traces, and stale exploration history. This "read–try–fail–reread" loop raises inference cost, degrades localization quality (lost-in-the-middle effect), and grows the prompt without proportionally increasing useful evidence. Generic truncation or summarization removes provenance and line numbers needed for editing; the gap is a controlled, source-grounded, runtime-aware context-selection layer.

Method

ContextSniper inserts a code memory engine between the host agent and the repository without modifying the agent's reasoning, editing, or validation loop.

Memory hierarchy. Two memory families—code memory and action memory—are stored externally in an AGFS (Agent File System)-backed store, each indexed at three views: - \(L_0\): compact abstract (returned as the sniped view for long reads/shell output). - \(L_1\): structured routing metadata (paths, line ranges, ctags-style symbols, BM25 documents, graph relations, tool names, command status). - \(L_2\): recoverable full content (AST-chunked source with path/line headers for Python; overlapping windows for other file types; original unfiltered output for action memory).

Adaptive top-\(k\) hybrid retrieval. Given query \(q\), an intent is inferred from action memory; candidate routes are planned; per route, \(L_1\) metadata is scored via weighted reciprocal rank fusion (RRF) combining semantic embedding similarity, BM25 lexical scoring, ctags-style symbolic metadata, and graph relations; ripgrep serves as fallback when the index misses a term. The ceiling \(k^*\) is constrained by a token budget \(B\).

Intention-aware context gate. Long file reads and command outputs pass through a gate that compares the content against the inferred repair intent; low-value regions are sniped (removed) and the sniped \(L_0\) view is returned to the agent; the original is preserved in \(L_2\) action memory for recoverable inspection.

Two-phase memory–repository synchronization. (1) Runtime hooks execute after each agent action (search, read, edit, command) to record touched paths, modified files, and updated regions, dispatching immediate \(L_2\) refreshes for edited files. (2) At conversation/task boundaries, ContextSniper reconciles the index with working-tree diffs to invalidate stale entries.

Key Contributions

  • ContextSniper: a host-agent-agnostic code memory engine that gates raw repository and runtime tool outputs into compact repair evidence without replacing the agent's outer workflow.
  • Two-family (code + action) \(L_0/L_1/L_2\) memory hierarchy backed by AGFS, separating compact recall, structured routing, and recoverable full content.
  • Adaptive top-\(k\) hybrid retrieval via weighted RRF over semantic, BM25, symbolic (ctags), and graph signals with ripgrep fallback.
  • Intention-aware context gate that snipes noisy tool output while preserving source provenance and editability.
  • Two-phase memory–repository synchronization (runtime hooks + boundary reconciliation) to keep retrieved context aligned with a mutating working tree.
  • Evaluation on SWE-bench Lite against two host agents (Claude Code and OpenClaw) measuring token use, cost, turns, tool behavior, and repair outcomes.

Results

  • OpenClaw: total token use \(-51.5\%\) (1.36M → 0.66M tokens/task); logged cost \(-36.4\%\); submitted-resolution rate \(26.0\% \to 24.0\%\) (\(-2\) pp).
  • Claude Code: total token use \(-38.9\%\) (1.45M → 0.79M tokens/task); estimated cost \(-27.3\%\); submitted-resolution rate \(32.0\% \to 30.0\%\) (\(-2\) pp).
  • Token savings are larger for OpenClaw, consistent with that agent performing more redundant exploration.

Limitations

  • Resolution rate decreases by 2 pp for both host agents; the cases where the sniper removes evidence needed for a correct patch are not analyzed in detail.
  • Evaluation is restricted to SWE-bench Lite (Python repositories only, 300 tasks); generalization to other languages or benchmarks is not demonstrated.
  • Only two host agents tested; behavior may differ substantially for agents with different exploration strategies.
  • The paper text is truncated mid-algorithm; full details of the SearchCode procedure and budget-to-\(k\) mapping are not provided.
  • No ablations are reported for individual components (retrieval vs. gating vs. synchronization), making it unclear which mechanism drives most savings.

Relevance to Agentic AI / LLM Agents

ContextSniper directly addresses a central scalability bottleneck in long-horizon agentic loops: uncontrolled context growth during multi-step tool use. Its middleware architecture—sitting between the host agent and the environment rather than modifying the agent's reasoning—is a broadly applicable pattern for any agent that calls read/search/shell tools over large corpora. The two-family \(L_0/L_1/L_2\) memory hierarchy with intent-conditioned gating offers a concrete design for task-time agentic memory, complementing the growing literature on cross-task experience memory (SWE-Exp, ExpeRepair). The 38–51% token reduction at only \(-2\) pp resolution cost demonstrates that context budgeting at the tool-output level is a high-leverage lever for coding agents operating on real repositories.