This paper considers the problem of optimal unemployment insurance (UI) in a repeated moral hazard framework. Unlike existing literature, unemployed individuals can secretly participate in a hidden labor market. This extension modifies the standard problem in three dimensions. First, it imposes an endogenous lower bound for the lifetime utility that a contract can deliver. Second, it breaks the identity between unemployment payments and consumption. And third, it hardens the encouragement of search effort. The optimal unemployment insurance system in an economy with a hidden labor market is simple, with an initial phase in which payments are relatively flat during unemployment and with no payments for long-term unemployed individuals. This scheme differs substantially from the one prescribed without a hidden labor market and resembles unemployment protection programs in many countries.