Menu

1 / 2

My AI Read a JSON File from Disk 900 Times in a Loop (And Why No Linter Can Save You)

DEV Community·Fernando Rodriguez·6 months ago
#ekE75elw
#ai#llm#file#offsets#code
Reading 0:00
15s threshold

Last week my AI wrote code that read a JSON file from disk, parsed it, did one lookup, and repeated this 900 times inside a for loop. Each iteration: open file, decode JSON, look up a value, throw it all away. Start over.

It's a mistake I teach my students not to make within their first month of programming.

What happened (straight to the point)

I'm building Tokamak, a macOS menu bar app that monitors Claude Max quota. Part of the functionality scans ~900 JSONL files from Claude Code sessions. For each file, it needs to know the byte offset where it left off last time (incremental reading — only process what's new).

The offsets are stored in a JSON file:

{ "version" : 1 , "offsets" : { "project-a/session-1.jsonl" : 48231 , "project-b/session-2.jsonl" : 12044 } }

Enter fullscreen mode

Exit fullscreen mode

A Dictionary<String, UInt64> . 900 entries. ~55KB. Nothing fancy.

And here's the detail that makes it even more absurd: the app itself created this file . It's not JSON from an external API.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.