Many lines of evidence suggest that memory in the mammalian brain is stored with distinct spatiotemporal patterns. Despite recent progresses in identifying neuronal populations involved in memory coding, the synapse-level mechanism is still poorly understood. Computational models and electrophysiological data have shown that functional clustering of synapses along dendritic branches leads to nonlinear summation of synaptic inputs and greatly expands the computing power of a neural network. However, whether neighbouring synapses are involved in encoding similar memory and how task-specific cortical networks develop during learning remain elusive. Using transcranial two-photon microscopy, we followed apical dendrites of layer 5 pyramidal neurons in the motor cortex while mice practised novel forelimb skills. Here we show that a third of new dendritic spines (postsynaptic structures of most excitatory synapses) formed during the acquisition phase of learning emerge in clusters, and that most such clusters are neighbouring spine pairs. These clustered new spines are more likely to persist throughout prolonged learning sessions, and even long after training stops, than non-clustered counterparts. Moreover, formation of new spine clusters requires repetition of the same motor task, and the emergence of succedent new spine(s) accompanies the strengthening of the first new spine in the cluster. We also show that under control conditions new spines appear to avoid existing stable spines, rather than being uniformly added along dendrites. However, succedent new spines in clusters overcome such a spatial constraint and form in close vicinity to neighbouring stable spines. Our findings suggest that clustering of new synapses along dendrites is induced by repetitive activation of the cortical circuitry during learning, providing a structural basis for spatial coding of motor memory in the mammalian brain.