Reid, I don't know how or why. I wish I did. I've read a lot about the subject of companion plantings and while I'm pretty well versed in what plants go with what plants, I can't tell you why it is the case.
What does Basil do to cause tomatoes to grow so well, and taste so good? I'll likely never understand the real reason. Same with the carrots.
But we know that borage is a dynamical nutrient accumulator, especially of calcium, something that tomatoes need for healthy fruit walls. Borage also is a powerful deterrent of the tomato horn worm. Borage also attracts pollinators as well as wasps, the latter of which can possibly attack pests attacking your tomatoes.
I can't remember the last time I saw a tomato horn worm. It's been a few years now.