I can't respond to this problem directly, but when I had a nail-biting problem, I stopped it by grooming (filing, cleaning, applying lotion) the nails instead. So, if you can find another way to occupy your hands while thinking: doodling, fiddling with a pencil, or some other thing that keeps your hands out of your hair. Having some other thing in your hands rather than your hair might help. Grooming the hair of a Troll doll (showing my age), or something like that?