Currently optical-based techniques for in vivo microbial population imaging are limited by low imaging depth and highly light-scattering tissue; and moreover, are generally effective against only one specific group of bacteria. Here, we introduce an imaging and therapy strategy, in which different bacteria actively eat the glucose polymer (GP)-modified gold nanoparticles through ATP-binding cassette (ABC) transporter pathway, followed by laser irradiation-mediated aggregation in the bacterial cells. As a result, the aggregates display ~15.2-fold enhancement in photoacoustic signals and ~3.0-fold enhancement in antibacterial rate compared with non-aggregated counterparts. Significantly, the developed strategy allows ultrasensitive imaging of bacteria in vivo as low ~105 colony-forming unit (CFU), which is around two orders of magnitude lower than most optical contrast agents. We further demonstrate the developed strategy enables the detection of ~107 CFU bacteria residing within tumour or gut. This technique enables visualization and treatment of diverse bacteria, setting the crucial step forward the study of microbial ecosystem.