I'd like to know too. I used to have a lot of drive in the past to code something without thinking about the end goal, but now whenever I start it's all I can think of precisely because my past efforts haven't resulted in an end product yet and it feels like a Sisyphean task. I guess it doesn't help that most of my work day is spent programming, either.
If working solo, the answer should be to not really think about the time, tasks or end results and to break it down into small goals, but you most likely already know that. The hard part is coming to terms with it. Sure, programming and seeing progress can be its own reward at times, but it can simultaneously feel hollow if you aren't fully committed to it.
I guess all of this is a roundabout way of saying it's probably something that can be better addressed by a mental health professional, but the state of mental healthcare is such that, well, good luck with getting it.