This article characterizes optimal unemployment insurance (UI) in an economy with endogenous negative duration dependence in hiring rates for the unemployed. The characterization generalizes the standard BailyChetty result and is independent of the particular mechanism generating endogenous hiring rates. I find that at the social optimum, UI equates the moral hazard cost with the sum of the insurance benefit and a new externality correction term. The sign of this externality correction term depends, in part, on the responsiveness of hiring rates to the UI benefit. I show how the effect of UI on hiring rates in turn depends on the particular assumptions about firm behavior, considering the cases of employer screening and human capital depreciation models.