Technically I think this would be fairly straightforward. You could keep the index fund and then short the stock you believe is overvalued, to the degree it's weighted in the index fund. That would give you stock market exposure equivalent to the index without the company you don't believe in.

But I would strongly advise you to NOT DO THIS.

The above position makes it explicit that your thesis involves shorting a stock that could go through the roof in value. That emphasizes what a risk you're taking with your thesis. If your typical investment approach is to just buy index funds, then carry on just buying index funds and let the market do its work.

By the way, if SpaceX, Anthropic, OpenAI etc were to be excluded from the indices, then professional investors would just start a trade the inverse of the one I outlined above - i.e. they'd start shorting your index fund to the extent it was underweight in those companies, in order to profit off the exclusion of those tickers from it.

If you're in this for the long term (which I assume you are given this is your 401k), don't try to second-guess the market short-term.