What's helped is switching from "debugging" to "externalizing". Writing the thoughts down, like logs, makes them feel less real and less recursive. Once it's on paper, it loses some power.
One small thought exercise I picked up from The Power of Now that surprisingly works for me: when I'm deep in a rabbit hole, I take a few deep breaths and ask myself, "What will my next thought be?" For a moment everything just goes quiet, and the mind kind of resets. I've used this hack multiple times.
Another thing that matters more than I expected is just building basic habits. Exercise, walking, sleeping on time, eating properly. Nothing fancy, but having a pattern makes the bad loops less frequent.
I've also learned anxiety isn't always something you can reason away. Sometimes it's just a physical state and you have to change the input before the mind follows.