SUMMARYFlies groom in response to competing mechanosensory cues in an anterior to posterior order using specific legs. From behavior screens, we identified a pair of cholinergic command-like neurons, Mago-no-Te (MGT), whose optogenetic activation elicits thoracic grooming by hind legs. Thoracic grooming is typically composed of body sweeps and leg rubs in alternation, but clonal analysis coupled with amputation experiments revealed that MGT activation only commands the body sweeps: initiation of leg rubbing requires contact between leg and thorax. With new electron microscopy (EM) connectome data for the ventral nerve cord (VNC), we uncovered a circuit-based explanation for why stimulation of posterior thoracic mechanosensory bristles initiates cleaning by the hind legs. Our previous work showed that flies weigh mechanosensory inputs across the body to select which part to groom, but we did not know why the thorax was always cleaned last. Here, the connectome for the VNC enabled us to identify a pair of GABAergic inhibitory neurons, UMGT1, that receive diverse sensory inputs and synapse onto both MGT and components of its downstream pre-motor circuits. Optogenetic activation of UMGT1 suppresses thoracic cleaning, representing a mechanism by which mechanosensory stimuli on other body parts could take precedence in the grooming hierarchy. We also mapped the pre-motor circuit downstream of MGT, including inhibitory feedback connections that may enable rhythmicity and coordination of limb movement during thoracic grooming.