This paper studies the optimal design of corporate taxes when firms have private information about future investment opportunities and face financial constraints. A government whose goal is to efficiently raise a given amount of revenue from its corporate sector should attempt to tax unconstrained firms, which value resources inside the firm less than financially constrained firms. We show that a corporate payout tax (a tax on dividends and share repurchases) can both separate constrained and unconstrained firms and raise revenue, and is therefore optimal. Our quantitative analysis implies that a revenue-neutral switch from profit taxation to payout taxation would increase the overall value of existing firms and new entrants by 7%. This switch could be implemented in the current U.S. tax system by making retained earnings fully deductible.