Sensitivity analysis (SA) is the study of how the output of a mathematical model is affected by changes in the inputs. SA is widely studied, due to its many applications: uncertainty quantification, quick evaluation of close solutions, and optimization, to name but a few. In this work we show that the classic SA techniques, in particular the continuous sensitivity equation (CSE) method, cannot be used if the mathematical model is a system of hyperbolic partial differential equations (PDEs) with discontinuous solutions. The problem arises from the fact that the CSE method requires the differentiation of the state variable: if the latter is discontinuous, this in turns generates Dirac delta functions in the sensitivity. The focus of the first part of this work is to define a system of sensitivity equations valid also in case of discontinuous state: in order to do that, we add a correction term based on the Rankine-Hugoniot conditions. In the second part of this work we illustrate with some numerical tests how some classical finite volume schemes (an exact Godunov method and a Roe-type method) do not converge to the analytical solution for the sensitivity, due to the numerical diffusion: for this reason, we present an anti-diffusive numerical scheme, which provides the correct results for the sensitivity. In this work we carry out the computation in detail for the barotropic Euler equations in Lagrangian coordinates, but the approach is general and can be applied to any hyperbolic system with discontinuous solutions.