Developer tools · Research feature

Name-Only Directory Routing Improves Code File Discovery in One-Shot Search

A study finds directory name routing recovers more annotated code files than basic lexical searches in one-shot code retrieval tasks.

Adapted from research by Manoj Bajaj.

arXiv preprint revision · 2026-09-28 · Attribution & reuse
In this article
Editorial illustration of stacked plates.

Editor’s introduction

The study evaluates name-only directory routing against fixed lexical queries and FTS5 in 82 software issues across 11 repositories. Directory routing recovered 0.465 of gold files among eight candidates, outperforming FTS5 (0.352) and a fixed full-issue query (0.245). Under shared context limits, it also retrieved more annotated lines than FTS5. Routing used significantly fewer model calls than an exploratory flat path method, which achieved higher recall but at greater computational cost. The researchers note that while routing adds relevant candidates to one-shot searches, the study does not determine whether directory hierarchy or prompt structure drives the improvement. The fusion of routing and FTS5 improved file recall but did not consistently outperform routing alone, and in some cases displaced files from fixed candidate lists. The evidence supports routing as a complementary method, but does not isolate causal factors or demonstrate impact on actual issue resolution.

Introduction

A coding agent can call rg repeatedly, but the first query is often a behavioral description rather than an identifier. Search terms may match documentation, changelogs, tests, and unrelated implementation. The repository’s directory structure supplies an alternate route to candidate files: at each directory, a model selects plausible children and may retain several branches. This paper asks whether that route discovers additional annotated source evidence at a useful cost, not whether it makes text search obsolete. Our contribution is a controlled, reproducible evaluation of when a language-model-guided walk of repository names adds files omitted by fixed lexical rankings, and whether those files survive an equal context-selection budget. We do not introduce hierarchical code search.

The claim has two stages. First, a file-discovery method must nominate gold files within a fixed candidate limit. Second, those candidates must yield the required source lines within the coding agent’s context budget. A method can win the first stage and lose the second through ordering, overly narrow windows, or noisy context. We therefore report both stages rather than using span overlap or downstream answer scores as a proxy for file discovery.

Our pilot motivates the question but does not answer it generally. On 24 previously inspected issues from Django and Svelte, name-only tree routing found a larger fraction of gold files at eight candidates than one fixed full-issue rg literal ranking (0.476 versus 0.219). A stronger FTS5 control reached 0.295; tree and FTS5 both delivered complete gold-line contexts for only 4/24 questions at 16K tokens. These observations demand a new-repository held-out comparison with multiple lexical controls and a shared final-context budget. We make no inference from a selected three-file pilot example to general performance.

Task and data

The unit is an issue statement paired with a repository at its pre-fix base commit. The retriever receives the issue text and source tree only: never annotated paths, gold line ranges, a solution patch, or post-fix code. ContextBench supplies repository issues and annotated source regions. We pinned its revision and Parquet checksum in a evals/fixtures/queries/contextbench_paper.json. The 24 Django/Svelte pilot cases are excluded. The independent manifest contains 87 issues at 87 commits from 11 other repositories in Python, TypeScript, JavaScript, Go, C, and Rust. Repositories were selected by eligible-case count within language strata; at most eight issues per repository were selected by a hash ordering of instance ID. This tests transfer across repositories but is not a random sample of software projects. Source availability and common-corpus eligibility are audited before scoring, with exclusions logged and never replaced. The exact selection and audit rules are in the accompanying paper/study-amendment-001.md. The source audit retained 82/87 cases. All five exclusions had gold paths outside the common searchable-file policy, including real source under directories named build. They remain in the exclusion ledger. Among the retained cases, 55 had every annotated span text align with the base-commit source after whitespace normalization or exact-text containment. File discovery uses all 82; line-level conclusions are shown both for all 82 and the 55-case aligned-text sensitivity subset. The initial 171-case tree pass was stopped at the author’s request after the reduced subset had already completed. Some interim tree outcomes were visible before the budget amendment, but the first-eight-per-repository rule depends only on the original hash-ordered manifest, not those outcomes. The study is not externally preregistered or fully blinded.

Retrieval arms

The tree arm walks the existing folder hierarchy. At each visited directory, a categorical classifier receives the first 500 issue characters and a menu of immediate child directory and file names. Each directory option also includes up to 12 descendant names from at most three levels below it. The classifier assigns probabilities and may keep multiple plausible branches. The evaluated implementation uses typesafe/jev-1.13.0, no generated directory summaries, minimum and relative branch-probability thresholds of 0.01, a 32-call cap, and a 180-second per-issue time cap. It outputs at most 16 ranked file paths. This is a file-discovery method, not a complete coding agent.

Here “classifier” means the TypeSafe System One choice endpoint, not a classifier trained for this study. The request state is User question: followed by the first 500 issue characters. Each criterion is an immediate child path and name-only summary; directory criteria additionally list up to 12 descendant names. A none_of_these criterion is added. The instruction is: “Choose the best route toward answer evidence. Directory options summarize descendants, so select a directory when a descendant could answer. Choose none only when the question is unrelated to every option.” The provider returns a probability for every criterion. The JSON request has questions.route.type=choice, instructions, and criteria={option_i: text,…, none_of_these: text}; the adapter reads answers.route.probabilities and rejects missing or out-of-range values. We do not renormalize probabilities across menus. Menus are split at 254 options or 48,000 request characters; each option is limited to 800 characters. The none_of_these probability is not a traversable child; the best-child threshold excludes it. Children with probability at least the larger of 0.01 and 0.01 times the best child probability are retained. A stack visits higher-scoring children first; tied children follow reverse input order. Path rank is traversal order; branch probabilities are not multiplied into a global file score. Single-child directories need no model call. The API request supplies no temperature setting. HTTP 429/529 responses are retried up to three times; other errors fail the issue. The archived model identifier is jev-1.13.0; provider-side weights and sampling behavior are not under our control.

Lexical arms search the same eligible UTF-8 files. The primary comparator is in-memory SQLite FTS5 ranking from the first 500 issue characters, chosen because it had the highest lexical recall@8 on the pilot. It indexes paths and file content, searches an OR of unique non-stopword tokens, and ranks with FTS5’s BM25 function using path/content weights 2/1. An actual full-issue ripgrep replay searches case-insensitive literal terms over the same files; its fixed file ranker weights term rarity and path matches. It is one nonadaptive query, not a proxy for an agent that can run successive searches or generate better keywords. The hybrid applies reciprocal-rank fusion (rank constant 60) to tree and FTS5 top-16 lists and truncates back to eight or sixteen files; it receives no larger candidate allowance. We do not compare its one-shot file ranking against Pi’s multi-turn grep/read loop using span recall; that would measure different systems and conflate file discovery with section selection.

Outcomes and statistics

For issue q, let G be its annotated gold-file set and R(k) the first k returned files. File recall is |G intersect R(k)| / |G|; the main aggregate is the unweighted mean over issues. We also count fully recovered gold-file sets, gold files found by tree but absent from the same-size FTS5 prefix, and issues with at least one such file. Since 16 of 82 audited issues have more than eight gold files, complete recovery at eight candidates is impossible for them; the ceiling is reported. File precision is secondary because the intended use tolerates some extra files if required evidence is present.

Candidate files are not equivalent to delivered context. Every ranking uses the same line selector: at most four lexical anchors per file, a 200-line radius around each, and merged overlapping windows. The windows are packed under a 16K-token budget with the same tokenizer and order. The selector tokenizes the full issue and every retrieved file, removes stopwords and tokens of at most two characters, and scores each source line by its count of distinct overlapping query terms. It takes the four highest-scoring lines per file (earlier line wins ties), expands each by 200 lines in both directions, and merges touching ranges. When a file has no matching line, it offers the whole file. Ranges are packed in file-rank order, with higher-scoring ranges first within a file; an over-budget range is skipped and packing continues. The tokenizer is cl100k_base, and line numbers and paths count toward the budget. The selector scans full retrieved files, but receives only the issue text and those files. Gold paths, annotated line text/ranges, patches, and post-fix code are never passed to retrieval or selection; they enter only the subsequent scorer. The same selector is rerun for every arm without arm-specific settings.

We score annotated-line recall and complete line coverage after packing. Because text annotations can differ from base-commit source, we show line outcomes separately on the pre-retrieval aligned-text subset. Paired differences use 10,000 repository-cluster bootstrap resamples (seed zero): sample the 11 repositories with replacement and carry all their paired issues into each sample. Per-repository results expose concentrated gains. Setup, query, model-call, token, cost, and wall-time measurements are reported separately. Neither file nor line recall is issue-resolution success. The reduced study does not repeat the tree run or measure the combined hybrid pipeline wall time; it reports each measured arm’s operations and does not claim a fused end-to-end speedup. Prespecified descriptive subgroups mark whether the issue explicitly mentions an annotated full path or basename and whether its gold files span more than one directory. These labels use the issue and gold metadata, never retrieval outputs.

Equal-budget retrieval

At eight candidates, tree had higher file recall than FTS5 on 33 issues, lower on 15, and equal on 34. Its 61 gold-file occurrences absent from FTS5’s top eight appeared in 40 issues; FTS5 had 34 gold-file occurrences absent from tree’s top eight. Against fixed rg, tree had 82 such occurrences in 49 issues and rg had 29 absent from tree. A further descriptive overlap count found 57 tree hits across 37 issues absent from both lexical top-eight lists. These are issue–file occurrences, not distinct files across the corpus. Tree alone recovered eight more complete gold-file sets than FTS5 at top eight. The fusion’s higher mean recall did not translate to more complete sets than tree: it recovered 23 versus 25. The primary macro average weights issues equally. A secondary micro average weights each annotated gold-file occurrence equally: at eight candidates, tree found 108/391 (0.276) and FTS5 found 81/391 (0.207); fusion found 120/391 (0.307). At sixteen, tree found 150/391 (0.384) and fusion 151/391 (0.386). Thus the small tree–fusion ordering at sixteen changes with the aggregation unit, while tree exceeds FTS5 under both.

Fusion therefore improves this FTS5 ranking, but is not a demonstrated improvement over tree alone. At top eight it raises file recall in 20 issues, lowers it in 13, and leaves it unchanged in 49 relative to tree. At top sixteen, fusion lowers mean candidate recall slightly. Rank fusion can displace a tree-selected gold file at a fixed limit; combining candidate lists is not free. The aligned-text line difference for fusion versus tree is +0.056 [0.002, 0.126]; this pre-retrieval aligned subset is smaller and easier on file recall, so it does not establish a robust general gain. On all 82 issues the annotation-sensitive difference is +0.043, interval -0.006 to +0.101.

Delivered context and annotation sensitivity

The selector packed, on average, 12.7K tokens for tree@8, 14.2K for FTS5@8, 14.9K for rg@8, and 13.8K for fusion@8, all within the same 16K cap. Greater tree line recall was not explained by a larger context allowance. Complete annotated-line coverage was nevertheless uncommon: 14/82 issues for tree, 8/82 for FTS5, 5/82 for rg, and 15/82 for fusion. File discovery remains only the first step toward sufficient coding context.

For the 55 issues whose every annotated text span aligns to the pinned pre-fix source, line recall@8 was 0.443 for tree, 0.246 for FTS5, 0.116 for rg, and 0.499 for fusion. The paired tree–FTS5 difference was +0.196 [0.125, 0.275], and fusion–tree was +0.056 [0.002, 0.126]. These are the most trustworthy exact-line comparisons. The predeclared all-82 line analysis remains in the archived artifact, but is annotation-sensitive: 940/991 spans aligned with the pinned source and 51 spans across 27 issues did not. A post-study mechanical audit found the annotated text elsewhere in the same file for 20 mismatched spans and did not find it in that file for 31; these labels do not establish why the dataset and source differ. The mismatch is fixed before retrieval and cannot vary by retrieval arm. Mismatched-case counts range from zero in GitHub CLI, Transformers, and PonyC to six of eight in Material UI; every repository’s count and case IDs are archived with the audit. We do not infer an exact-line improvement on the 27 cases from the numeric range overlap alone. The aligned subset is not a random sample of difficulty: tree file recall@8 was 0.531 there versus 0.331 on the 27 mismatched cases. We use it for annotation validity, not as a representative replacement for all 82 issues.

Illustrative gains and failures

In a GitHub CLI issue asking to hide the current branch in pr status —repo, the annotated file was pkg/cmd/pr/status/status.go. Tree routing followed the command hierarchy and ranked it eighth; neither FTS5 nor fixed rg included it in the first eight. Conversely, for a VS Code issue about command links rendered from Markdown, FTS5 ranked the annotated src/vs/base/browser/markdownRenderer.ts fifth, while tree routing followed workbench command files and missed it. Equal-k fusion also missed the renderer in its first eight. These examples were selected after aggregate analysis to show both a lexical-vocabulary failure and a routing/fusion failure; they are not independent evidence of average performance.

Hierarchy-guided retrieval is not new: PageIndex applies tree reasoning to documents. Code-localization work exploits structure in other ways. LocAgent uses a graph of code entities and dependencies for multi-hop localization; repository-aware file-path retrieval trains a model to predict paths from natural-language queries. These methods test different trade-offs from a folder walk. Blink already navigates codebase folders with Jev, so neither hierarchical code search nor Jev use is claimed as a first here.

Lexical search is a serious baseline, not a straw man. Better Call Grep studies grep-like retrieval for repository-level completion. Our narrower question is whether tree routing adds gold files to a fixed-budget lexical candidate list when issue wording and source vocabulary differ, and whether that addition survives context selection. A same-agent comparison is needed before claiming an adaptive coding workflow improves; offline list fusion alone cannot establish that. Nor do these fixed-query baselines exhaust the space of intent-aware lexical search or query reformulation.

Limitations and conclusion

On this cohort, name-only directory routing is a complementary source of file candidates for one-shot, issue-driven code retrieval. At equal candidate and context budgets, it found more annotated files and delivered lines than the selected lexical baselines while using much less model computation than the higher-recall exploratory flat path tournament. The procedures differ in prompt, menus, and calls, so the study does not isolate hierarchy as the cause of the quality difference. Equal-budget tree+FTS5 fusion improves over FTS5, but does not reliably improve over tree and can displace tree-selected gold files from a fixed shortlist.

The primary study tests an issue’s first fixed query, not an adaptive agent. A multi-turn agent can reformulate searches, inspect stack traces, and follow references. Therefore a tree-only file-recall advantage over one fixed rg ranking would establish complementary candidate generation, not superiority over grep as a tool or over Pi as an agent. Fusion improves an agent only if the added files survive its context selection and are actually used; we measure delivered lines but not issue resolution.

The corpus policy excludes hidden files and directories commonly used for generated outputs. Five selected cases lost gold files to that rule, including real source under directories named build; those exclusions are reported, not silently swapped. Folder names can also be misleading, and the classifier may prune an essential branch. The pre-fix gold text alignment check found 27 audited cases with at least one mismatch; line-level results on those cases are less secure than file-level results. The 11-repository convenience cohort and one provider/model may not generalize to other repository layouts or query styles. The original larger tree run was shortened after interim outcomes were visible, although the reduced-case rule was independent of those outcomes; the resulting evidence is weaker than a fully blinded preregistered replication. The post-study flat Jev tournament used a different instruction and more calls than tree. A call- and prompt-matched comparison with repeated stochastic runs would be needed to estimate the hierarchy’s effect independently of compute allocation. A chat-model gate would test the role of the Choice endpoint. The scripted two-search rg control does not cover agent-led query revision; code-symbol indexes and downstream coding agents remain untested. Provider prices and latency can change, so the paper reports observed calls/tokens and setup costs alongside dollar estimates.