Beyond their role as immune sentinels, microglia are actively involved in establishing and maintaining cortical circuits. Alteration in microglial numbers has been associated with abnormal behaviors akin to those observed in neurodevelopmental disorders. Consequently, establishing the appropriate microglial numbers during development is crucial for ensuring normal cortical function. Here, we uncovered a dynamic relationship between pyramidal cells and microglia that tunes microglial numbers and development through distinct phases of mouse postnatal development. Changes in pyramidal cell activity during development induce differential release of activity-dependent proteins such as Activin A, which, in turn, adjusts microglial numbers accordingly. Decoupling of this relationship not only changes microglial numbers but has a long-term consequence on their role as synaptic organizers, which ultimately affects cortical function. Our findings reveal that microglia adapt their numbers to changes in pyramidal cell activity during a critical time window in development, consequently adjusting their numbers and function to the demands of the developing local circuits.