1. In many parts of the world, changes in agricultural land-use have led to significant declines of bird species, including aerial insectivores such as barn swallows. In particular, barn swallow populations have been declining across Europe where mixed and livestock farming have been replaced by arable farming.
2. A positive association between livestock farming and barn swallow reproductive success is well documented but the specific roles of micro- and macroenvironment, which are not mutually exclusive, remain unclear. A positive effect of livestock on swallow breeding performance might be due to improved feeding conditions associated with dung around cattle farms (macrohabitat). Barn swallows also might profit from raised and more constant temperatures at the nest site in stables housing farm animals (microhabitat).
3. We analysed data on barn swallows breeding across Switzerland to quantify the effects of livestock farming at the micro- and macrohabitat on the reproductive success of single- and double-brood pairs. We focus on the effects of nest temperature (expressed as presence of livestock) and food availability around the nest (quantified by the number of manure heaps providing large number of flies).
4. The presence of livestock in the building with the nest and large numbers of manure heaps around nest sites increased nestling survival in double-brood but not in single-brood pairs. Furthermore, the presence of livestock tended to increase the probability of pairs rearing double broods and increased the annual output of double-brood pairs by 0·8 chicks. Both factors of livestock farming combined increased the annual output by 1·6 chicks.
5. Synthesis and applications. The productivity of barn swallows depends on the characteristics of the micro- and the macrohabitat. Since changes in farming systems, grazing patterns, landscape heterogeneity and climate may have different effects on micro- and macrohabitats, respectively, they affect productivity of declining bird species in a complex way. Measures designed to enhance habitat quality in aerial insectivores should improve microclimatic conditions at the nest and increase the number of food patches providing airborne insects. In general, habitat improvements should include both spatial scales, namely suitable sites for nesting and accessible food resources on the foraging grounds.