  This paper focuses on the optimal control of weak (i.e. in general non
smooth) solutions to the continuity equation with non local flow. Our driving
examples are a supply chain model and an equation for the description of
pedestrian flows. To this aim, we prove the well posedness of a class of
equations comprising these models. In particular, we prove the
differentiability of solutions with respect to the initial datum and
characterize its derivative. A necessary condition for the optimality of
suitable integral functionals then follows.
