Structural complexity generally reduces predation and cannibalism rates. Although the benefits from this effect vary among environmental contexts and through time, it has been the common explanation for high species abundance in complex habitats. We hypothesized that oviposition habitat selection for structural complexity depends on the expected trophic function of the progeny. In Salamandra infraimmaculata larvae, expected trophic function is dictated by their sequence of deposition. First cohorts cannibalize later-arriving cohorts, while all compete for shared prey resources. In a mesocosm experiment, we show that gravid salamanders facing conspecific-free pools preferred structurally simple habitats (no rocks), while females facing only pools with older conspecific larvae preferred complex habitats (with rocks). Context-dependent preference of habitat complexity for managing food/safety trade-offs may be extended from classic foraging patch decisions to breeding habitat selection. These trade-offs vary with dynamic larval processes such as priority effects and ontogenetic diet shifts, potentially leading to complex maternal parturition behaviours.