TL;DR
FastCode is a novel framework for repository-scale code reasoning that drastically cuts down LLM token costs while simultaneously improving accuracy. By decoupling codebase exploration from full-text content consumption through a "structural scouting" mechanism, it builds highly relevant context in a single optimized step instead of relying on expensive, iterative file-reading loops.
What Problem Does This Paper Address?
While Large Language Models (LLMs) excel at understanding isolated code snippets, scaling their reasoning to entire repositories (e.g., for complex debugging, refactoring, or codebase QA) remains a massive bottleneck.
Standard Retrieval-Augmented Generation (RAG) pipelines typically flatten code into text chunks, which destroys critical structural relationships like imports, class inheritance, and function call chains. Conversely, feeding an entire codebase into a long-context window is prohibitively expensive and floods the model with distracting noise.
Existing agentic approaches try to solve this by iteratively searching and reading files via an "Observe-Think-Act" loop. However, this multi-turn process causes token consumption to explode quadratically as the agent re-ingests its accumulating context history at every single turn, often paying a high price only to find out a file was irrelevant.
Methods
FastCode introduces a scouting-first paradigm that allows an LLM to pinpoint exactly what it needs before reading full file contents. The framework consists of three synergistic components:
- Semantic-Structural Code Representation: Instead of raw text chunks, FastCode parses the repository into a hierarchical tree spanning four levels (File, Class, Function, and Documentation) containing lightweight metadata (signatures, docstrings, line ranges). It simultaneously builds a multi-layered directed graph capturing file dependencies ($G_{dep}$), class inheritance ($G_{inh}$), and function call flows ($G_{call}$).
- Codebase Context Navigation: To bridge the semantic gap between natural language queries and code, FastCode augments the user's prompt with intent-guided rewriting, keyword expansion, and LLM-generated pseudocode hints. The agent uses lightweight tools like Directory Traversal and Codebase Search to scout metadata and expand candidates via the relationship graph without reading full file bodies.
- Cost-Aware Context Management: FastCode treats context assembly as a state-aware optimization problem. It tracks query complexity, repository structural entropy, and current resource consumption to dynamically enforce a token/line budget. It monitors an Information Gain Rate (IGR) to evaluate the incremental value of expanding the context, allowing it to prune irrelevant paths and terminate the search efficiently.
Datasets
The authors evaluated FastCode across four rigorous repository-level benchmarks:
- SWE-QA: A repository-level question answering benchmark containing 576 human-validated QA pairs from 12 open-source Python repositories.
- LongCodeQA: A subset of LongCodeBench featuring multiple-choice questions derived from real GitHub issue discussions, spanning token lengths from 32K to 1M tokens.
- LOC-BENCH (SWE-Bench-Lite subset): A benchmark consisting of 274 issue-patch pairs designed to measure a model's ability to accurately localize faulty files and regions.
- GitTaskBench: An end-to-end benchmark containing 54 human-curated tasks that require setting up environments, navigating codebases, and producing runnable outputs.
Key Insights and Ideas
- Visibility Without Reading: You don't need to ingest full code bodies to know if a file is relevant. Lightweight metadata (signatures and docstrings) combined with a structural dependency graph provides more than enough signal for an LLM to navigate effectively.
- Neutralizing the "Context Tax": In traditional long-context models, costs scale quadratically with repository size. FastCode achieves near-constant costs regardless of input scale by selectively assembling context in a single final step.
- Empowering Small Models: High-precision context construction can compensate for lower parameter counts. FastCode enabled a lightweight 3B model (Ministral-3b) to achieve a score of 36.13 on SWE-QA, outperforming a much larger 30B model (Qwen3-Coder-30b) running in a standard direct setting (35.77).
Key Results
FastCode consistently demonstrated a decisive advantage in both accuracy and cost-efficiency across all benchmarks:
- Massive Cost Reductions: On LongCodeQA, while baseline costs grew quadratically to over $2.60 per query, FastCode maintained near-constant costs, resulting in a >90% cost reduction at 256K tokens alongside a 17.87% accuracy improvement.
- State-of-the-Art Localization: On LOC-BENCH, FastCode paired with Gemini-3-Flash established a new SOTA with an Acc@1 of 86.13%, outperforming the previous best method (LocAgent) by 8.39% while operating 18–22× cheaper than agentic frameworks like OpenHands.
- End-to-End Agentic Efficiency: On GitTaskBench, FastCode achieved a peak Task Pass Rate (TPR) of 57.41% using Claude 3.7. Its Gemini-3-Flash variant offered a practical sweet spot, outperforming strong baselines while being 15× to 2000× cheaper than OpenHands.
Limitations and Future Work
- Dynamic Typing Ambiguity: The paper notes that Python's dynamic typing introduces ambiguity when constructing function call graphs. While they mitigate this using scope-constrained type inference, highly dynamic languages remain a challenge.
- Static Analysis Reliance: The framework relies heavily on Abstract Syntax Tree (AST) parsing to build its initial structural map. Repositories that make heavy use of runtime metaprogramming or dynamic code generation may not be fully captured.
- Future Directions: Promising future work includes extending this structural scouting paradigm to multi-lingual repositories (where cross-language dependencies exist) and integrating it directly into interactive IDE loops for real-time developer assistance.
Summary updated