Have you ever stared at code you supposedly "wrote" and realised you couldn't read it?

I asked an AI to build me a small Python file-renamer, it handed me about eighty lines, everything ran, and I felt like a genius for roughly one day.

This is the story of what happened on day two, and why it changed how I use AI completely.

The setup: a genius and his renamer

The tool was simple. Point it at a folder of downloaded lecture files with names like final_FINAL_v2(1).pdf, and it renames them into something clean and sorted.

I described what I wanted. The AI produced tidy, confident code. I ran it on a test folder and it worked beautifully.

So, naturally, I ran it on my real folder.

The break

Some files renamed fine. Others came out wrong in a strange, slippery way: the numbering was off, and a few names got a prefix they were never supposed to have. No crash. No error. Just quietly wrong output, which I now know is the worst kind of bug.

I opened the code to find the problem and had a genuinely cold moment: I did not know where to look. Not "I couldn't find the bug." I couldn't tell you what most of the file did. It was mine the way a meal is yours because you ordered it.

What I tried first (all of it useless)

I did what anyone does. I re-ran it, hoping the output would change its mind. It didn't.

I renamed a folder and ran it again, in case the folder was the problem. The wrongness moved with the files.

I stared at the section with the string formatting, because it looked complicated, and complicated-looking code feels guilty. It was innocent. I wasted half an hour interrogating the one part of the file that worked perfectly, which taught me something I now repeat to myself: bugs live where the logic is, not where the syntax looks scary.

I even checked the file extensions, one by one, like a man shaking a locked door's handle twenty times. The door was fine. The person who locked me out was a variable on line thirty-something, and I walked past it four times before clue 3 made me stop and actually read the names in the file instead of skimming them.

That is the other humiliating detail. The bug was visible the whole time. It wasn't hidden in a library or a race condition. It was a repeated English word in code I'd "written," and I couldn't see it because I had never truly read my own file top to bottom, slowly, as if someone else had written it and I didn't trust them. I didn't trust the AI either, of course. I just hadn't replaced trust with reading.

The three clues that finally found it

Clue 1: it only broke with certain filenames. Files with spaces were fine. Files with brackets or a second dot in the name were the wrong ones. That narrowed the crime scene from eighty lines to the small section handling the name cleanup.

Clue 2: the wrong output had a pattern. Every broken name had been processed as if it were a folder path, not a filename. Something in the code was feeding the wrong thing into the renaming step.

Clue 3: one variable name appeared twice, doing two different jobs. And there it was. The AI had reused a variable, and later in the file the second meaning quietly overwrote the first. A shadowing bug:

name = clean(folder_name) # the path being processed # ... twenty lines later ... name = file.split('.')[0] # now 'name' means something else entirely 

One variable, two jobs. The second assignment clobbered the first, and every file after that point was renamed using the wrong value. The fix was embarrassingly small:

base = file.split('.')[0] # give the second job its own variable 

Rename one variable, and the whole tool behaved. One word. I had spent the better part of an evening hunting a single repeated word.

The catch, and it's the whole point

Here is the part I keep thinking about. Once I found the bug, I pasted the original error into the AI out of curiosity. It spotted the shadowing and fixed it in seconds.

So the fastest path was always: don't understand anything, just feed the machine its own mistake until it corrects itself. And that is exactly the problem. If I had done that first, the tool would work today and I would be helpless again tomorrow, on the next bug, in the next project, forever renting a brain.

The evening I spent lost in that file taught me more than the tool ever did. I learned to narrow a bug by asking which inputs break. I learned that "no error" doesn't mean "no bug." I learned that a variable quietly changing meaning is a real way programs fail, because it failed on me.

How I use AI now

AI still writes first drafts for me. I'm not a monk. But I read every line before it runs, and if I can't explain a line, the line doesn't ship. Slower by an hour, sometimes. Cheaper by a disaster, so far.

The renamer works, by the way. It's mine now. It took an evening of being lost to earn that sentence.

So tell me honestly:

When did AI code last break on you, and did you understand the fix?