We present a numerical scheme, implemented in the cosmological adaptive mesh refinement code enzo, to model the injection of cosmic ray (CR) particles at shocks, their advection and their dynamical feedback on thermal baryonic gas. We give a description of the algorithms and show their tests against analytical and idealized one-dimensional problems. Our implementation is able to track the injection of CR energy, the spatial advection of CR energy and its feedback on the thermal gas in run-time. This method is applied to study CR acceleration and evolution in cosmological volumes, with both fixed and variable mesh resolution. We compare the properties of galaxy clusters with and without CRs for a sample of high-resolution clusters with different dynamical states. At variance with similar simulations based on smoothed particles hydrodynamics, we report that the inclusion of CR feedback in our method decreases the central gas density in clusters, thus reducing the X-ray and Sunyaev–Zeldovich effect from the clusters centre, while enhancing the gas density and its related observables near the virial radius.