My strategy is like:
"Thanks brain for that helpful monologue on suicide...again. But actually that's not really thoughts I need to focus on right now, because I already know that speech back to front, and right now I'm driving my car and focusing on that." (Cue refocus on the road!)
I have suicidal thoughts habitually. Wake up, what about suicide? Car needs petrol, how about suicide? Drives me batty. I don't need to focus on it, because it's the same thought, and I've thought it millions of times, it doesn't need endless repetition.
The fancy title is "thought defusion", often associated with ACT. For me, it's the helpful part of ACT. It basically posits that the more you struggle against having a thought, or the more you engage the thought by CBT-ing it to death, the more you're gonna have that thought. Like, if I tell you that you urgently need to stop thinking about chocolate, what's the first thought that pops into your head? Oooh, chocolate! I must stop thinking about suicide? Suddenly the suicide monologue is on repeat.
The first half of The Happiness Trap has been my go to several times over; because it includes a (much better) description, as well as different methods that different people find helpful. But the essence of it is to recognise those thoughts as nothing more than thougts, and refocusing on whatever you're doing, consciously deciding to let the thoughts be (rather than try and stop them), and just refocus. Over and over again if need be. The thought isn't good or bad, it's just a thought, my brain goes there by habit (not because I need reminding), refocus.
It doesn't work for everything. Like, thoughts that are actually core beliefs rather than just thoughts, I don't find it helpful. But if thoughts become habitual, it helps me a lot. Like, a lot!