Skip to content

copilot: use the shipped Copilot shim in terminals - #338927

Merged
Karthik Nadig (karthiknadig) merged 2 commits into
packaging/vscode-with-copilotfrom
karthiknadig/copilot-shim-use-shipped
Sep 30, 2026
Merged

Karthik Nadig (karthiknadig) merged 2 commits into
packaging/vscode-with-copilotfrom
karthiknadig/copilot-shim-use-shipped

Conversation

@karthiknadig

@karthiknadig Karthik Nadig (karthiknadig) commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

The extension stopped using the copilot shim that ships with VS Code. b284dd5b991 replaced the lookup of {app}/bin/copilot-shim/copilot with a copy of a local development build, taken from LOCAL_SHIM_SOURCE_PATHS, into global storage. That path is set to a developer machine on Windows and is empty on macOS and Linux. So a shipped build never found its bundled shim, and integrated terminals fell back to copilot from PATH.

Change

  • Shipped shim first: the extension looks for the shim next to the code command again (getNativeCopilotShimPath, restored with its test). When it's there, the extension uses it and removes <globalStorage>/copilotCli. That folder held the script shims from earlier versions, which terminals restored with their old PATH could still run.
  • Development fallback: when the build doesn't ship a shim (a build from source), the extension uses the development deployment in copilotCLINativeShim.ts, unchanged.
  • Docs: REQUIREMENTS.md now describes the shipped shim as the default and the global-storage copy as the fallback.

Not in this PR

Validation

  • copilotCLITerminalIntegration.spec.ts and copilotCLINativeShim.spec.ts pass (40 tests).
  • New tests cover the shipped shim with cleanup, the development fallback, and the shim path on each platform.
  • tsc --noEmit -p extensions/copilot/tsconfig.json and eslint pass on the changed files.

The extension had switched to copying a local development build into global
storage, so a shipped build ignored its bundled shim and ran copilot from PATH.
Use the shim next to the code command again, remove the script shims that
earlier versions stored in global storage, and fall back to the development
deployment only when the build doesn't ship a shim.

Co-authored-by: Copilot <[email protected]>
The terminal PATH order is changed separately.

Co-authored-by: Copilot <[email protected]>
@karthiknadig
Karthik Nadig (karthiknadig) merged commit dd98d2d into packaging/vscode-with-copilot Sep 30, 2026
3 checks passed
@karthiknadig
Karthik Nadig (karthiknadig) deleted the karthiknadig/copilot-shim-use-shipped branch September 30, 2026 20:50
@vs-code-engineering vs-code-engineering Bot added this to the 1.141.0 milestone Sep 30, 2026
Karthik Nadig (karthiknadig) added a commit that referenced this pull request Oct 5, 2026
* Use the Copilot shim that ships with VS Code in terminals

The extension had switched to copying a local development build into global
storage, so a shipped build ignored its bundled shim and ran copilot from PATH.
Use the shim next to the code command again, remove the script shims that
earlier versions stored in global storage, and fall back to the development
deployment only when the build doesn't ship a shim.

Co-authored-by: Copilot <[email protected]>

* Don't tie the development fallback test to the PATH order

The terminal PATH order is changed separately.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Karthik Nadig (karthiknadig) added a commit that referenced this pull request Oct 7, 2026
* Use the Copilot shim that ships with VS Code in terminals

The extension had switched to copying a local development build into global
storage, so a shipped build ignored its bundled shim and ran copilot from PATH.
Use the shim next to the code command again, remove the script shims that
earlier versions stored in global storage, and fall back to the development
deployment only when the build doesn't ship a shim.

Co-authored-by: Copilot <[email protected]>

* Don't tie the development fallback test to the PATH order

The terminal PATH order is changed separately.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Karthik Nadig (karthiknadig) added a commit that referenced this pull request Oct 9, 2026
* Use the Copilot shim that ships with VS Code in terminals

The extension had switched to copying a local development build into global
storage, so a shipped build ignored its bundled shim and ran copilot from PATH.
Use the shim next to the code command again, remove the script shims that
earlier versions stored in global storage, and fall back to the development
deployment only when the build doesn't ship a shim.

Co-authored-by: Copilot <[email protected]>

* Don't tie the development fallback test to the PATH order

The terminal PATH order is changed separately.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Karthik Nadig (karthiknadig) added a commit that referenced this pull request Oct 9, 2026
* Use the Copilot shim that ships with VS Code in terminals

The extension had switched to copying a local development build into global
storage, so a shipped build ignored its bundled shim and ran copilot from PATH.
Use the shim next to the code command again, remove the script shims that
earlier versions stored in global storage, and fall back to the development
deployment only when the build doesn't ship a shim.

Co-authored-by: Copilot <[email protected]>

* Don't tie the development fallback test to the PATH order

The terminal PATH order is changed separately.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Karthik Nadig (karthiknadig) added a commit that referenced this pull request Oct 13, 2026
* Use the Copilot shim that ships with VS Code in terminals

The extension had switched to copying a local development build into global
storage, so a shipped build ignored its bundled shim and ran copilot from PATH.
Use the shim next to the code command again, remove the script shims that
earlier versions stored in global storage, and fall back to the development
deployment only when the build doesn't ship a shim.

Co-authored-by: Copilot <[email protected]>

* Don't tie the development fallback test to the PATH order

The terminal PATH order is changed separately.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Karthik Nadig (karthiknadig) added a commit that referenced this pull request Oct 15, 2026
* Use the Copilot shim that ships with VS Code in terminals

The extension had switched to copying a local development build into global
storage, so a shipped build ignored its bundled shim and ran copilot from PATH.
Use the shim next to the code command again, remove the script shims that
earlier versions stored in global storage, and fall back to the development
deployment only when the build doesn't ship a shim.

Co-authored-by: Copilot <[email protected]>

* Don't tie the development fallback test to the PATH order

The terminal PATH order is changed separately.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Karthik Nadig (karthiknadig) added a commit that referenced this pull request Oct 15, 2026
…1667)

* Add native Copilot CLI shim to the Windows installer

- Publish the native `copilot` shim to {app}\bin\copilot-shim from the
  Inno Setup installer and manage its PATH entry. A new wizard page offers
  to install Copilot CLI now, on first use, or not at all.
- Support silent installs (/copilotcli=install|onfirstuse|none), a one-time
  migration for user installs with Add to PATH, the CopilotCliCommand
  policy, and uninstall cleanup. Fix the uninstall step guard.
- Copy the shim into the Windows package when the build provides it.
- Replace the Copilot extension's integrated-terminal script shims with the
  native shim, resolved next to the `code` command.

Refs microsoft/vscode-internalbacklog#9765

Co-authored-by: Copilot <[email protected]>

* Add standalone Copilot CLI shim

Add the cross-platform Rust shim, runtime tests, and independent build and signing pipeline validation.

Co-authored-by: Copilot <[email protected]>

* Updates

* Fix Copilot shim PATH discovery on Windows

Opening a directory on Windows requires FILE_FLAG_BACKUP_SEMANTICS, so reading
the file identity of every PATH entry failed with ERROR_ACCESS_DENIED and the
shim never discovered an installed Copilot CLI. Open with attribute-only access
and backup semantics instead.

Also keep test thread names, which contain `::`, out of Windows temp file names.

Co-authored-by: Copilot <[email protected]>

* Resolve Copilot shim integration blockers

- Add the leading --vscode-shim option namespace: the clear modifier and the
  info, probe and install setup commands that the Windows installer runs.
- Install GitHub's per-user Copilot CLI MSI on Windows (checksum and
  "GitHub, Inc." Authenticode verification) instead of winget, and search
  its install folder during discovery.
- Fix .cmd/.bat launches: pass cmd switches unquoted and encode the tail for
  /E:ON /V:OFF.
- Make the ConPTY tests work with redirected stdio (as in CI), and fix the
  Windows and Linux test and lint failures.
- Build the shim in the existing CLI jobs and add it to bin/copilot-shim of
  the client and server builds before they are signed, replacing the
  separate shim jobs and the Windows shim signing job.
- Update REQUIREMENTS.md for these decisions.

Co-authored-by: Copilot <[email protected]>

* Add the CopilotCliCommand policy to the Copilot shim integration

- Declare chat.copilotCliCommand.enabled, controlled by the CopilotCliCommand
  policy. The Copilot extension stops adding the native shim to integrated
  terminals, and uses copilot from PATH, when it is off.
- The shim reads the policy on Windows for every VS Code quality (a disabled
  policy in any quality wins). It still launches an installed Copilot CLI but
  never installs or updates one, and exits with code 10 instead. probe
  reports the policy and install reports a policy status.
- Setup applies the same any-quality rule and no longer reads aiDisabled from
  the probe.

policyData.jsonc still needs `npm run export-policy-data`.

Co-authored-by: Copilot <[email protected]>

* Make the Copilot shim script-friendly without a terminal

- Prompts go to stderr, and the shim only prompts when stdin and stderr are
  terminals.
- Without a terminal, a missing Copilot CLI prints a message to stderr and
  exits with 127 (command not found) instead of printing the prompt to stdout
  and exiting 0. An old Copilot CLI is launched with a warning, because a
  script can't answer the update prompt.
- Update the Unix tests for the --vscode-shim clear modifier, which they still
  passed as the removed --clear option.

Co-authored-by: Copilot <[email protected]>

* Drop the Copilot shim's minimum version check and startup probes

- Launch the first usable Copilot CLI without running it first. The 1.0.82
  minimum and the update prompt are gone; the Copilot CLI keeps itself up to
  date, and running --version before every launch cost 0.15-1 s (seconds on
  the first run after an update).
- Locate PowerShell only when discovery reaches a .ps1 candidate, instead of
  starting it on every Windows launch (about 450 ms).
- Search only the first 16 MiB of a candidate for the shim marker, instead of
  reading all of a 150 MB Copilot CLI executable.

Co-authored-by: Copilot <[email protected]>

* Publish the Copilot shim like inno_updater and leave the CLI to Copilot

- Setup publishes the shim with inno_updater's three-way rename: stage
  new_copilot.exe, rename copilot.exe to old_copilot.exe (or old_N_copilot.exe
  when an older session holds it), rename the new copy into place, and restore
  the old copy if that fails. Each step is retried for transient locks, and
  old_* copies still in use are skipped until a later install or update.
- Replace the shim only when its embedded file version changes. build.rs
  writes the version resource directly, with no new dependencies.
- Never run the MSI when Copilot CLI is already installed (its file or its
  MSI registration), and launch the MSI-installed CLI by its full path right
  after installing, since the terminal's PATH doesn't have it yet.
- Soften setup's PowerShell note to a recommendation: Copilot CLI supports
  Windows PowerShell 5.1.
- Document ownership: VS Code owns only the shim; Copilot owns the CLI, its
  PATH entry, updates, uninstall and data.

Co-authored-by: Copilot <[email protected]>

* Make copilot follow code on PATH unless the user chose otherwise

- Without the installer page, an explicit choice (the page earlier or
  /copilotcli=) is kept; otherwise copilot is added when the Add to PATH
  task for code is selected. This covers silent installs, silent
  reinstalls, background updates and interactive installs that skip the
  page, for user and system installs, including once for existing installs.
- A saved policy state isn't a choice, so lifting CopilotCliCommand=0
  brings back the default. Policy 1 means the same as not set.
- Append the shim folder so that removing it restores the user's PATH
  exactly, including a trailing separator.

Co-authored-by: Copilot <[email protected]>

* Export the CopilotCliCommand policy data

Generated with npm run export-policy-data.

Co-authored-by: Copilot <[email protected]>

* Ship the CopilotCliCommand policy in 1.141

main is now 1.141, so the policy's minimumVersion follows it. policyData.jsonc
was regenerated with npm run export-policy-data.

Co-authored-by: Copilot <[email protected]>

* Check revocation of the Copilot CLI MSI's signing chain

The shim verified the MSI's Authenticode signature with WTD_REVOKE_NONE, so a
revoked GitHub signing certificate would still be accepted. Check revocation
for the whole chain except the root. When the revocation server can't be
reached, the Windows Authenticode policy decides; by default it accepts.

Co-authored-by: Copilot <[email protected]>

* Don't read large Copilot CLI candidates to look for the shim marker

Discovery read the first 16 MiB of every candidate to find the shim marker, so
launching an installed Copilot CLI (about 150 MB) read 16 MiB on every run.
Only candidates up to 16 MiB are searched now; the shim is under 1 MB. With a
signed 30 MB candidate this saves about 60 ms per launch.

Most of the remaining startup cost in local builds is Microsoft Defender
scanning the unsigned shim on every launch; the same binary signed launches
in a few milliseconds.

Co-authored-by: Copilot <[email protected]>

* Add verbose Copilot shim diagnostics

Co-authored-by: Copilot <[email protected]>

* Simplify the installer's Copilot shim code

- Detect install progress from the shim's heartbeat instead of converting the
  UTF-16 progress file through the ANSI code page.
- Remove the system installer's HKCU PATH cleanup; VS Code never adds that
  entry.
- Replace the test-only retry override with a preprocessor define and share
  one retry loop for copying and renaming.
- Log the previous shim version, not the new one twice.
- Update the documented shim contract.

Co-authored-by: Copilot <[email protected]>

* Remove unneeded Copilot shim code and fix review findings

Correctness:
- Honor a setup cancel after the download: check before msiexec starts.
- Ctrl+C during the first-use Windows install: the install child handles
  Ctrl+C and stops at its next step, removing the partial MSI, and the parent
  waits for it instead of killing it after 250 ms. Once msiexec runs, it
  finishes and reports.
- On Unix, exec the Copilot CLI, so killing copilot by PID ends the CLI and
  signals and exit status are the CLI's.
- A PATH entry that can't be inspected no longer blocks installer tool
  discovery, and a missing current directory only skips relative entries.
- A silent install checks the registry PATH for an existing CLI, like probe.
- build.rs rejects pre-release versions, which the file version can't carry.

Encoding and locale:
- Scripts that aren't UTF-8 (OEM .cmd, UTF-16 .ps1) are candidates, not
  skipped; a UTF-8 prefix cut inside a character still classifies.
- WinHTTP errors use winhttp.dll's message text in the user's language, and
  OS errors use the system's localized message.
- The install prompt accepts full-width y from East Asian IMEs.
- PowerShell from the Microsoft Store (app execution alias) is usable.

Performance:
- Look up the four candidate names directly instead of listing every PATH
  directory, and don't inspect directories.
- Read a candidate once for both the marker and legacy checks, and not at all
  when it's larger than 16 MiB.
- Locate ComSpec only for .cmd/.bat candidates.
- The probe uses HEAD requests and skips the network when a CLI is found.

Removed: the info command, unused probe keys, installed_msi_candidate
(discovery already searches the MSI folder), launch adapters, host kinds,
unused candidate fields and error payloads, the single-variant Cancellation,
the Unix captured-probe path and its tests, the WinHTTP default-proxy
fallback, sync_all on the temporary MSI, and trivial tests.

Co-authored-by: Copilot <[email protected]>

* updates

* copilot: use the shipped Copilot shim in terminals (#338927)

* Use the Copilot shim that ships with VS Code in terminals

The extension had switched to copying a local development build into global
storage, so a shipped build ignored its bundled shim and ran copilot from PATH.
Use the shim next to the code command again, remove the script shims that
earlier versions stored in global storage, and fall back to the development
deployment only when the build doesn't ship a shim.

Co-authored-by: Copilot <[email protected]>

* Don't tie the development fallback test to the PATH order

The terminal PATH order is changed separately.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>

* Append the Copilot shim to the terminal PATH

The extension had switched to prepending the shim's folder to the integrated
terminal PATH, so the shim came before the user's own PATH. Append it again,
as Windows setup does, so a Copilot CLI already on PATH is found first.

Co-authored-by: Copilot <[email protected]>

* Copilot shim: restore Ctrl+C in the ConPTY cancellation test

A test runner started in a new process group ignores Ctrl+C, and the shim
under test inherited that, so the cancellation test exited 1 instead of 130.
Restore Ctrl+C before starting the shim, as an interactive terminal does.

Co-authored-by: Copilot <[email protected]>

* Copilot setup: say where Copilot CLI was found

Setup skips its Copilot page when Copilot CLI is already installed, which
looked like a missing page. The probe now reports the path it found, setup
logs it, and the Ready page shows "GitHub Copilot CLI: Already installed at
<path>".

Co-authored-by: Copilot <[email protected]>

* Update the Copilot shim post-install notes for the current code

SHIM_POST_INSTALL.md described the shim before the installer-only PATH and the
official-script install directory fallback existed, and referenced types that
were since removed. Keep the investigation (the transcript, why only the legacy
shim got the profile prompt, how the script picks a profile) and describe what
the shim does now.

Co-authored-by: Copilot <[email protected]>

* copilot shim: always explain why copilot stopped, and decide verbose mode (#338991)

Always explain why the Copilot shim stopped without running the CLI

With verbose mode off, several outcomes ended copilot with a nonzero exit and
no output: the policy block (10), no terminal (127), a CLI that can't start,
unsupported targets, missing installer tools, and failed installs, including
the Windows MSI install's reason. Print one line for each of these; keep
discovery, probe, and per-attempt detail as verbose diagnostics, and point to
verbose mode after a failed install.

VSCODE_COPILOT_SHIM_VERBOSE also turns on verbose mode, for scripts and other
places where the arguments can't be changed. Malformed --vscode-shim options,
which only VS Code passes, stay quiet.

Co-authored-by: Copilot <[email protected]>

* Ship the CopilotCliCommand policy in 1.142

main is now 1.142, so the policy's minimumVersion follows it.

Co-authored-by: Copilot <[email protected]>

* Declare the CopilotCliCommand policy's Agent Host status

main now requires every policy to declare how the Agent Host enforces it.
Windows setup and the copilot command read CopilotCliCommand themselves, so it
applies to shells of every session type, like the other shared editor-owned
controls.

Co-authored-by: Copilot <[email protected]>

* Copilot shim: don't create a non-UTF-8 folder in the installer PATH test

macOS file systems reject names that aren't valid UTF-8, so the test failed on
macOS with "Illegal byte sequence". installer_path keeps PATH entries
byte-for-byte whether or not they exist, so the entry no longer needs a folder.

Co-authored-by: Copilot <[email protected]>

* Copilot setup: let the keyboard reach the Learn more link (#340626)

The link on the GitHub Copilot CLI page wasn't a tab stop, so keyboard users
couldn't reach it. Tab now stops on it, and Space opens it.

Fixes microsoft/vscode-internalbacklog#9998

Co-authored-by: Copilot <[email protected]>

* Copilot shim: rewrite the download line less often (#340627)

During the first-use install, copilot rewrote its download line at every
percent, and screen readers announced each rewrite. It now shows the line when
the download starts and finishes, and otherwise at most every 5 seconds.

Fixes microsoft/vscode-internalbacklog#9999

Co-authored-by: Copilot <[email protected]>

* Copilot setup: say that Install now also adds copilot to PATH (#340760)

Only the "when I first run copilot" option said it adds copilot to PATH, so
Install now read as if it didn't. Every option's description now starts with
what it does to PATH, and Ready to Install says the same.

Install now also adds the copilot command to PATH when Copilot CLI installs,
not only when the install fails, so both install options end the same way: if
Copilot CLI is uninstalled later, copilot offers to install it again instead of
disappearing outside VS Code.

Fixes microsoft/vscode-internalbacklog#9996

Co-authored-by: Copilot <[email protected]>

* Copilot setup: read the Copilot page in order with screen readers (#340761)

Screen readers follow the window order of a page's controls, and each control
setup created was placed above the ones before it, so NVDA read the GitHub
Copilot CLI page from the bottom up. Each control now moves to the bottom of the
window order when it's created, so the window order matches the page. The Tab
order is unchanged.

Fixes microsoft/vscode-internalbacklog#10007

Co-authored-by: Copilot <[email protected]>

* Ship the CopilotCliCommand policy in 1.143

release/1.142 branched without this feature and main is now 1.143, so the
policy's minimumVersion follows it.

Co-authored-by: Copilot <[email protected]>

* Copilot shim: keep % literal in Windows script paths

cmd.exe expands %VARIABLE% even inside quotes, so a .cmd or .bat Copilot CLI
in a folder whose name contains %NAME% was launched from the wrong path. Escape
% in the script path the same way as in the arguments.

Co-authored-by: Copilot <[email protected]>

* Copilot shim: only run Copilot CLIs the current user can execute

On macOS and Linux, discovery accepted a candidate when any execute bit was
set, so a file only another user can execute was chosen and failed with
EACCES instead of moving on to the next Copilot CLI on PATH. Check execute
access for the current user with faccessat(AT_EACCESS), like a shell's PATH
search.

Co-authored-by: Copilot <[email protected]>

* Copilot shim: describe only Copilot CLI's public behavior

Remove references to Copilot CLI's private source and packaging internals from
the shim's requirements and comments. Keep the shim's own behavior: install
only where there is no Copilot CLI, and never run the MSI over one.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Don Jayamanne <[email protected]>
Co-authored-by: Don Jayamanne <[email protected]>
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants