We use state-of-the-art chemical models to track the cosmic evolution of the CNO isotopes in the interstellar medium (ISM) of galaxies, yielding powerful constraints on their stellar initial mass function (IMF). We re-assess the relative roles of massive stars, asymptotic giant branch (AGB) stars and novae in the production of rare isotopes such as 13 C, 15 N, 17 O and 18 O, along with 12 C, 14 N and 16 O. The CNO isotope yields of super-AGB stars, novae and fast-rotating massive stars are included. Having reproduced the available isotope enrichment data in the solar neighbourhood, and across the Galaxy, and having assessed the sensitivity of our models to the remaining uncertainties, e.g. nova yields and star-formation history, we show that we can meaningfully constrain the stellar IMF in galaxies using C, O and N isotope abundance ratios. In starburst galaxies, where data for multiple isotopologue lines are available, we find compelling new evidence for a top-heavy stellar IMF, with profound implications for their star-formation rates and efficiencies, perhaps also their stellar masses. Neither chemical fractionation nor selective photodissociation can significantly perturb globally-averaged isotopologue abundance ratios away from the corresponding isotope ones, as both these processes will typically affect only small mass fractions of molecular clouds in galaxies. Thus the Atacama Large Millimetre Array now stands ready to probe the stellar IMF, and even the ages of specific starburst events in star-forming galaxies across cosmic time unaffected by the dust obscuration effects that plague optical/near-infrared studies.