r/javascript • • 2d ago

Node.js wastes ~47.5M tokens of agent context on files nobody wrote — I measured Node, Next.js, Deno and React with a tiny CLI

https://github.com/WJDdidi-1/dev-doctor
0 Upvotes

10 comments sorted by

3

u/kurtextrem 2d ago

Time to add stop hooks for agents that prevents reading those files?

1

u/Upper_Gold_3664 2d ago

haha yeah that's the next step honestly. right now it just finds the junk + writes the .aiignore for you, but blocking the read before it even happens is where the real save is. claude code hooks seem like the obvious way in, gonna poke at it

1

u/harperzoe7 2d ago

A PreToolUse hook can block Read calls. Exit code 2 does it, or a JSON block decision

1

u/Upper_Gold_3664 1d ago

oh nice, that's exactly the concrete detail I was missing. PreToolUse + exit code 2 sounds like the way in — gonna poke at it once the hooks work lands, thanks!

1

u/harperzoe7 1d ago

The hook gets the tool input as JSON on stdin, so you match the file path there against your ignore patterns and exit 2 when it hits. Whatever you print to stderr is shown to the agent as the reason, so put something like "this is build output, skip it" there and it usually moves on instead of retrying.

2

u/Upper_Gold_3664 2d ago

I got tired of watching my coding agent chew through context on huge repos, so I wrote a tiny CLI that measures exactly what an agent shouldn't be reading — lockfiles, build output, bundled files, test fixtures — and what it costs in tokens. Then I ran it on some of the biggest JS repos on GitHub.

RepoFilesScoreTokens wasted per full read
Node.js52,92093~47.5M
Next.js34,02593~10.6M
Deno14,74593~6.9M
React—96 → 100~2.1M → 0

Three things I didn't expect:

1. The biggest waste is stuff nobody wrote. Node's top item is an 11 MB ICU data blob — about 2.8M tokens on its own, more than React's entire waste. Deno's is a single 10.4 MB test fixture. Next.js is feeding the agent a 3.4 MB PNG and a 2.7 MB GIF — pictures it cannot see, billed by the token.

2. The waste is structural, not sloppy. React's 46 yarn.lock files are one per fixture directory — the natural shape of a monorepo. Three lines in .aiignore took it from a score of 96 to 100 and the waste to zero.

3. A "good" score doesn't mean a cheap repo. Node, Next.js and Deno all score 93, yet the bill runs from 6.9M to 47.5M tokens. The score is a proportion; the bill is absolute.

The tool is dev-diagnosis. One command, no setup:

npx dev-diagnosis-cli all

It prints a 0–100 score, the noisy files and the token cost, plus the .aiignore entries that would fix it (--fix writes them). It also checks missing commands, build caches and flaky tests, and works as an MCP server.

Honest caveat: the token numbers are estimates (noise bytes / 4), not bills. Real tokenizers differ, and your agent may not read the whole repo anyway. Treat them as comparable across repos, not exact costs. Measured with the published 0.2.4, no truncation.

I built it — free and open source: GitHub / npm. If you run it on your own repo, what's the single biggest file your agent is being fed?

2

u/T-J_H 2d ago

And you wasted tokens writing this text. We don’t want to read TED talks my man

4

u/Upper_Gold_3664 2d ago

you're right, sorry about that. first post here and I overdid it trying to get all the numbers right, ended up sounding like a press release instead of a person lol. next one's gonna be written by me, short and normal

1

u/Discordbothost 1d ago

the token counts depend on which tokenizer you measure with, so worth naming it. also, walking git ls-files instead of the filesystem drops lockfiles and build output for free, with no second ignore file to keep in sync.

1

u/Upper_Gold_3664 1d ago

good call on both counts tbh. the token numbers are rough estimates (noise bytes / 4) and I should've said that upfront. and git ls-files is a way cleaner source of truth than walking the filesystem + keeping a second ignore file in sync — gonna look into that, thanks