I am not sure that there is a universal remedy here, honestly, but try to look for something monotonous that distracts you. I cannot give any specific advice because you have to experiment. I like assembling MJP jigsaw online; it helps. My friend reads simple books, some light reading. Someone runs, someone goes swimming. In general, there are many options. You just have to try.
Often it is not thoughts that come to my mind, but dreams that appear. And it is terrible, because it feels like I have been working not for 3 days, but for 10 consecutive days, because both during the day and at night I am in this process.
I currently have a new job, as you understand. And it seems that I am doing reasonably well, but after every task I simply cannot fall asleep. I lie down and replay in my head how I could have done something differently. It is awful, I do not rest, and yet I like my job, I want to work there. But how to make myself stop thinking and relax, I have no idea.