Observations with theHerschelSpace Telescope have established that most star forming gas is organised in filaments, a finding that is supported by numerical simulations of the supersonic interstellar medium (ISM) where dense filamentary structures are ubiquitous. We aim to understand the formation of these dense structures by performing observations covering the12CO(4→3),12CO(3→2), and various CO(2–1) isotopologue lines of the Musca filament, using the APEX telescope. The observed CO intensities and line ratios cannot be explained by PDR (photodissociation region) emission because of the low ambient far-UV field that is strongly constrained by the non-detections of the [C II] line at 158μm and the [O I] line at 63μm, observed with the upGREAT receiver on SOFIA, as well as a weak [C I] 609μm line detected with APEX. We propose that the observations are consistent with a scenario in which shock excitation gives rise to warm and dense gas close to the highest column density regions in the Musca filament. Using shock models, we find that the CO observations can be consistent with excitation by J-type low-velocity shocks. A qualitative comparison of the observed CO spectra with synthetic observations of dynamic filament formation simulations shows a good agreement with the signature of a filament accretion shock that forms a cold and dense filament from a converging flow. The Musca filament is thus found to be dense molecular post-shock gas. Filament accretion shocks that dissipate the supersonic kinetic energy of converging flows in the ISM may thus play a prominent role in the evolution of cold and dense filamentary structures.