Cortico-spinal fMRI acquisitions aim to investigate direct interactions between brain and spinal cord, e.g. during motor output or pain processing, by covering both regions in a single measurement. Due to their large distance and location in the body, a dynamic shim update of constant and linear shim terms is required when using echo-planar imaging (EPI) to achieve reasonable image quality in both target regions. A previously presented approach with region-wise shim settings is based on a standard single-region shim algorithm and suffers from (i) non-optimal shim settings because it combines linear and second-order shim terms optimized for different volumes, and (ii) significant user interactions making it rather cumbersome, time consuming, and error-prone. Here, a dedicated (“CoSpi”) shim algorithm for cortico-spinal fMRI is presented that performs joint optimization of static second-order shim terms and one set of linear and constant shim terms for each region in a single run and with minimal user interaction. Field map and T2*-weighted EPI measurements were performed on a clinical 3 T whole-body MR system in water phantoms and five healthy volunteers using the conventional region-wise and CoSpi shim settings as well as “gold standard” shim settings optimized for one of the target regions only. With CoSpi shim settings, (i) overall field inhomogeneity was reduced by about 65% / 75% (brain / spinal cord volume) compared to the conventional region-wise approach and in vivo was within 5% of the values obtained with the single-volume shim settings, (ii) geometric distortions derived from voxel displacement maps were reduced on average by about 35% / 70%, (iii) the temporal SNR determined from an EPI time series that may reflect the impact of through-slice dephasing, was increased by about 17% / 10%, and (iv) the variation of the mean field between slices, a measure targeting the predisposition to insufficient fat saturation and GRAPPA-related ghosting artifacts, was reduced by about 90% / 45%. Thus, the presented algorithm not only speeds up and simplifies the shim procedure considerably, but also provides a better field homogeneity and image quality, which both could help to significantly improve the applicability of cortico-spinal fMRI.