Skip to content

Copilot attempts writing files in windows format on linux remote host via ssh #284417

Closed as duplicate

Description

@nbuhay

VS Code Remote-SSH File Tool Path Resolution Bug

Issue Summary

GitHub Copilot Agent file editing tools fail completely in Remote-SSH workspace. Tools report success but files are never created on the remote filesystem. The workspace path is registered as \\opt\\apps\\dealer (with backslashes) instead of proper remote URI scheme, causing all file operations to be silently dropped.

Environment

Local System:

  • OS: Windows
  • VS Code Version:
  • Version: 1.107.0 (user setup)
  • Commit: 618725e
  • Date: 2025-12-10T07:43:47.883Z
  • Electron: 39.2.3
  • ElectronBuildId: 12895514
  • Chromium: 142.0.7444.175
  • Node.js: 22.21.1
  • V8: 14.2.231.21-electron.0
  • OS: Windows_NT x64 10.0.22631
  • Remote-SSH Extension Version: 0.122.0

Remote System:

  • OS: Linux
  • Connection: SSH
  • Workspace Path (actual): /opt/apps/dealer
  • Workspace Path (VS Code shows): \opt\apps\dealer (backslashes)

Extensions:

  • GitHub Copilot: Running on UI (required for Chat to function)
  • GitHub Copilot Chat: Running on UI
  • Remote-SSH: Installed

Problem Description

Symptoms

  1. All file read/write operations fail with error: "File \\opt\apps\dealer\[filename] is outside of the workspace"
  2. File creation reports false success - tools report "Successfully edited" but files don't exist on filesystem
  3. User must approve each operation - VS Code prompts "Allow edits to sensitive files? The model wants to edit files outside of your workspace"
  4. Search tools work - file_search and grep_search successfully locate files
  5. Terminal commands work - run_in_terminal with /opt/apps/dealer/ paths works perfectly

Evidence

1. File Search Works

file_search("*.md")
Results:
  \\opt\\apps\\dealer\\README.md ✓
  \\opt\\apps\\dealer\\Code_Quality_Guide.md ✓

2. File Read Fails

read_file("\\opt\\apps\\dealer\\README.md", startLine=1, endLine=10)
Error: "File \\opt\apps\dealer\README.md is outside of the workspace, and not open in an editor, and can't be read"

3. File Creation False Success

create_file("\\opt\\apps\\dealer\\.local\\test_write.txt", content="test")
Response: "The following files were successfully edited: \\opt\apps\dealer\.local\test_write.txt"

Terminal verification:
$ ls -la /opt/apps/dealer/.local/test_write.txt
ls: cannot access '/opt/apps/dealer/.local/test_write.txt': No such file or directory

4. Terminal Works

run_in_terminal("cat /opt/apps/dealer/README.md")
Result: Successfully returns file contents ✓

run_in_terminal("echo 'test' > /opt/apps/dealer/.local/terminal_test.txt")
Result: File created successfully ✓

5. Grep Search Works

grep_search(query="Dealer", includePattern="README.md")
Result: 1 match
  <match path="\\opt\\apps\\dealer\\README.md" line=1>

Root Cause Analysis

The workspace is being registered with an incorrect path format:

  • Expected: vscode-remote://ssh-remote+hostname/opt/apps/dealer/ (proper remote URI)
  • Actual: \opt\apps\dealer (backslashes, no URI scheme)

This malformed path causes:

  1. File tools cannot resolve paths to actual filesystem locations
  2. VS Code treats all file operations as "outside workspace" (security violation)
  3. File operations silently fail - tools report success but writes go nowhere
  4. Search tools work because they use different path resolution
  5. Terminal works because it directly accesses the remote filesystem

Attempted Solutions (All Failed)

1. Copilot Extension Location

❌ Tried: Set "remote.extensionKind": {"GitHub.copilot": ["workspace"], "GitHub.copilot-chat": ["workspace"]}

  • Result: Copilot Chat completely broke with timeout error
  • Reverted: Must run on "ui" for Chat to function

2. Workspace Trust

❌ Tried: Added /opt/apps/dealer to trusted folders via "Workspace Trust"

  • Result: No change - still prompts "outside workspace"

3. Folder Reopening

❌ Tried: Closed workspace, used "File > Open Folder", entered /opt/apps/dealer

  • Result: Workspace still shows as \opt\apps\dealer with backslashes

4. SSH Server Configuration

❌ Tried: Set "remote.SSH.useLocalServer": false in settings.json

  • Result: No change in path resolution

5. Window Reload

❌ Tried: "Developer: Reload Window" multiple times

  • Result: No change

6. Remote Server Restart

❌ Tried: Killed remote VS Code server process, restarted, reloaded window

  • Result: No change - path still malformed

7. Multiple Path Formats

❌ Tried: Using /opt/apps/dealer, \opt\apps\dealer, \\opt\\apps\\dealer in file operations

  • Result: All formats fail

Gemini Suggested Steps

8. VS Code Settings

❌ Tried: Explicitly set remote.SSH.remotePlatform for the host to "linux" to override incorrect OS auto-detection.

  • Result: No change - path still malformed

9. VS Code Settings

❌ Tried: Unchecked terminal.integrated.inheritEnv to prevent local Windows environment variables from leaking into the remote shell.

  • Result: Windows paths persist in $PATH despite setting change

10. Copilot Config

❌ Tried: Disabled github.copilot.chat.terminal.enabled to stop the injection of Windows-formatted debug strings.

  • Result: Semicolon-delimited Windows paths still appearing in Linux terminal

11. Remote Priority

❌ Tried: Set "GitHub.copilot": ["workspace", "ui"] to force the base extension to prioritize the Linux file system.

  • Result: Extension logic continues to default to Windows path separators ()

12. Critical Reversion

❌ Tried: Attempted to set GitHub.copilot-chat to workspace mode.

  • Result: FAILED. Copilot Chat completely broke (authentication/network timeout); strictly required reversion to ["ui"].

13. Agent Instruction

❌ Tried: Created .github/copilot-instructions.md with strict rules: "Environment is Linux; Use forward slashes only."

  • Result: Agent acknowledges instructions but still attempts replace_string_in_file using backslashes

14. Shell Cleanup

❌ Tried: Added a sanitization script to ~/.bashrc to scrub C:\ and ; (semicolons) from the $PATH using pure bash logic.

--- CLEAN PATH FROM WINDOWS POLLUTION ---

Use built-ins only so we don't rely on broken $PATH

_NEW_PATH=""

Use IFS=: to split properly by colons

OLD_IFS="$IFS"
IFS=':'
for entry in $PATH; do
# Only keep entries that use forward slashes AND don't have semicolons
case "$entry" in
\|;) ;; # Skip Windows backslashes and semicolons
*)
if [ -n "$entry" ]; then
if [ -z "$_NEW_PATH" ]; then _NEW_PATH="$entry"; else _NEW_PATH="$_NEW_PATH:$entry"; fi
fi
;;
esac
done
IFS="$OLD_IFS"

Ensure basic Linux paths are present if they were accidentally removed

for basic in /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin; do
case ":$_NEW_PATH:" in
:$basic:) ;;
*) _NEW_PATH="$_NEW_PATH:$basic" ;;
esac
done

export PATH="$_NEW_PATH"
unset _NEW_PATH

------------------------------------------

  • Result: Successfully cleaned terminal $PATH, but Copilot Agent context still appears "poisoned" by host OS

15. Session Reset

❌ Tried: Executed Remote-SSH: Kill VS Code Server on Host to clear the environment cache and force a clean reload.

  • Result: No change - path still malformed

Impact

Critical - GitHub Copilot Agent is completely non-functional for code editing in Remote-SSH workspaces.

  • Cannot create new files
  • Cannot read existing files
  • Cannot edit/refactor code
  • Cannot perform multi-file operations
  • Agent reduced to terminal-only operations

This severely limits the value of Copilot Agent for remote development workflows.

Current Workaround

Using run_in_terminal tool with shell commands (cat, echo, heredoc) for all file operations:

# Create file
cat > /path/to/file.py << 'EOF'
# Python code here

Activity

  1. added
    chat-ext-issue
    on Dec 19, 2025
  2. added and removed
    chat-ext-issue
    on Dec 19, 2025
  3. Ranjit2111 commented on Dec 22, 2025

    @Ranjit2111

    Same issue also prevalent on Remote-WSL

  4. reeered commented on Dec 25, 2025

    @reeered

    same issue

  5. ringform commented on Dec 27, 2025

    @ringform

    I'm running VS Code 1.107.1 on a Windows 10 host connecting to a Ubuntu 25.04 VM on the same machine. In my experience, GitHub Copilot has worked locally on Windows without any issues but has broken numerous times over the past year when connecting to the dev container on my VM.

    Adding these configuration options to the remote settings:

    "remote.extensionKind": {
        "GitHub.copilot": ["ui"],
        "GitHub.copilot-chat": ["ui"]
    }

    ...allows GitHub Copilot to get past this error:

    Chat took too long to get ready. Please ensure you are signed in to GitHub and that the extension GitHub.copilot-chat is installed and enabled.
    

    ... and function somewhat (e.g. getting a response back from the model). However, it can't make changes as it normally would because of the Windows/Linux path separator issue reported here.

    I've tried numerous other configuration options I've found in other GitHub issues and on Reddit, and none have solved the problem.

    Edit: the source of this issue seems to be the VM losing network connectivity. For VMware Workstation Player 17, you would need to restart the VMware NAT Service in Windows (Win+R - services.msc) and reload the window in VS Code (Ctrl+Shift+P - Developer: Reload Window) with remote.extensionKind options removed.

    IMO, GitHub Copilot should display a network issue error message rather than "Chat took too long to get ready. Please ensure you are signed in to GitHub..." which is unhelpful and misleading.

  6. added
    stale
    on Jan 5, 2026
  7. chencyu commented on Apr 16, 2026

    @chencyu

    Root Cause Analysis: Copilot File Tools Fail with Remote SSH + extensionKind: ["ui"]

    Symptom

    When Copilot extensions are forced to run on the UI (Windows) side via:

    "remote.extensionKind": {
        "GitHub.copilot": ["ui"],
        "GitHub.copilot-chat": ["ui"]
    }

    All file-manipulation agent tools (read_file, create_file, replace_string_in_file) fail in Remote-SSH workspaces (Windows local → Linux remote). Errors include:

    • "File \opt\apps\dealer\file.ts is outside of the workspace"
    • False success reports (tool says "edited" but file never appears on remote)
    • Security prompts ("Allow edits to sensitive files?")

    Meanwhile, file_search, grep_search, and run_in_terminal work normally.

    Root Cause

    The bug is a path round-trip corruption in the agent tool pipeline. Two defects combine to produce the failure:

    Defect 1: getFilePath() applies Windows fsPath to remote Linux URIs

    File: vscode-copilot-chat/src/platform/prompts/common/promptPathRepresentationService.ts (line 53)

    getFilePath(uri: Uri): string {
        if (uri.scheme === Schemas.file || uri.scheme === Schemas.vscodeRemote) {
            return uri.fsPath;  // <-- BUG: uses OS-native path format
        }
        return uri.toString();
    }

    uri.fsPath internally calls uriToFsPath() in vscode-copilot-chat/src/util/vs/base/common/uri.ts (line 645):

    export function uriToFsPath(uri: URI, keepDriveLetterCasing: boolean): string {
        let value: string;
        // ... path extraction ...
        if (isWindows) {
            value = value.replace(/\//g, '\\');  // <-- Converts ALL forward slashes to backslashes
        }
        return value;
    }

    Effect: A remote workspace URI like vscode-remote://ssh-remote+host/opt/apps/dealer becomes \opt\apps\dealer (Windows backslashes) when the extension runs on the Windows UI side. This backslash-formatted path is what the LLM sees in the system prompt:

    <workspace_info>
    I am working in a workspace with the following folders:
    - \opt\apps\dealer
    </workspace_info>
    

    The LLM consequently uses backslash paths in all tool calls.

    Defect 2: resolveToolInputPath() does not pass predominantScheme

    File: vscode-copilot-chat/src/extension/tools/node/toolUtils.ts (line 146)

    export function resolveToolInputPath(path: string, promptPathRepresentationService: IPromptPathRepresentationService): URI {
        const uri = promptPathRepresentationService.resolveFilePath(path);
        //          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        //          No predominantScheme argument → defaults to Schemas.file
        if (!uri) {
            throw new Error(`Invalid input path: ${path}. Be sure to use an absolute path.`);
        }
        return uri;
    }

    When resolveFilePath() receives \opt\apps\dealer\file.ts without a predominantScheme:

    1. Detects it as a Windows path (\ prefix on Windows → isWindowsPath = true)
    2. Calls URI.file('\opt\apps\dealer\file.ts') → produces file:///opt/apps/dealer/file.ts
    3. Since predominantScheme defaults to Schemas.file, returns a file:// URI directly

    File: vscode-copilot-chat/src/platform/prompts/common/promptPathRepresentationService.ts (line 96)

    const fileUri = URI.file(filepath);
    return predominantScheme === Schemas.file
        ? fileUri                                                    // <-- Returns file:// URI
        : URI.from({ scheme: predominantScheme, path: fileUri.path }); // Would fix scheme

    The Fatal Mismatch

    The tool then validates the URI against workspace folders in assertFileOkForTool():

    File: vscode-copilot-chat/src/extension/tools/node/toolUtils.ts (line 182)

    const normalizedUri = normalizePath(uri);          // file:///opt/apps/dealer/file.ts
    if (workspaceService.getWorkspaceFolder(normalizedUri)) {
        // Compares against vscode-remote://ssh-remote+host/opt/apps/dealer
        // file:// ≠ vscode-remote://  →  NEVER MATCHES
        return;
    }
    // ... falls through to:
    throw new Error(`File ... is outside of the workspace`);

    Scheme mismatch: file:///opt/apps/dealer/file.ts vs vscode-remote://ssh-remote+host/opt/apps/dealer → the file is always judged as "outside the workspace."

    Complete Failure Chain

    Extension runs on Windows UI side (due to extensionKind: ["ui"])
        │
        ▼
    Workspace folder URI = vscode-remote://ssh-remote+host/opt/apps/dealer
        │
        ▼  getFilePath() → uri.fsPath → uriToFsPath() replaces / with \
    LLM sees: "\opt\apps\dealer" (backslashes, no scheme, no authority)
        │
        ▼  LLM emits tool call with path "\opt\apps\dealer\file.ts"
        │
        ▼  resolveToolInputPath() → resolveFilePath(path) with default scheme="file"
    Produced URI = file:///opt/apps/dealer/file.ts  (WRONG SCHEME)
        │
        ▼  assertFileOkForTool() → workspaceService.getWorkspaceFolder(uri)
    file:// ≠ vscode-remote://  →  scheme mismatch  →  "outside workspace"
        │
        ▼
    ❌ Tool fails / silent drop / false success
    

    Why editCodeIntent Is Not Affected

    editCodeIntent has two defenses that agent tools lack:

    File: vscode-copilot-chat/src/extension/intents/node/editCodeIntent.ts (line 636)

    private _createUriFromResponsePath(path: string): URI | undefined {
        // Defense 1: Match against known working set entries by fsPath string
        // This returns the ORIGINAL URI (with correct vscode-remote scheme)
        for (const entry of this._editCodeStep.workingSet) {
            if (this.promptPathRepresentationService.getFilePath(entry.document.uri) === path) {
                return entry.document.uri;  // ← preserves vscode-remote:// scheme
            }
        }
    
        // Defense 2: Pass predominantScheme from working set
        const uri = this.promptPathRepresentationService.resolveFilePath(
            path,
            this._editCodeStep.getPredominantScheme()  // ← "vscode-remote"
        );
    }

    Agent tools (resolveToolInputPath) have neither defense.

    Why Search Tools Are Not Affected

    • file_search and grep_search use VS Code APIs (workspace.findFiles()) that operate at the URI level. They query the remote filesystem through the VS Code remote file system provider, bypassing string-to-URI conversion entirely.
    • Their results are displayed via getFilePath() (so they show backslashes in output), but the search operation itself works at the URI layer.
    • run_in_terminal executes commands directly on the remote shell, completely bypassing the path resolution pipeline.

    Why the Bug Only Manifests with extensionKind: ["ui"]

    When Copilot runs on the workspace (remote) side:

    • isWindows is false (Linux remote)
    • uri.fsPath produces /opt/apps/dealer (forward slashes)
    • URI.file('/opt/apps/dealer/file.ts') produces file:///opt/apps/dealer/file.ts
    • The workspace folder is also file:///opt/apps/dealer → schemes match, tools work

    When forced to UI (Windows) side:

    • isWindows is true
    • uri.fsPath replaces / with \
    • The reconstructed URI gets file:// scheme while workspace has vscode-remote://
    • Scheme mismatch → tools fail

    Suggested Fix

    Option A: Fix resolveToolInputPath() to pass predominantScheme

    Mirror the pattern used in editCodeIntent:

    export function resolveToolInputPath(
        path: string,
        promptPathRepresentationService: IPromptPathRepresentationService,
        workspaceService: IWorkspaceService
    ): URI {
        const predominantScheme = workspaceService.getWorkspaceFolders()[0]?.scheme;
        const uri = promptPathRepresentationService.resolveFilePath(path, predominantScheme);
        if (!uri) {
            throw new Error(`Invalid input path: ${path}. Be sure to use an absolute path.`);
        }
        return uri;
    }

    Option B: Fix getFilePath() for remote URIs

    Use uri.path (POSIX path) instead of uri.fsPath for vscode-remote URIs, so the LLM always sees correct forward-slash paths for remote workspaces:

    getFilePath(uri: Uri): string {
        if (uri.scheme === Schemas.vscodeRemote) {
            return uri.path;  // Always POSIX for remote
        }
        if (uri.scheme === Schemas.file) {
            return uri.fsPath;
        }
        return uri.toString();
    }

    Recommended: Both fixes together

    Option A alone would fix the scheme mismatch. Option B alone would fix the backslash display. Applying both ensures the LLM sees correct paths AND the round-trip preserves the correct URI scheme.

    Affected Code Paths (All Agent Tool Callers)

    Tool File Line
    ReadFileTool extension/tools/node/readFileTool.tsx 131
    CreateFileTool extension/tools/node/createFileTool.tsx 67, 161, 196
    CreateDirectoryTool extension/tools/node/createDirectoryTool.tsx 48
    AbstractReplaceStringTool extension/tools/node/abstractReplaceStringTool.tsx 157, 581
    ApplyPatchTool extension/tools/node/applyPatchTool.tsx 120, 126, 168, 295, 607, 711
    GetErrorsTool extension/tools/node/getErrorsTool.tsx 157, 228
    ViewImageTool extension/tools/node/viewImageTool.tsx 42

    I use Copilot to trace the code and analysis the root cause, hopefully helpful to development team
    The problem code lines are located in vscode-copilot-chat, not vscode

  8. vs-code-engineering commented on Nov 6, 2026

    @vs-code-engineering
    Contributor

    Thanks for the detailed report and source analysis. This is the same Remote-SSH failure tracked by #280816: Copilot is forced onto the Windows UI side, remote Linux paths are converted as local paths, file tools reject them as outside the workspace, and terminal operations still work. This report additionally documents Remote-WSL confirmations and the PromptPathRepresentationService round-trip in detail, which should remain part of that investigation.

    This issue was closed automatically as a duplicate of #280816: the VS Code sweeper proposed it and an independent second review confirmed it. If this is a different problem, reply here or reopen the issue and a maintainer will take a look.

  9. added
    *duplicate
    on Nov 6, 2026
  10. removed
    stale
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

*duplicate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions