Agency problems limit firms' access to capital markets, curbing investment. Firms and investors seek contractual ways to mitigate these problems. What are the implications for investment? We present a theory of a firm's investment dynamics in the presence of agency problems and optimal long-term financial contracts. We derive results relating firms' investment decisions, current and past cash flows, firm size, capital structure, and dividends. Among the results, optimal investment is increasing in current and past cash flow; and optimal investment is positively serially correlated over time (after controlling for investment opportunities). These results hold for a range of agency problems. (JEL G30, G31, G32, G35, D82, D86, D92) Copyright 2007, Oxford University Press.