In this paper, we propose and study a first risk model in which the insurer may invest into a prevention plan which decreases claim intensity. We determine the optimal prevention investment for different risk indicators. In particular, we show that the prevention amount minimizing the ruin probability maximizes the adjustment coefficient in the classical ruin model with prevention, as well as the expected dividends until ruin in the model with dividends. We also show that the optimal prevention strategy is different if one aims at maximizing the average surplus at a fixed time horizon. A sensitivity analysis is carried out. We also prove that our results can be extended to the case where prevention starts to work only after a minimum prevention level threshold.