People can definitely perform mental compulsions.
Some examples of mental compulsions would be saying prayers over and over again until they are said “just right,” repeating the name of someone you thought something negative about to try to undo the “bad” thought, or counting up to certain lucky numbers to prevent a feared consequence.
All of these compulsions can be performed without anyone actually noticing them being performed. However, as the compulsions increase over time, the individual performing them becomes more and more preoccupied with doing the mental compulsions, and they appear distracted more and more often.
Eventually, individuals with mental compulsions can spend hours in their head, fearing their thoughts and attempting to undo the effects of those thoughts with other thoughts. However, therapy is effective for mental compulsions as well as physical compulsions, with the focus of the therapy being acceptance of the thoughts and decreasing the attempts to mentally undo the thoughts.
For example, some people compulsively count things, such as ceiling tiles, carpet squares, or the number of steps that they take. One way to start challenging this is to have them change the way that they count. They can start to count every other step, and then every third step, and so on until they are barely counting at all, eventually, they’ll stop altogether.
Just changing your rituals can have a major impact on your giving them up because you allow yourself to see that there really is not a correct way to do them, and if there is no correct way to do them, then maybe they do not even have to be done.