We study an optimal investment–reinsurance problem for an insurer who faces dynamic risk constraint in a Markovian regime-switching environment. The goal of the insurer is to maximize the expected utility of terminal wealth. Here the dynamic risk constraint is described by the maximal conditional Value at Risk over different economic states. The rationale is to provide a prudent investment–reinsurance strategy by taking into account the worst case scenario over different economic states. Using the dynamic programming approach, we obtain an analytical solution of the problem when the insurance business is modeled by either the classical Cramer–Lundberg model or its diffusion approximation. We document some important qualitative behaviors of the optimal investment–reinsurance strategies and investigate the impacts of switching regimes and risk constraint on the optimal strategies.