We present a new implementation of a recent open-ended response theory formulation for time- and perturbation-dependent basis sets (Thorvaldsen et al., J. Chem. Phys. 2008, 129, 214108) at the Hartree–Fock and density functional levels of theory. A novel feature of the new implementation is the use of recursive programming techniques, making it possible to write highly compact code for the analytic calculation of any response property at any valid choice of rule for the order of perturbation at which to include perturbed density matrices. The formalism is expressed in terms of the density matrix in the atomic orbital basis, allowing the recursive scheme presented here to be used in linear-scaling formulations of response theory as well as with two- and four-component relativistic wave functions. To demonstrate the new code, we present calculations of the third geometrical derivatives of the frequency-dependent second hyperpolarizability for HSOH at the Hartree–Fock level of theory, a seventh-order energy derivative involving basis sets that are both time and perturbation dependent. © 2014 Wiley Periodicals, Inc.