How do you know when to stop coding because you're overworking, writing too many duplicate files and making common mistakes?
When is it best to take a break when you're use to hyperfocusing (an ADHD trait) where you easily spend hours on end coding (sometimes skipping meals or workouts, but not always), or are on a tight deadline and have to get a lot done, but then you find because you pushed yourself too hard, your eyes are heavy and you're making common mistakes?
Or you were fine (not heavy eyes), but only realize later on when you debug, you had tiny mistakes you wouldn't have made, but were so busy rushing and overworking you made minute errors you normally wouldn't make, and your code quality sucks.
It's hard to quantify exactly, but I stop working when 1 of 2 happens:
I try to have a goal for each of my days, broken down by hours (e.g. by 2PM, I want X done). If I'm falling behind, then I'll quickly retrospect to see what's happening (which sometimes leads to 1 of the 2 vibe checks above).
My higher-level advice though is to set up systems so you never need to reactively correct due to the above 2 scenarios. In particular, leverage your calendars + alarms to make sure you:
I talk about this in-depth in my productivity course: https://www.jointaro.com/course/maximize-your-productivity-as-a-software-engineer/get-good-sleep/