I was in a very similar position. After digging I to that feeling with my therapist, I found out that I wasn't miserable coding. I was miserable with all the other bullshit I've had at my job: stand-ups, task tracking, constant meetings, always feeling pressure and responsibility that triggered impostors syndrome, and so on.
I've changed companies, and now I don't have any of that. I don't even remember how my bosses voice sounds: it's a remote position where we communicate in text, mostly asynchronously. There's no task tracking, just company chat. I almost never get asked when will I complete something; we just discuss what needs to be done, and then I do it. If I don't feel like working, I don't. Nobody's tracking my time. And later, when I get internal motivation, I put in 20 hours of uninterrupted, productive work.
I don't think that I've ever been that happy coding in my entire life.