These seem like OCD tendencies, but not full-blown OCD.
Best thing to do is challenge the idea of counting to a specific number;
e.g. when you have the intrusive thought arise about counting whilst doing something, don't count.
When this happens it's likely you'll get a spike in anxiety, and more thoughts about counting.
Just learn to to tolerate these thoughts and feelings, and overtime your anxiety and compulsions will subside.
Here's a video for overcoming intrusive thoughts / anxieties:
YouTube