I use a hairtail screen (ultrawide) in my home, and I remote login every day from my office.
Because the screen resolution is different, I have to change the resolution every time when remote connecting and then change it back when I get back home.
I was thinking Keyboard Maestro might be able to do the work?
Sorry for the bad English. I hope my grammar is not rude.
One of the existing triggers, like Login or Wake, might be able to detect more or less when you login. Then you just have to detect if you are remote logging in. You could probably do that in a pinch by checking the results of lsof -i -n | grep ESTABLISHED. Something in there will be your remote login connection.