One tomato plant needs at least a five gallon bucket sized pot (not at first when it is a teeny baby, but will need to be up-potted to it). Some people say 15 gallon size is better. It needs to be staked or caged. And it needs full sun; it is not a windowsill plant.
I think the worm you are talking about is the hornworm?
Despite how big it is, it is surprisingly hard to spot on the plant, blends right in.
Basil around your plant may help a little, but is certainly no guarantee against them.
What helps more is to have flowers planted around your garden that have nectar in tiny florets. This includes sweet alyssum, buckwheat, dill, fennel and other carrot family plants when flowering, yarrow, tansy, chamomile, feverfew, catnip, lemon balm, and other mint family flowers, and others. These flowers attract and feed adult braconid wasps (tiny and stingless, you will probably never see them) which parasitize the hornworms. If you ever see a hornworm looking like this:
leave it alone. The white things are the cocoons of the wasp larvae. The hornworm is now dead or dying and the adult wasps will emerge from the cocoons to be the next generation.
It's late in the season for this strategy to be of use to you now, but start planting appropriate flowers now, so next season you will have lots of flowers and lots of braconids.