diff --git a/crates/util/src/util.rs b/crates/util/src/util.rs index 5961089a3b228e2b76cd3225568eab298c2baf3f..9b099f04983909b55e0fc5c161fd911210e96f37 100644 --- a/crates/util/src/util.rs +++ b/crates/util/src/util.rs @@ -365,6 +365,13 @@ pub async fn load_login_shell_environment() -> Result<()> { .await .with_context(|| format!("capturing environment with {:?}", get_system_shell()))? { + // Skip SHLVL to prevent it from polluting Zed's process environment. + // The login shell used for env capture increments SHLVL, and if we propagate it, + // terminals spawned by Zed will inherit it and increment again, causing SHLVL + // to start at 2 instead of 1 (and increase by 2 on each reload). + if name == "SHLVL" { + continue; + } unsafe { env::set_var(&name, &value) }; }