If there's a reason for me to be on the front then I want to have someone on my wheel. I am going to use them later on. If there isn't a reason to be on the front, then I try to get them off my wheel or make them work.
If I am passing riders on climbs and I don't want company, I go a bit faster as I pass. That discourages them from latching on. When I catch them I may sit in for a bit then go by on a steeper part where they are struggling. The idea is to look like you're too fast for them.
This is for long climbs obviously, when everything is slow motion and riders are spread out. Normal racing isn't like this.