Worms are primarily classified as decomposers, which means that they consume organic matter, including both plant and animal remains. Most common earthworms, such as Lumbricus terrestris, feed on decomposing leaves, organic material, and microorganisms found in the soil.
Though they mainly eat decaying plant matter, some species of worms also feed on dead organic material of animal origin, making them more accurately described as detritivores. Thus, worms can be considered omnivores because they eat a variety of organic materials, regardless of their plant or animal origin.
To summarize, while worms are not traditional herbivores or carnivores, they can best be categorized as omnivores due to their consumption of both plant and animal-based organic matter.