Given an open set \(T\subset [-1,1)\) , we introduce the concepts of T-avoiding spherical codes and designs, that is, spherical codes that have no inner products in the set T. We show that certain codes found in the minimal vectors of the Leech lattice, as well as the minimal vectors of the Barnes–Wall lattice and codes derived from strongly regular graphs, are universally optimal in the restricted class of T-avoiding codes. We also extend a result of Delsarte–Goethals–Seidel about codes with three inner products \(\alpha , \beta , \gamma \) (in our terminology \((\alpha ,\beta )\) -avoiding \(\gamma \) -codes). Parallel to the notion of tight spherical designs, we also derive that these codes are minimal (tight) T-avoiding spherical designs of fixed dimension and strength. In some cases, we also find that codes under consideration have maximal cardinality in their T-avoiding class for given dimension and minimum distance.