Skip to content

Add shellIntegrationNonce support to TerminalOptions and ExtensionTerminalOptions #253008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 30, 2025

This PR implements support for custom shell integration nonces in VS Code terminals, allowing extensions to enable shell integration features for shells that VS Code doesn't natively support.

Problem

Previously, the VSCODE_NONCE environment variable was only available for VS Code's natively supported shells (bash, zsh, pwsh, etc.). This prevented extensions like Julia from implementing shell integration features because:

  1. Shell integration injection would fail for unsupported shells
  2. No VSCODE_NONCE environment variable would be set
  3. Extensions couldn't send trusted shell integration sequences

Solution

Added a new optional shellIntegrationNonce property to both TerminalOptions and ExtensionTerminalOptions interfaces, enabling extensions to provide their own nonce for shell integration.

API Changes

export interface TerminalOptions {
  // ... existing properties
  shellIntegrationNonce?: string;
}

export interface ExtensionTerminalOptions {
  // ... existing properties  
  shellIntegrationNonce?: string;
}

Usage Example

// Extensions can now enable shell integration for any shell:
const terminal = vscode.window.createTerminal({
  name: 'Julia REPL',
  shellPath: '/usr/bin/julia',
  shellArgs: ['-i'],
  shellIntegrationNonce: 'custom-nonce-12345'
});

// The VSCODE_NONCE environment variable will be available
// in the terminal, allowing shell integration sequences:
// print("\x1b]633;A;$(ENV["VSCODE_NONCE"])\x07")

Implementation Details

  1. API Extension: Added shellIntegrationNonce to VS Code's public API
  2. Flow Implementation: Nonce passes through ExtHost → MainThread → Terminal Process
  3. Critical Fix: Modified terminal process to set VSCODE_NONCE environment variable even when shell integration injection fails for unsupported shells
  4. Security: Maintains nonce verification model while extending to all shells

Benefits

  • ✅ Extensions can implement shell integration for any shell type
  • ✅ Works with both regular terminals and pseudoterminals
  • ✅ Maintains security through nonce verification
  • ✅ Backward compatible - existing code unchanged
  • ✅ Enables rich terminal features (command detection, decorations, etc.) for custom shells

This enables extensions like Julia to provide the same shell integration capabilities that were previously only available for VS Code's natively supported shells.

Fixes #190253.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Tyriar Tyriar added this to the June 2025 milestone Jun 30, 2025
Copilot AI and others added 2 commits June 30, 2025 14:49
…n flow

Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Shell integration nonce unavailable in unknown shells and Pseudoterminal-based extension terminals Add shellIntegrationNonce support to TerminalOptions and ExtensionTerminalOptions Jun 30, 2025
@Copilot Copilot AI requested a review from Tyriar June 30, 2025 14:55
Copilot finished work on behalf of Tyriar June 30, 2025 14:55
@Tyriar Tyriar modified the milestones: June 2025, July 2025 Jun 30, 2025
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.

Shell integration nonce unavailable in unknown shells and Pseudoterminal-based extension terminals
2 participants