Skip to content

Copilot CLI Feedback: PowerShell Process Leak on Windows #1368

@takurooper

Description

@takurooper

Describe the bug

Copilot CLI Feedback: PowerShell Process Leak on Windows

Issue

Copilot CLI does not clean up winpty-agent and pwsh processes after tool execution on Windows, causing significant memory accumulation over time.

Environment

  • OS: Windows 11
  • Shell: PowerShell 7 (pwsh)
  • Copilot CLI: latest version
  • Terminal: Windows Terminal

Observed Behavior

When Copilot CLI executes the powershell tool, it spawns a winpty-agent → pwsh process pair for each invocation. After the tool execution completes, neither process is terminated. Over a single session, dozens of orphan processes accumulate.

Example (observed data from a single work session):

Copilot Session Duration Orphan pwsh Orphan winpty-agent Wasted Memory
Session 1 (oldest) ~3 hours 44 44 ~3,500 MB
Session 2 ~30 min 2 2 ~200 MB
Session 3 ~20 min 4 4 ~300 MB
Total 50 50 ~4,000 MB

Each orphan pwsh process consumes ~75 MB of memory and is completely idle (average CPU: 9 seconds total over 3 hours of uptime — only startup initialization).

Impact

  • Memory: 50 orphan processes × ~75 MB = ~4 GB wasted RAM
  • Process table: 100+ unnecessary processes (pwsh + winpty-agent)
  • User confusion: Resource monitoring tools show alarming process counts

Workaround

Manual cleanup of orphan processes by terminating pwsh processes whose parent is a winpty-agent spawned by a copilot process.

Affected version

0.0.406

Steps to reproduce the behavior

  1. Start Copilot CLI on Windows (copilot)
  2. Execute several prompts that trigger the powershell tool
  3. Check process tree: Get-Process -Name pwsh | Select Id, @{N='Parent';E={$_.Parent.Id}}
  4. Observe that each tool execution leaves behind a winpty-agent → pwsh pair

Expected behavior

Copilot CLI should terminate winpty-agent and pwsh processes after the associated shell session/tool execution is complete, or at minimum reuse existing shell sessions instead of spawning new ones for each tool call.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions