Protocol

Retrieve code before sending code

The cheapest token is the irrelevant file you never send.

When it fits

  • A coding assistant repeatedly receives large repository dumps or oversized file context to answer narrow questions.

When to avoid it

  • Repository structure matters. Retrieval that works on one codebase can miss generated code, dynamic links or cross-cutting configuration elsewhere.

Why it matters

Build a local or privacy-appropriate code retrieval layer that combines complementary search signals, rejects weak matches and supplies only likely relevant fragments. Measure recall on known tasks before relying on the savings; a tiny context that omits the dependency is not efficient.

Steps

  1. Create a benchmark of code questions with known relevant files or symbols.
  2. Combine lexical and semantic search when they cover different misses.
  3. Reject low-relevance candidates instead of filling the context quota.
  4. Measure retrieval recall, task success and total context cost together.

An example

For a failing API endpoint, retrieve the route, service and referenced model instead of uploading the whole repository tree to every coding turn.

Check your result

Known-task benchmarks show that the reduced context still retrieves the dependencies needed for correct answers.

Keep this limit in mind

  • Repository structure matters. Retrieval that works on one codebase can miss generated code, dynamic links or cross-cutting configuration elsewhere.

Connected ideas

Useful with
Treat context as a budget, not a transcript

Evidence and sources

Supports

A local code-retrieval layer can select relevant repository fragments before model inference instead of repeatedly sending broad code context.

Retrieval can miss dependencies or return plausible irrelevant code. The reported headline token reduction is case-specific and is not a universal expectation.

We Cut 94% of Our AI Coding Tokens With a Local Code Index. Here's the Architecture. · Architecture sections on local retrieval, complementary searches, relevance rejection and benchmark comparison

All sources (1)