Skip to content

[Windows] PowerShell tool guidance: prefer -LiteralPath for file paths (brackets are wildcards with -Path) #5340

Description

@wUEZRs

Describe the feature or problem you'd like to solve

On Windows, the agent often passes file names containing [ ] to cmdlets via -Path (the default), so PowerShell treats them as wildcards: commands fail, Test-Path returns a false negative, and Remove-Item can delete a different file.

Proposed solution

Add a line to the built-in PowerShell tool guidance, alongside the existing Windows tips (&& vs ;, no heredoc), for example:

For concrete filesystem paths, prefer -LiteralPath where supported; quoting -Path does not disable wildcard expansion ([ ] * ?). Use -Path only when wildcard matching is intentional. (This applies to source paths such as Get-Content, Set-Content, Test-Path, Remove-Item, Copy-Item, Move-Item, Rename-Item, Get-ChildItem; not to destination parameters.)

Benefit: fewer failed tool calls and retries, and it reduces the risk of acting on the wrong file (data loss with Remove-Item / Move-Item / Set-Content).

Example prompts or workflows

  1. "Rename the scans in this folder to yyyy-MM-dd format": files like scan[2].jpg fail with -Path; the agent then retries with -LiteralPath.
  2. "Delete del[2].jpg": Remove-Item -Path 'del[2].jpg' deletes del2.jpg if it exists, and the requested file stays.
  3. "Edit notes [draft].md": Set-Content -Path fails with "An object at the specified path ... does not exist".

Additional context

Repro (pwsh 7.6.9, Copilot CLI 1.0.105, Windows):

Set-Content -LiteralPath 'a[1].txt' x
Test-Path -Path 'a[1].txt'      # False (file exists)
Get-Content -Path 'a[1].txt'    # error: An object at the specified path a[1].txt does not exist...
Set-Content a1.txt y
Remove-Item -Path 'a[1].txt'    # deletes a1.txt, keeps a[1].txt

Docs: about_Wildcards and Supporting Wildcard Characters in Cmdlet Parameters / -LiteralPath.

Filed as a feature request rather than a bug: PowerShell behaves as designed; the ask is guidance for the model. No existing issue found for "LiteralPath".

Activity

  1. added theissue type on Nov 3, 2026
  2. added
    area:platform-windowsWindows-specific: PowerShell, cmd, Git Bash, WSL, Windows Terminal
    area:toolsBuilt-in tools: file editing, shell, search, LSP, git, and tool call behavior
    and removed on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:platform-windowsWindows-specific: PowerShell, cmd, Git Bash, WSL, Windows Terminalarea:toolsBuilt-in tools: file editing, shell, search, LSP, git, and tool call behavior

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions