We apply the Symanzik improvement programme to the 4+1-dimensional local re-formulation of the gradient flow in pure SU( N) lattice gauge theories. We show that the classical nature of the flow equation allows one to eliminate all cutoff effects at O(a^2), which originate either from the discretised gradient flow equation or from the gradient flow observable. All the remaining O(a^2) effects can be understood in terms of local counterterms at the zero flow-time boundary. We classify these counterterms and provide a complete set as required for on-shell improvement. Compared to the 4-dimensional pure gauge theory only a single additional counterterm is required, which corresponds to a modified initial condition for the flow equation. A consistency test in perturbation theory is passed and allows one to determine all counterterm coefficients to lowest non-trivial order in the coupling.