We formulate the theory of shortcuts to adiabaticity in classical mechanics. For a reference Hamiltonian, the counterdiabatic term is constructed from the dispersionless Korteweg-de Vries (KdV) hierarchy. Then the adiabatic theorem holds exactly for an arbitrary choice of time-dependent parameters. We use the Hamilton-Jacobi theory to define the generalized action. The action is independent of the history of the parameters and is directly related to the adiabatic invariant. The dispersionless KdV hierarchy is obtained from the classical limit of the KdV hierarchy for the quantum shortcuts to adiabaticity. This correspondence suggests some relation between the quantum and classical adiabatic theorems.