From 169c237c425021afdfb7e7252bc0b1d5b6418f29 Mon Sep 17 00:00:00 2001 From: blumlaut <13604413+blumlaut@users.noreply.github.com> Date: Tue, 21 Jul 2026 10:34:32 +0000 Subject: [PATCH] fix: preserve custom env vars in multi-user mode via sudo -E --- open_terminal/utils/runner.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/open_terminal/utils/runner.py b/open_terminal/utils/runner.py index 2e63868..137d541 100644 --- a/open_terminal/utils/runner.py +++ b/open_terminal/utils/runner.py @@ -61,7 +61,10 @@ def __init__(self, command: str, cwd: str | None, env: dict | None, run_as_user: if run_as_user: # Build the inner command: optionally cd first, then run the command. inner = f"cd {shlex.quote(cwd)} && {command}" if cwd else command - command = f"sudo -u {shlex.quote(run_as_user)} -- bash -c {shlex.quote(inner)}" + # ``sudo`` resets the environment by default. ``-E`` preserves + # it so that caller-supplied env vars (e.g. ``GH_TOKEN``) actually + # reach the child process. + command = f"sudo -E -u {shlex.quote(run_as_user)} -- bash -c {shlex.quote(inner)}" cwd = None # Popen runs as parent user — can't chdir into chmod 700 dirs master_fd, slave_fd = pty.openpty() try: