Cut the cost of re-reading your code
Coding agents send your codebase to the model on every turn. Providers bill text they have already seen at a fraction of the normal price, so the longer the unchanged part stays at the front of each request, the smaller the bill.
krypton order checks your own history before it changes anything.How caching rewards order
Providers cache the longest identical prefix of a request. If a file near the start changes, everything after it has to be read again at full price. If only files near the end change, almost the whole request is reused.
So the best order puts the files that rarely change first and the ones that change often last.
Krypton's ordering
$ krypton order . --subdir src --ext .py,.ts --model gpt-4o --post
# the order to send the files in, or your own order when Krypton would not win
Krypton's ordering algorithm uses each file's change history. Build your prompt from the files in that order. The ordering is a hint from history, not a guarantee, and it never changes a score.
What we learned
- Order matters a lot on some repositories. Putting the files that rarely change first made the same prompts up to 35% cheaper in our tests.
- On others it does nothing or hurts. After a refactor, or when the team starts working on different files, the quiet files stop being quiet and an early change throws the cache away.
- The typical gain is a few points of reuse, not 35%. That is why
krypton orderreplays your own history first and leaves your order alone unless it would clearly win. - Cache breakpoints matter. With a single breakpoint at the very end of the prompt, no order helped.
The numbers behind each point, repository by repository, are in the case study.
When Krypton would lose, it does nothing
Reordering blindly is not safe: on some repositories a stable-first order loses to plain alphabetical order. krypton order is the safe form of the feature. Before a request it replays your repository's history, tries several orders (stable files first, big files that rarely change first, least recently changed first, alphabetical, reverse alphabetical), builds each from the commits before every past change only, and compares how much of the prompt each would have kept. It takes the order that kept the most, and reorders only when there is enough history, its average gain over your order is clear, and it was ahead in more changes than it was behind. The answer lists every order it tried. Otherwise the answer is keep: your request goes out exactly as you built it.
How to run it, and what the answer looks like, is on file ordering.
Try it on your own repository
The hosted demo reads a repository you choose and shows its real size in tokens and an estimate of what ordering and a refactor could save.