Throughout vertebrates, cerebrospinal fluid-contacting neurons (CSF-cNs) are ciliated cells surrounding the central canal in the ventral spinal cord. Their contribution to modulate locomotion remains undetermined. Recently, we have shown CSF-cNs modulate locomotion by directly projecting onto the locomotor central pattern generators (CPGs), but the sensory modality these cells convey to spinal circuits and their relevance to innate locomotion remain elusive. Here, we demonstrate in vivo that CSF-cNs form an intraspinal mechanosensory organ that detects spinal bending. By performing calcium imaging in moving animals, we show that CSF-cNs respond to both passive and active bending of the spinal cord. In mutants for the channel Pkd2l1, CSF-cNs lose their response to bending and animals show a selective reduction of tail beat frequency, confirming the central role of this feedback loop for optimizing locomotion. Altogether, our study reveals that CSF-cNs constitute a mechanosensory organ operating during locomotion to modulate spinal CPGs.