Why does my coding agent read whole files?

Updated

Short answer

Because its read tool returns files, not answers: to learn what a file contains, the agent opens all of it. On Hugging Face's 4,639-line trainer.py that read costs 57,058 tokens, and pixel list-signatures answers the same question in 1,649. Across 8 well-known files the agent reads 79.7 to 97.2% less, median 94.5%.

Where the tokens go

An agent learns a repository the way its tools let it: it searches for a name, gets a line back, then opens the file around that line to understand it. Its read tool has no notion of “the functions in this file” or “the class this method belongs to”, so the whole file enters the context, and it stays there for every later turn of the session.

On a small file that costs little. On the large files every real codebase has, a trainer, a router or a query builder of several thousand lines, one read fills a large part of the context before the agent has written anything.

What an index returns instead

pixel list-signatures answers “what does this file contain” from an index Pixel keeps in .pixel/: each module- and class-level definition with its line, and nothing else. The agent then reads the lines it needs with a targeted range. No second model reads the file in its place: the saving is the index’s own answer, counted with the same rule on both sides (UTF-8 bytes divided by four).

To check it on a file of yours, Measure it on your own code gives the command pair: the whole file against pixel list-signatures on it, in bash or zsh.

The figures

Full read of trainer.py57,058 tok
pixel list-signatures on it1,649 tok
Less read, 8 well-known files79.7 to 97.2%, median 94.5%
Pixel's own repository, single large file48,465 tok read in full, 2,172 tok through Pixel

Every figure above is on the benchmarks page, with its sample size and its method: Well-known files, Reading code.

Where Pixel does not win

The figure counts what reaches the agent's context, not your invoice. The files with the most signatures per line save the least, the low end of the range: VS Code's text model and CPython's typing.py. A file the graph cannot parse lists too few signatures and overstates the saving, which is why React's work loop, written in Flow, is left out of the range. When the agent edits, it still reads the lines it changes.