Skip to content

Inject environment variables into existing terminals on activation#4

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/ensure-env-vars-in-terminals
Draft

Inject environment variables into existing terminals on activation#4
Copilot wants to merge 5 commits intomainfrom
copilot/ensure-env-vars-in-terminals

Conversation

Copy link

Copilot AI commented Feb 12, 2026

Environment variables were only applied to terminals created after extension activation via environmentVariableCollection. Pre-existing terminals remained unaware of PLANNOTATOR_BROWSER and PLANNOTATOR_VSCODE_PORT.

Changes

  • Shell detection: Infer shell type from terminal.creationOptions.shellPath or platform defaults (PowerShell on Windows, bash elsewhere)

  • Command injection: Send shell-specific export commands to existing terminals via terminal.sendText():

    • bash/zsh: export VAR="value"
    • PowerShell: $env:VAR="value"
    • cmd.exe: set VAR=value
  • Dual strategy: environmentVariableCollection for new terminals (unchanged), sendText() for existing terminals

  • Logging: All injection operations logged to Plannotator output channel

Implementation

function detectShellType(terminal: vscode.Terminal): "bash" | "powershell" | "cmd" {
  const shellPath = terminal.creationOptions.shellPath?.toLowerCase();
  if (shellPath?.includes("powershell") || shellPath?.includes("pwsh")) return "powershell";
  if (shellPath?.includes("cmd")) return "cmd";
  if (shellPath?.includes("bash") || shellPath?.includes("zsh")) return "bash";
  return process.platform === "win32" ? "powershell" : "bash";
}

function injectEnvVarsIntoAllTerminals(envVars: Record<string, string>): void {
  for (const terminal of vscode.window.terminals) {
    const shellType = detectShellType(terminal);
    for (const [key, value] of Object.entries(envVars)) {
      const command = shellType === "powershell" ? `$env:${key}="${value}"`
                    : shellType === "cmd" ? `set ${key}=${value}`
                    : `export ${key}="${value}"`;
      terminal.sendText(command, true);
    }
  }
}

Called once during activate() after setting up IPC server and environmentVariableCollection.

Original prompt

This section details on the original issue you should resolve

<issue_title>Ensure environment variables are passed to existing terminals</issue_title>
<issue_description>## Summary

Environment variables set by the extension should be propagated to already-open terminals, not just newly created ones.

Problem

When the extension sets environment variables (e.g., for hook configuration or plan context), these may only be available in terminals opened after the extension activates. Pre-existing terminals do not receive the updated environment variables, which can lead to inconsistent behavior.

Expected Behavior

  • Environment variables should be injected into all open terminal instances, not just new ones
  • When env vars change (e.g., plan context updates), existing terminals should reflect the updated values

Acceptance Criteria

  • Env vars are propagated to terminals that were open before extension activation
  • Env var updates are reflected in existing terminals when values change
  • No terminal restart should be required for env vars to take effect</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits February 12, 2026 08:11
Co-authored-by: 7tg <20913374+7tg@users.noreply.github.com>
…nals

Co-authored-by: 7tg <20913374+7tg@users.noreply.github.com>
…tion

Co-authored-by: 7tg <20913374+7tg@users.noreply.github.com>
Co-authored-by: 7tg <20913374+7tg@users.noreply.github.com>
Copilot AI changed the title [WIP] Ensure environment variables are passed to existing terminals Inject environment variables into existing terminals on activation Feb 12, 2026
Copilot AI requested a review from 7tg February 12, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure environment variables are passed to existing terminals

2 participants