This paper builds a dynamic capital structure model of the firm with costly external financing and long term debt, and studies the joint interactions between a firm's corporate cash policy, investment policy and strategic default risk. Investment takes the form of a real option and is both costly and irreversible. Firms hold cash both as a precaution against default and costly equity issuance, as well as to fund investment. The resulting setup is tractable, delivers the prices of equity and in closed form, and yields a number of rich insights: (i) Optimal cash and investment policies take the form of threshold rules that are a function of firm capital stock, default risk and earnings fundamentals. (ii) A rise in strategic default risk mitigates both the incentive to hold cash and the incentive to invest. This can explain why cash holdings rose more for less levered firms while investment fell for smaller, more levered firms during the crisis. (iii) The relationship between cash and capital when investing is affected by credit risk, with the cash needed to invest falling with capital for firms close to default, and rising with capital otherwise. (iv) An increase in volatility of the real option results in increased cash holdings, lower dividends and lower equity value prior to investment - contrary to the standard growth - option literature. (v) Firms with high market-to-book ratio hold less cash than other firms when far from default, but this relationship reverses as default risk rises. (vi) Optimal cash holdings as a function of capital is U-shaped and increases close to default and when the firm invests. (vii) When external financing becomes more costly, it lowers the optimal leverage choice of firms, which is consistent with the debt conservatism puzzle. Finally, the paper verifies that the predictions of the model are supported in the data.