Cramps when you stretch your legs after waking up from sleep may be caused by calcium deficiency, exposure to cold, excessive exercise and other factors. According to the specific conditions, we should adopt appropriate treatment methods, such as oral calcium and other medications, keep warm, and pay attention to warm up before exercise. 1. Calcium deficiency: When the body lacks calcium, it will cause low blood calcium, resulting in involuntary muscle twitching. It can be treated with oral calcium and vitamin D3 as prescribed by the doctor. 2. Cold: cold muscles can also cause muscle cramps during sleep, it is recommended to pay attention to leg warmth during sleep to avoid getting cold. 3. Excessive exercise: leg muscle fatigue due to strenuous exercise or excessive exercise can cause leg cramps. You can do a good job of warming up and stretching your muscles before exercise, which can relax them. Leg cramps may also be related to local nerve compression and other factors, it is recommended to go to the hospital in time to identify the cause of the disease, under the guidance of the doctor for treatment.