Navigation is the real cost of AI coding agents

Fredrik Claesson is a Senior Software Engineer on the Payments team at Mews, building reliable, high-scale fintech systems for hospitality. Based in Sweden, he focuses on payment processing, observability, and performance in the core monolith, with a strong interest in developer experience and AI-assisted tooling. He also builds tools like ContextKing to help engineers better understand and navigate complex codebases.

Twenty minutes into a token-burning grep across 20,000 files, my AI agent still hadn’t found where retry handling lives.

I work on the Fintech platform at Mews, where our core product is a C# monolith that size, and if you have ever used AI coding agents inside something that big you know the wall I hit. The tools are genuinely impressive once they know where to look. The problem is getting them there.

On a small project they feel almost magical. On a big one, they start behaving like someone who just joined the team on day one, doing repo-wide searches, reading the wrong files, and burning through tokens before they arrive at anything useful.
So I built a tool to fix that. It is called Context King.

The problem nobody really talks about

Most of the conversation around AI coding tools and token usage is about compacting what the agent reads. Tighter prompts, summarised context, leaner encoding. All of that is useful, but it sidesteps the bigger question for anyone working in a large codebase.

The cost is not just in what the agent reads once it gets to the right place. The cost is in the navigation itself. In how many wrong files it touches on the way there.
Think of it like walking into a huge library to find one specific paragraph. If you know the section, the shelf, and the book, you are in and out in a minute. If you do not, you end up pulling down thirty books, flipping pages, putting them back, and slowly closing in on the one you actually need. Every book you open is a cost, even if you only read the cover.

That is exactly what an unguided repo-wide grep looks like on a 20,000-file codebase. By the time the agent finds the right method, the context window is full of noise and the real question has been pushed out the back.

The idea

I wanted the agent to walk through the codebase the way a human does when they actually know it. Not “search everywhere for the word reservation”. More like “okay, reservations probably live under Inventory somewhere, let me look there first, then drill down.”
That is really a four-step movement:

  1. Figure out where the thing probably lives. Narrow down to a set of folders, semantically ranked, not just plain match.
  2. Look at what is in those folders without opening the files. Just the shape of it, via signature extractions using AST (Abstract Syntax Tree, a hierarchical node structure representing the code, extracted by SDK or parsers).
  3. Pick the one method that actually matters and read only that.
  4. Edit.

Context King installs four small commands, an embedding model, and a CLI into your AI CLI, one for each step. The embedding model is bundled and runs locally, and the index is a local file on disk, so nothing about your code ever leaves the machine.

The agent never has to open a file blindly, and it never has to scan the whole repo.

What the four steps actually look like

Take the retry-handling question from the opening. Here is what the agent sees at each step when it runs against MassTransit, an open-source C# codebase of about 5,500 files.

Step 1, find the scope. The agent runs ck find-scope –query “retry failed message policy backoff incremental” and gets back a ranked list of folders:

0.85 src/MassTransit/RetryPolicies 0.75 src/MassTransit/Configuration/Configuration/Retry 0.71 src/MassTransit/SagaStateMachine/Configuration 0.69 src/MassTransit/Configuration/Configuration/Redelivery 0.68 src/MassTransit/RetryPolicies/ExceptionFilters ...

No files opened yet. The top two hits are obviously the right places to look.

Step 2, inspect the shape. The agent runs ck signatures on those folders and gets a flat list of every method and property signature underneath, with file paths and line numbers, but no method bodies. It can see:

IncrementalRetryPolicy, ExponentialRetryPolicy, IntervalRetryPolicy, GetRetryInterval,
 CalculateIntervals, CanRetry, and so on.

Still no file reads by the Agent, method signatures extracted by AST.

Step 3, read the one method that matters. Now the agent picks specific methods and pulls just those, one at a time: 

ck-get-method-source ExponentialRetryPolicy.cs GetRetryInterval.

It returns the body of that single method with its exact line range. No file is ever opened whole.

Step 4, answer or edit. With the relevant method bodies in context, the agent answers the original question or makes the edit. For the retry question, that was enough to describe all four policy types, the exception filters, and how redelivery differs, without having read a single full file.

The whole trace is three targeted shell commands and a handful of method lookups. The agent never loaded a full file, never ran a repo-wide grep, and never pulled anything from a test project or a generated file.

Why folder-level indexing
Most existing tools use file-level indexing,  On a 20,000-file C# repo the initial index took several minutes to build, and incremental updates fell apart the moment I switched branches or worked across git worktrees. Keeping deltas in sync was both messy and expensive.

Folder-level indexing has an order of magnitude fewer units to track, builds in seconds, and barely notices a branch switch.

Do you work with large codebases and AI coding agents?

This might be your thing.

See open roles

It also happens to fit how code is usually organised. A folder represents one bounded concept. Meaning clusters at the folder boundary, not the file boundary.

This assumes your folder structure reflects what the code does. In a polyglot monorepo, or a codebase where one giant folder holds a dozen unrelated concepts, the ranking degrades.

Does it actually work?
The honest answer is that I was not sure until I ran the numbers. So I ran the same prompt against the same codebase twice, once with Context King active and once without, and counted the tokens.

Prompt “Describe retry handling” on MassTransit (open source project) (~5,500 files)

  With Context King Without Context King
.cs files read in full 1 43
Repo-wide Glob/Grep/Bash searches 0 7
ck find-scope calls 1
ck signatures calls 2
ck get-method-source calls 3
Total tool calls 11 54
New tokens processed 21,283 97,937
Ratio 1x 4.6x more

Prompt “find the Stripe reconciliation logic” on a proprietary codebase (~20,000 files)

  With Context King Without Context King
.cs files read in full 0 9
Repo-wide Glob/Grep searches 0 2
ck find-scope calls 2
ck signatures calls 2
Total tool calls 5 20
New tokens processed 22,280 234,842
Ratio 1x 10.5x more

The bigger the repo, the bigger the win

That second number is the one worth sitting with. It is not that the tool helps more on a bigger codebase by a little, it helps more by a lot.

Unguided search does not scale linearly with repo size. It scales worse than linearly, because every wrong hit costs a file read and every file read eats context that then has to be recovered. The larger the project, the more compounding the waste. Which means the value of pointing the agent at the right place on the first try grows as your codebase grows. That is the part I did not fully appreciate until I had the numbers in front of me.

These savings are concentrated in the investigation phase. Once the agent has the right file open and is writing code, Context King is no longer on the hot path. So on an end-to-end task, the overall saving is closer to 30 percent. Still worth having, but a very different number from the headline 10x.

What changed for me

The thing I actually notice day to day is that investigation questions no longer derail my morning.
“Where do we handle Stripe reconciliation failures?” used to be a fifteen-minute detour through wrong files, with me half-watching the agent crawl through the repo and half-losing the thread of what I was actually trying to do. Now the session stays on the task I started with.

Context King is a navigation layer, not a code-writing tool, and you will not feel the difference on a small repo. Plain grep is fine under a few thousand files. But if you work in something large and you use AI coding agents, it is worth twenty minutes of your afternoon to try it.

Whats next?

Now that the code navigation is solved it is time to address the goldfish nature of coding, one central memory.md/agents.md does not scale. Checkout the repo for how things evolve.

Get started

I would love to hear what works, what does not, and what you would want it to do next.

Fredrik Claesson is a Senior Software Engineer on the Payments team at Mews, building reliable, high-scale fintech systems for hospitality. Based in Sweden, he focuses on payment processing, observability, and performance in the core monolith, with a strong interest in developer experience and AI-assisted tooling. He also builds tools like ContextKing to help engineers better understand and navigate complex codebases.
Share:

More About &