We develop general recursive methods to solve for optimal contracts in dynamic principal-agent environments with hidden states and hidden actions. In our baseline model, the principal observes nothing other than transfers. Nevertheless, optimal incentive-constrained insurance can be attained. Starting from a general mechanism with arbitrary communication, randomization, full history dependence, and without restrictions on preferences or technology, we show that the optimal contract can be implemented as a recursive direct mechanism. The state variable for this mechanism is a vector of utility promises conditional on realized income. However, the standard recursive formulation suffers from a curse of dimensionality which arises from the interaction of hidden income and hidden actions. The curse can be overcome by introducing judiciously chosen utility bounds for deviation behavior off the equilibrium path. Our methods generalize to environments with multiple actions and additional states, some of which may be observable, and to non-separable preferences. The key to implementing these extensions is to introduce multiple layers of off-path utility bounds.