The shapes of most bacteria are imparted by the structures of their peptidoglycan cell walls, which are determined by many dynamic processes that can be described on various length scales ranging from short-range glycan insertions to cellular-scale elasticity1–11. Understanding the mechanisms that maintain stable, rod-like morphologies in certain bacteria has proved to be challenging due to an incomplete understanding of the feedback between growth and the elastic and geometric properties of the cell wall3,4,12–14. Here, we probe the effects of mechanical strain on cell shape by modelling the mechanical strains caused by bending and differential growth of the cell wall. We show that the spatial coupling of growth to regions of high mechanical strain can explain the plastic response of cells to bending4 and quantitatively predict the rate at which bent cells straighten. By growing filamentous Escherichia coli cells in doughnut-shaped microchambers, we find that the cells recovered their straight, native rod-shaped morphologies when released from captivity at a rate consistent with the theoretical prediction. We then measure the localization of MreB, an actin homologue crucial to cell wall synthesis, inside confinement and during the straightening process, and find that it cannot explain the plastic response to bending or the observed straightening rate. Our results implicate mechanical strain sensing, implemented by components of the elongasome yet to be fully characterized, as an important component of robust shape regulation in E. coli.