The heterogeneity and continuous genetic adaptation of tumours complicate their detection and treatment via the targeting of genetic mutations. However, hallmarks of cancer such as aberrant protein phosphorylation and calcium-mediated cell signalling provide broadly conserved molecular targets. Here, we show that, for a range of solid tumours, a cyclic octapeptide labelled with a near-infrared dye selectively binds to phosphorylated Annexin A2 (pANXA2), with high affinity at high levels of calcium. Because of cancer-cell-induced pANXA2 expression in tumour-associated stromal cells, the octapeptide preferentially binds to the invasive edges of tumours and then traffics within macrophages to the tumour’s necrotic core. As proof-of-concept applications, we used the octapeptide to detect tumour xenografts and metastatic lesions, and to perform fluorescence-guided surgical tumour resection, in mice. Our findings suggest that high levels of pANXA2 in association with elevated calcium are present in the microenvironment of most solid cancers. The octapeptide might be broadly useful for selective tumour imaging and for delivering drugs to the edges and to the core of solid tumours.