Molecular mediators have demonstrated broad applicability in electrolyte chemistry of lithium–sulfur batteries, transforming sulfur conversion from traditional multiphase reactions to highly reactive pathways1–6. Despite tremendous efforts to elucidate the mechanistic roles of molecular mediators7–9, the influence of molecular skeleton regulation on their mediating effects remains barely understood. Here we propose 2-chloropyrimidine as a potential ‘premediator’ and a model material for molecular skeleton design, which can be in situ activated into a molecular mediator during sulfur reaction progression by means of aromatic nucleophilic substitution, homogeneously inducing a rapid redox loop over the electrode. Integrating quantum chemistry and machine learning, we develop a molecular skeleton programming strategy that illuminates the structure–property relationship between electronic, geometric and site features of side-chain groups and mediating performance, offering control over the activation rate and mediating activity of premediators. The strategy identifies 2-chloro-4-(trifluoromethyl)pyrimidine as a favourable premediator from 196 candidates, enabling lithium–sulfur batteries to achieve an average capacity retention of 81.7% over 800 cycles together with an energy density of 549 Wh kg−1 in a 14.2-Ah-level pouch cell. We expect that our work on molecular skeleton programming may find application in designing functional molecules in broader organic chemical spaces.