How do you find those teams and that work... or is it a matter of those companies finding you because of your open source work? For example, Google hiring Robert Griesemer, Rob Pike, and Ken Thompson to create Go?
After you've built up credibility in some interesting tech, other companies would find you based on your work.
This is just my observation, so take it with a grain of salt
In my career I built trust internally and so got interesting work. I talked about that work and so got approached about other jobs, and I’ve been able to move when I’ve wanted to because I’ve kept in contact with some former colleagues.
I would however like to stress that the most important point of this is doing the aork, and doing it well. If you don’t do that then everything else is pointless.