The confinement of neuronal activity to specific subcellular regions is a mechanism for expanding the computational properties of neurons. Although the circuit organization underlying compartmentalized activity has been studied in several systems, its cellular basis is still unknown. Here we characterize compartmentalized activity in Caenorhabditis elegans RIA interneurons, which have multiple reciprocal connections to head motor neurons and receive input from sensory pathways. We show that RIA spatially encodes head movement on a subcellular scale through axonal compartmentalization. This subcellular axonal activity is dependent on acetylcholine release from head motor neurons and is simultaneously present and additive with glutamate-dependent globally synchronized activity evoked by sensory inputs. Postsynaptically, the muscarinic acetylcholine receptor GAR-3 acts in RIA to compartmentalize axonal activity through the mobilization of intracellular calcium stores. The compartmentalized activity functions independently of the synchronized activity to modulate locomotory behaviour.