So how does that play out when I work as a contractor for multiple companies which have some overlap?
There are any amount of large companies where being employed by multiple entities is either frowned upon to expressly verboten. Of course, there are also any number of companies that do no care as long as you deliver, and many that actively encourage / expect nerds to nerd out in our spare time :)
It boils down to, employee transfers IP to their consulting firm, and the firm agrees to transfer ownership of the IP for which hours were billed to produce.
IME, the firm I worked for would not bill clients for work done to our shared libraries. I'd record those hours to the firm itself, but I would still get paid the same.