A magnesium (Mg) battery in the combination with the redox active polymers possesses attractive electrochemical properties as a future battery technology. This concept has been demonstrated by using quinone based polymers and the non-nucleophilic electrolytes, while polyimides were rarely investigated. In this work, a naphthalene-hydrazine diimide polymer (NP) has been tested as a cathode material for Mg organic battery in two different electrolytes. Average discharge voltage of the Mg-NP battery is 1.70 V with Coulombic efficiency above 99% in the TEGDME/DOL based electrolyte. The electrochemical mechanism was studied by in operando ATR IR spectroscopy and confirmed by DFT calculation of the IR spectra. We confirmed redox activity of carbonyl moieties, which undergo reversible reduction to enolate anion. Moreover, in operando IR spectroscopy shows charge delocalization in the reduced form since none of the bonds has pure single/double bond character.