I do not get them during my ride sorry I was not claer about that. If I go for a long ride lite I did today then at about 3:00 am I am jumping out of bed to try and walk it out. It's just the right which I am guessing it's do to breaking as I put my left down and the r foot always on the brake at a stop.
I used to be a practicing chiropractic orthopedist years ago, now I own an ergonomic consulting firm. All the advice given to this point is great, but if you are getting the cramping at night, it points strongly to either stressing / overworking the muscle during the day and then the muscle cramps up at night while not being used, or you are stressing your back or hip while riding and getting some temporary nerve irritation to the leg from hip or back muscle spasms at night cauing leg spasms. this is common. Dehydration or potassium depletion are all causes of muscle cramping but they usually affect the muscle groups during the day too and not just at night or at rest, and they will often affect more than just one muscle. All the advice given will help, but may not be enough to solve the problem if the problem is overworking the muscle groups or irritating some spinal, hip, or knee arthritis while riding.
Here are some structural things you can look out for:
Look for proper positioning of your lower body. Your lower back should be supported and you should maintain your arch in your lower back. You may have to continually work on reminding yourself to straighten your back posture until it becomes habit. (not rigid straight, just maintain your front to back curve and avoid rounding it out slouching forward) Be relaxed.
You might need some back support, but be sure you do not get into an awkward posture to try and lean back against the support. You need some thing that will properly support you there if this is your issue.
I suspect that you might be subconsciously holding your right leg up in anticipation of braking, kind of like some people keep a finger raised up when using a mouse, ready to hit the mouse button as needed. Your lfoot and leg may actually be on the floorboard but your muscles may be contracted and not relaxed even so. try consciously relaxing the leg when riding. If you can relax the muscles at all when you try, that means you are unconsciously keeping them contracted in anticipation when riding. I have had patients with hip problems that did this and it always affects the braking leg since by design the shifting foot has to be rested more on the floorboard to work so the muscles are less likely to be actively held in a tense state.
there can be compression of the sciatic nerve from your seat or spasm of the gluteal or piriformis muscles in the buttock that can cause nerve irritation. this may be especially true if you hold your braking leg with the foot turned out for long periods of time (external hip rotation) as you will keep those hip muscles contracted all day to do so. I have had many car drivers as patients complain of back, hip, and leg cramping and pain until we figured out they were doing this with their gas foot.
Of course there are other potential causes ranging from issues of poor circulation to some degenerative arthritis of the back, hip, or knee.
Typically, even if you can not identify what is causing the abnormal stress in the calf or hamstring (I assume that is what is cramping up) a daily stretching program would help you alot. BTW if you are on your feet all day at work (or even in a chair all day) this may be contributing to the overall muscle fatigue and further suggests the need for stretching. lack of activity is as bad as too much activity.
try stretching your calf, hamstring, quadriceps, the gluteals, lower back and your inner thigh muscles and that should do the trick. Do them every day as the effects of stretching is cumulative, and especially do them before and after riding. Additionally I stretch out my hamstrings and quads whenever we stop for a break too. I am old enough and have had enough skiing injuries over the years to need to do that to keep any discomfort away. the guys I ride with now do this and they have cut down most of the discomfort in their backs from being on the seat for hours.
if you are unsure of what to do in regard to stretching, I can see if I can post some of the stretches for you.
And again, the other advice given here by others is good to follow thru with too. Hope this info helps.: