We developed fatigue-resistant hydrogel optical fibers through the controlled growth of polymeric nanocrystalline domains to enable light delivery to peripheral nerves during locomotion. The hydrogel fibers withstand locomotion strain across more than 30,000 fiber stretch cycles and enable the optogenetic inhibition of pain hypersensitivity in naturally behaving mice.