The worm algorithm samples the XY model by growing and shrinking a worm (open-path defect) on the lattice. At criticality, worms span the system — a signature of the Berezinskii-Kosterlitz-Thouless transition.