this happens to me a lot as well, i learned if you allow it to achieve a full cramp, it's harder to relieve, but you need to prevent it as soon as it happens. may hurt a little, but it's better in the long run
if you allow it to fully cramp, you lay there in pain until it decides to go away, but if you intercept it before, it'll hurt for a minute or so while you pull it out, then you can relax.
Sometimes my fourth toe mislocates. Like, it moves forward and down so that instead of being in line with everyone else it's all "screw you, hell is warm."
This has happened to me
It's awful