Skip to content

[Bug]: Windows: exec tool causes console window flash when spawning commands #59362

@hyydmmhy

Description

@hyydmmhy

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

On Windows, every exec tool call causes a brief black console window (cmd) to flash on screen. This happens because the exec tool wraps all commands through powershell.exe -NoProfile -NonInteractive -Command "...", and PowerShell as a console application creates a visible console window even when windowsHide: true is set on the spawn options.

Steps to reproduce

Steps to Reproduce

  1. Run OpenClaw on Windows (tested with both openclaw gateway start and Windows Service mode)
  2. Trigger any exec tool call from an agent (e.g., running an external CLI tool)
  3. Observe a black console window briefly flashing on screen

Expected Behavior

No visible window should appear when executing commands via the exec tool.

Actual Behavior

A black cmd/console window flashes briefly on screen for every exec tool invocation.

Root Cause Analysis

In src/process/supervisor/adapters/child.ts, createChildAdapter correctly sets windowsHide: true on spawn options. However, the shell config (getShellConfig) wraps all commands through powershell.exe:

if (process.platform === "win32") return {
    shell: resolvePowerShellPath(),
    args: ["-NoProfile", "-NonInteractive", "-Command"]
};

So the actual spawn is: spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "<actual command>"], { windowsHide: true }).

windowsHide: true passes CREATE_NO_WINDOW to CreateProcess, but PowerShell is a console application (CUI subsystem), and Windows still briefly allocates and shows a console window before hiding it.

Verification

Directly spawning the target executable without the PowerShell wrapper eliminates the flash completely:

// This does NOT flash:
spawn('D:\\toolbox\\Toolbox.exe', ['cli', 'timestamp', '--datetime', '2026-04-02 10:37:00'], {
    windowsHide: true,
    stdio: ['pipe', 'pipe', 'pipe']
});

// This DOES flash:
spawn('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command',
    'D:\\toolbox\\Toolbox.exe cli timestamp --datetime "2026-04-02 10:37:00"'], {
    windowsHide: true,
    stdio: ['pipe', 'pipe', 'pipe']
});

Suggested Fix

For exec commands that don't require shell features (pipes, redirections, glob expansion, etc.), spawn the target executable directly without the PowerShell wrapper. This would:

  • Eliminate the console window flash
  • Reduce startup latency (no PowerShell overhead)
  • Reduce memory usage

For commands that do need shell features, consider using cmd.exe /c with CREATE_NO_WINDOW (which handles the flag better than PowerShell), or explore conhost.exe --headless on Windows 10+.

Environment

  • OS: Windows 10 (10.0.26200, x64)
  • Node.js: v24.12.0
  • OpenClaw: latest
  • Shell: PowerShell

Expected behavior

NOT_ENOUGH_INFO

Actual behavior

NOT_ENOUGH_INFO

OpenClaw version

latest

Operating system

Windows 10 (10.0.26200, x64)

Install method

npm

Model

claude-opus-4-6

Provider / routing chain

openclaw -> ixiaozu -> claude-opus-4-6

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingregressionBehavior that previously worked and now fails

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions