Many animals and robots move using undulatory motion of their bodies. When the bodies are in close proximity undulatory motion can lead to novel collective behavior such as gait synchronization, spatial reconfiguration, and clustering. Here we study the role of contact interactions between model undulatory swimmers: three-link robots in experiment and multilink swimmers in simulation. The undulatory gait of each swimmer is generated through a time-dependent sinusoidal-like waveform which has a fixed phase offset, ϕ. By varying the phase relationship between neighboring swimmers we seek to study how contact forces and planar configurations are governed by the phase difference between neighboring swimmers. We find that undulatory actuation in close proximity drives neighboring swimmers into planar equilibrium configurations that depend on the actuation phase difference. We propose a model for stable planar configurations of nearest-neighbor undulatory swimmers which we call the gait compatibility condition, which is the set of planar and phase configurations in which no collisions occur. Robotic experiments with two, three, and four swimmers exhibit good agreement with the compatibility model. To study the contact forces and the time-averaged equilibrium between undulatory systems we perform simulations. To probe the interaction potential between undulatory swimmers we apply a small force to each swimmer longitudinally to separate them from the compatible configuration and we measure their steady-state displacement. These studies reveal that undulatory swimmers in close proximity exhibit attractive longitudinal interaction forces that drive the swimmers from incompatible to compatible configurations. This system of undulatory swimmers provides new insight into active-matter systems which move through body undulation. In addition to the importance of velocity and orientation coherence in active-matter swarms, we demonstrate that undulatory phase coherence is also important for generating stable, cohesive group configurations.