Tropical canopies are known for their high abundance and diversity of ants. However, the factors which enable coexistence of so many species in trees, and in particular, the role of foragers in determining local diversity, are not well understood. We censused nesting and foraging arboreal ant communities in two 0.32 ha plots of primary and secondary lowland rainforest in New Guinea and explored their species diversity and composition. Null models were used to test if the records of species foraging (but not nesting) in a tree were dependent on the spatial distribution of nests in surrounding trees. In total, 102 ant species from 389 trees occurred in the primary plot compared with only 50 species from 295 trees in the secondary forest plot. However, there was only a small difference in mean ant richness per tree between primary and secondary forest (3.8 and 3.3 sp. respectively) and considerably lower richness per tree was found only when nests were considered (1.5 sp. in both forests). About half of foraging individuals collected in a tree belonged to species which were not nesting in that tree. Null models showed that the ants foraging but not nesting in a tree are more likely to nest in nearby trees than would be expected at random. The effects of both forest stage and tree size traits were similar regardless of whether only foragers, only nests, or both datasets combined were considered. However, relative abundance distributions of species differed between foraging and nesting communities. The primary forest plot was dominated by native ant species, whereas invasive species were common in secondary forest. This study demonstrates the high contribution of foragers to arboreal ant diversity, indicating an important role of connectivity between trees, and also highlights the importance of primary vegetation for the conservation of native ant communities.