I'm recovering from a severe burnout that sounds similar.

I started at a small company about three years ago. I had about 17-18 years of experience and had spent the prior five years working as a freelance consultant/engineer helping big companies build private and public clouds using open source stacks. The entire team was comprised of developers with much less experience, mostly fresh grads/bootcampers/web developers who'd worked on small projects, and the CTO had no technical expertise. I became interested in staying after working with them for a few months because they had big, multinational conglomerates as customers for some reason and I thought I saw some potential. So I buckled down, found the right project to introduce a solid REST API built on simple, boring technology that was easy to maintain. I became the engineering manager out of necessity: the CTO had no experience writing, maintaining, operating software and no clue with what it took to hire, mentor, and train developers. It became my passion project: could I build up a team to meet the challenge?

I think I mostly did do that. The platform I had built for that initial project now powers everything. It took a lot of convincing to get the development team on board with building a REST API to begin with but once our customers started asking us to integrate with their software it started to make sense to them. I set up the hiring process, created a rubric for different job roles at the company, started doing quarterly 1 on 1's with every member of the engineering teams, started collecting metrics and signals to gather insights into the productivity and impact of the engineering team, I made diversity a priority on how we build our teams, I shifted the operations away from sleepless nights of putting out fires to a more sustainable SRE/devops style team, I led the technical design of several high-profile projects, I even helped secure our funding by having done the due diligence and having the right numbers prepared ahead of the meeting (something our CTO didn't have the foresight to do himself)... and in that time the company grew: we took on some funding, our MRR was growing at a good clip -- it was working!

But I was doing this all in spite of a toxic culture. The CEO disagreed with anything I had to say about management of software engineers from over-time, compensation, all the way to how I scheduled and organized the teams. The CTO was someone who was equally insecure and incompetent but was always rewarded by our success in the small, local community. He would use my ideas as if they were his own, second guess my every decision, put me down in front of the team, and make terrible, terrible decisions despite our best efforts to inform him.

One such decision led to our team working on a doomed feature for three months. When it failed, for exactly the reason I tried my best to inform him of before we started, the customer was furious. The project was due and it would be another four to five months before we had a solution in place. I warned him that a proper implementation of this feature was going to take about four to five months and that we'd be better off cutting it from the release for now so that we could deliver 90% of what was asked on time. If we had tried to implement this feature the naive way it was going to blow up as soon as the customers' data set grew to a reasonable size. I even gave him estimates, based on current statistics, as to how long it would take to blow up if we shipped it to production. He wanted us to ship it anyway. We did, it failed within the predicted time line. Nobody was surprised.

At the early meeting after I patiently described to him, in general terms, why we needed to cut that feature so we could ship on time, do you know what he said to me? If I was smart I would be able to figure it out.

This would all culminate in him completely overriding me. The teams were under a lot of stress from management to ship and I was doing my best to deflect it as always so they could do their work. But the team was feeling the pressure none the less. The CTO decided that the best way to fix the situation was to take matters into his own hands. He decided a re-organization was in order. After consulting me after lunch one day about his idea which I thought would be good, later, when we grow out the team a little more and wrapped up some of our existing, in-progress projects... in the weeks that followed, he just took over and did the re-organization any way. In a meeting with our advisors about this re-organization he went so far as to go behind my back to pick out quotes from frustrated developers to use to put me down.

Suddenly, out of no where, everything I had worked so hard for was turned over. I hated going into work. I didn't even want to look at the CTO anymore or be in a room with him. He'd spent the last few years giving me feedback that people were saying things about me (they weren't saying those things). Putting me down in front of the team. Second guessing everything I ever did for the company. Arguing with me about topics when he had absolutely no idea what I was talking about. And I felt trapped. I had a family to look after, a mortgage to pay, and I'm getting older; maybe too old to be hired as an IC (even though maths and programming are what I like best)... and here I was working with people who couldn't see the value in anything I'd done for them, the struggle I went through to build it for them -- and they're taking advantage of me every day and making me feel like a worthless, talent-less piece of shit in return.

A fog descended upon me. I felt lethargic. Tired. Angry. A dried twig that would snap under the lightest force. I hated programming. I hated everyone I worked with. I could only sense people saying bad things about me behind every closed door. Wondered if I really was that bad at my job. I felt like everything I had worked for in the last three years was for nothing. And the voice inside me had nothing good to say about me either: stupid, hack, washed up, useless.

Of course you can't listen to that for long. Fortunately I have good friends, a good partner, wonderful kids, and I'm self aware enough to know that what I was going through wasn't normal. It's burnout. And it needs to be dealt with.

I was simply in denial for years because I was finding success despite all of the adversity. That is the perfect recipe for burnout. It's a ticking time bomb. You can't keep it up indefinitely.

Presently I'm still recovering. I took my first vacation this year. I'm on another one right now. I'm going to continue taking small vacations throughout next year and be kinder to myself. I did keep the CEO up to speed on what was going on with me. He was smart enough, or someone had given him good advice, to isolate me from the CTO and give me projects to work on by myself. The burnout is still there. I still feel betrayed by a team I had invested so much time and energy in raising up (there were some who weren't 100% supportive of my direction). While there are a number of people who desperately want to know if I am going to reprise my role... I don't think I have the energy for it again. I don't want to succeed against the odds anymore. I want to do damn good work and ship software that matters to people.

If you're in a similar boat to me, all I know is, is that you have to be the change. Whether you want to take time away by working on another project and taking as much vacation time as you can until you recharge and are ready for round two or whether you need to jump ship and find something new: the key for me is to find some control. Burnout happens because we feel like we have no control over a stressful situation we're forced into. My first steps so far have been regaining some control. And maybe that might mean later on that I don't have enough control where I am now and I need to leave this company... but maybe I'll recover and be the change to fix this toxic culture. It's all up in the air right now.

Also... read a lot of fiction. Spend hours absorbed in literature, in poetry, and get outside yourself. It helps with coping.