By directly altering microscopic interactions, pressure provides a powerful tuning knob for the exploration of condensed phases and geophysical phenomena1. The megabar regime represents an interesting frontier, in which recent discoveries include high-temperature superconductors, as well as structural and valence phase transitions2-6. However, at such high pressures, many conventional measurement techniques fail. Here we demonstrate the ability to perform local magnetometry inside a diamond anvil cell with sub-micron spatial resolution at megabar pressures. Our approach uses a shallow layer of nitrogen-vacancy colour centres implanted directly within the anvil7-9; crucially, we choose a crystal cut compatible with the intrinsic symmetries of the nitrogen-vacancy centre to enable functionality at megabar pressures. We apply our technique to characterize a recently discovered hydride superconductor, CeH9 (ref.10). By performing simultaneous magnetometry and electrical transport measurements, we observe the dual signatures of superconductivity: diamagnetism characteristic of the Meissner effect and a sharp drop of the resistance to near zero. By locally mapping both the diamagnetic response and flux trapping, we directly image the geometry of superconducting regions, showing marked inhomogeneities at the micron scale. Our work brings quantum sensing to the megabar frontier and enables the closed-loop optimization of superhydride materials synthesis.