Environment variables are the silent backbone of modern development and deployment. They store secrets, API keys, configuration values, and settings that your code needs at runtime. They’re everywhere — in local builds, CI/CD pipelines, container configurations, and production deployments. Handle them well, and your systems run like clockwork. Handle them poorly, and you burn hours chasing bugs that hide in plain sight.
Mosh, a popular roaming shell, works differently than SSH. It maintains a persistent session across network changes. This means environment variables behave in ways that might differ from your normal workflows. Knowing how Mosh interacts with environment variables is the difference between a smooth session and a surprise failure.
When you start a Mosh session, environment variables don’t always transfer automatically. Unlike SSH, where you might forward LANG or PATH, Mosh requires explicit configuration to propagate variables. If you rely on them for per-session behavior — say, pointing to the right staging database or selecting specific build tools — you must set them in your shell configuration or scripts that execute on login.
A common issue happens when a developer sets an environment variable locally and expects it to be available over Mosh. Without the right setup in .bashrc, .zshrc, or .profile, those variables vanish when the session starts. This becomes critical if your deploy script, test runner, or server process relies on them.