Oh my goodness. I can relate to such dangerous thoughts. I had moments where I thought of using the knife on myself and that was just horrible indeed. And I even used to think about getting run over by the vehicles while crossing the street on a pedestrian lane! Like wth, intrusive thoughts are the worst!!!
How did I get rid of such? Well as a Catholic I went and prayed then read an Examination of Conscience online and repented of my sins back in 2023, including those evil thoughts and even the occult practices I did. I listed everything down after examining my conscience and went to confession to clean up my soul.
We have to nip it in the bud as soon as such thoughts become frequent because it's one of the signs you're "secretly" going the wrong way. I didn't realize what was happening but thank God for my guardian angel I believe it helped me a lot in hitting the brakes and repenting otherwise it's gonna be downhill from there. Been doing frequent confession and daily prayers (rosary, Divine Mercy chaplet, etc.) since then to keep such thoughts away so if you're Catholic you can do it too! 🙏
God bless you and your family!