We study the optimal execution problem in a principal-agent setting. A client (e.g., a pension fund, endowment, or other institution) contracts to purchase a large position from a dealer at a future point in time. In the interim, the dealer acquires the position from the market, choosing how to divide his trading across time. Price impact may have temporary and permanent components. There is hidden action in that the client cannot directly dictate the dealer’s trades. Rather, she chooses a contract with the goal of minimizing her expected payment, given the price process and an understanding of the dealer’s incentives. Many contracts used in practice prescribe a payment equal to some weighted average of the market prices within the execution window. We explicitly characterize the optimal such weights: they are symmetric and generally U-shaped over time. This U-shape is strengthened by permanent price impact and weakened by both temporary price impact and dealer risk aversion. In contrast, the first-best solution (which reduces to a classical optimal execution problem) is invariant to these parameters. Back-of-the- envelope calculations suggest that switching to our optimal contract could save clients billions of dollars per year.