  Recently, cosmic ray (CR) feedback has been identified as a critical process
in galaxy formation but most previous simulations have integrated out the
energy-dependence of the CR distribution, despite its large extent over more
than twelve decades in particle energy. To improve upon this simplification, we
present the implementation and first application of spectrally resolved CRs
which are coupled to the magneto-hydrodynamics in simulations of galaxy
formation. The spectral model for the CRs enables more accurate cooling of CRs
and allows for an energy-dependent spatial diffusion, for which we introduce a
new stable numerical algorithm that proves essential in highly dynamical
systems. We perform galaxy formation simulations with this new model and
compare the results to a grey CR approach with a simplified diffusive transport
and effective cooling that assumes steady-state spectra. We find that the
galaxies with spectrally resolved CRs differ in morphology, star formation
rate, and strength and structure of the outflows. Interestingly, the first
outflow front is driven by CRs with average momenta of
$\sim200-600\,\mathrm{Gev}~c^{-1}$. The subsequent formation of outflows, which
reach mass loading factors of order unity, are primarily launched by CRs of
progressively smaller average momenta of $\sim8-15\,\mathrm{GeV}~c^{-1}$. The
CR spectra in the galactic centre quickly approach a steady state, which does
not significantly vary over time. In the outer disc and outflow regions, the
spectral shape approaches steady state only after $\sim2\,\mathrm{Gyr}$ of
evolution. Furthermore, the shapes of the approximate steady state spectra
differ for individual regions of the galaxy, which highlights the importance of
actively including the full CR spectrum.
