Keeping climate change within limits requires that most of the available carbon-based energy sources need to be abandoned underground. We study how fast and how much this transition to carbon-free energy needs to occur within a welfare-maximizing Ramsey growth model of climate change. Our model also addresses the market failure in the development of clean energy which leads to an under-provision of renewable energy, delays the transition time to the carbon-free era and reduces the amount of dirty fuels locked up in situ. Optimal policy requires an aggressive renewables subsidy in the near term and a gradually rising carbon tax which falls in long run. We also study the transition timing and the performance of recently proposed policy rules for the carbon tax.