Anticipatory behaviour is the expectation of a near-future event based on information processed in the past and influences an animal's tactical decisions, particularly when there are significant fitness consequences. The grass lizard (Takydromus viridipunctatus) perches on blades of grass at night which likely reduces the probability of predation by terrestrial predators such as snakes, rodents and shrews. During twilight (starting 30 min before sunrise), they move from above the grass to within grass clumps and this is thought to afford the lizard protection while reducing detection by avian predators. Here, we examined how lizards shift their behaviour as a function of visual detectability to their primary predator, the cattle egret (Bubulcus ibis). We show that the lizards shift from their perch site during twilight at the earliest time at which egrets depart communal roosts. At the same time, visual modelling shows a dramatic increase in the detectability of the lizards to the visual system of egrets. Therefore, anticipatory behaviour in response to environmental cues acts to reduce predation risk as lizards become more conspicuous and predators become more active. Grass lizard anticipatory behaviour appears to be finely tuned by natural selection to adjust to temporal changes in predation risk.