The spread of cancer cells between organs, a process known as metastasis, is the cause of most cancer deaths. Detecting circulating tumour cells -- a common marker for the development of metastasis -- is difficult because ex vivo methods are not sensitive enough owing to limited blood sample volume and in vivo diagnosis is time-consuming as large volumes of blood must be analysed. Here, we show a way to magnetically capture circulating tumour cells in the bloodstream of mice followed by rapid photoacoustic detection. Magnetic nanoparticles, which were functionalized to target a receptor commonly found in breast cancer cells, bound and captured circulating tumour cells under a magnet. To improve detection sensitivity and specificity, gold-plated carbon nanotubes conjugated with folic acid were used as a second contrast agent for photoacoustic imaging. By integrating in vivo multiplex targeting, magnetic enrichment, signal amplification and multicolour recognition, our approach allows circulating tumour cells to be concentrated from a large volume of blood in the vessels of tumour-bearing mice, and this could have potential for the early diagnosis of cancer and the prevention of metastasis in humans.