This is by design. Each command is started in a separate SSH channel, so the previous commands won’t affect the next ones. This is by design as otherwise unforeseen side effects from some commands executed early could cause very hard-to-diagnose bugs later.