Control of action selection in the brain must be stable yet flexible. Using two-photon calcium imaging, the authors find distinct population activity states in secondary motor cortex for different stimulus–response contingencies and show that transitions between these states occurred earlier when mice were required to abort a repetitive action and use a conditional rule.