This paper presents a small open economy model with capital accumulation and without commitment to repay debt. The optimal debt contract specifies debt relief following bad shocks and debt increase following good shocks and brings first order benefits if the country's borrowing constraint is binding. Countries with less capital (with higher marginal productivity of capital) have a higher debt-GDP ratio, are more likely to default on uncontingent bonds, require higher debt relief after bad shocks and pay a higher spread over treasury. Debt relief prescribed by the optimal contract following the interest rate hikes of 1980-81 is more than half of the debt forgiveness obtained by the main Latin American countries through the Brady agreements