Foraging theory suggests animals should prefer habitats with a greater density of prey, but few have investigated whether birds change foraging habitats according to short-term changes in prey abundance caused by weather. We studied a woodpecker, the northern flicker (Colaptes auratus), in which the diet is composed mainly of ants collected on the ground surface. We measured the surface density of the ant prey in 1-m2 quadrats placed in 2 habitat types that had different thermal properties: open grassland and forest. The density of ants varied according to year of the study, habitat type, date during the summer, and time of day and was strongly associated with ambient temperature. In the shaded forest habitat, ant density increased linearly with air temperatures between 6 and 28 °C. In contrast, the surface activity of ants in the open habitat exposed to sun began to decline once ground surface temperatures reached 26 °C. Ant densities were higher in the open habitat than in the shade in relatively cold conditions but were higher in the shaded forest habitat when it was hot. Using radio telemetry, we recorded the habitat use of foraging flickers and found they shifted from foraging in the open when it was cold to foraging in shaded habitats when it was hot. Flickers tracked the density of their main prey on fine spatial and short temporal scales consistent with foraging theory.