Shape optimization of modern three-dimensional hypersonic inlets requires many geometric design parameters. Because the flow physics is complex, a Reynolds-averaged Navier–Stokes (RANS) analysis is also desirable when performing optimization. A computationally efficient means of handling many-parameter optimization with expensive cost functions is to use gradient-based searches informed by an adjoint flow solution. In this work, a discrete adjoint method for high-speed flows is documented. It is implemented in the open-source compressible-flow solver Eilmer. One difficulty with extending a hypersonic flow solver to include an adjoint solver is the differentiation of complex, nonlinear (and sometimes nondifferentiable) algorithms. Here, it is shown that difficulty can be overcome using flow Jacobians constructed with finite differences based on complex variables. The coupled flow and adjoint solvers are packaged together with a gradient-based optimizer. The flow and adjoint solvers are verified and validated for high-speed RANS analysis. The discrete adjoint method for optimization is demonstrated using the NASA P2 hypersonic inlet as a test case. The results show that the optimization method can remove an undesirable shock present in the original geometry, while achieving the desired compression ratio and improving overall performance metrics.