I suspect that so many of us overthink most of the time, such that it's one of the reasons that the most productive times seem to be in the early morning or late at night.
Early morning our brains have been largely reset and it's a clean slate, thoughts haven't had the chance to build up yet. Late night our brains are tired, making it easier to be single-minded in focus during coding.
Balmer's peak could be related to this (though I haven't personally found alcohol to work for me).