claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Windows: Console window flashing when executing tools

Open zangzongkui opened this issue 11 months ago • 2 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Description

When using Claude Code on Windows (Windows Terminal), a console window briefly flashes/appears every time a tool is executed (Bash, Grep, Glob, Read, etc.).

Environment

  • OS: Windows
  • Terminal: Windows Terminal
  • Platform: win32

Steps to Reproduce

  1. Run Claude Code on Windows
  2. Execute any command or let Claude use any tool
  3. Observe brief window flash

Expected Behavior

Tools should execute without visible window flashing.

Possible Solution

When creating child processes on Windows, use CREATE_NO_WINDOW flag or STARTUPINFO.dwFlags = STARTF_USESHOWWINDOW with wShowWindow = SW_HIDE.

Workaround

Currently using WSL as a workaround.


What Should Happen?

11

Error Messages/Logs


Steps to Reproduce

11

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.0.74

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

zangzongkui avatar Dec 20 '25 05:12 zangzongkui

I'm also experiencing this issue, and it extends beyond just tool execution.

Additional Context

The console window flashing also occurs when plugin hooks execute. For example, the claude-mem plugin registers hooks for SessionStart, UserPromptSubmit, PostToolUse, and Stop events that run node and bun commands. Each execution creates a visible console window.

What I tried (unsuccessfully)

  1. VBS wrapper with hidden window - Wrapped commands in a VBS script using WScript.Shell.Run with vbHide flag. Failed due to quote escaping issues with cmd /c.

  2. PowerShell -WindowStyle Hidden - Wrapped commands with powershell -WindowStyle Hidden -Command "...". The PowerShell window was hidden, but the spawned node.exe/bun.exe processes still created their own console windows.

Root Cause

On Windows, console applications (like node.exe, bun.exe) create console windows by default when spawned. The only reliable way to prevent this is to use the CREATE_NO_WINDOW flag when calling CreateProcess().

Environment

  • OS: Windows 11
  • Terminal: Windows Terminal
  • Claude Code with claude-mem plugin

Request

Please consider implementing CREATE_NO_WINDOW for all child process spawning on Windows, including:

  • Tool execution (Bash, Grep, etc.)
  • Plugin hook execution
  • MCP server processes

This would significantly improve the Windows user experience.

GigiTiti-Kai avatar Dec 27 '25 15:12 GigiTiti-Kai

I've recently started to experience this on windows and it's a really bad user experience. You can't do anything else while claude is running or it'll get in the way

TheDan64 avatar Jan 03 '26 23:01 TheDan64

yes , it's very annoying

EngDawood avatar Jan 11 '26 17:01 EngDawood

Hook execution also affected - critical UX impact for plugin users

User Experience Impact:

I'm experiencing this same issue with plugin hooks, not just tool execution. Every time a claude-mem plugin hook executes (SessionStart, UserPromptSubmit, PostToolUse, Stop), a Node.js console window flashes on screen, often stealing keyboard focus mid-sentence. This happens dozens of times per session and significantly disrupts workflow.

Root Cause:

The issue is in Claude Code's hook execution function (appears to be GE1() in the bundled CLI). The spawn call is missing the windowsHide option:

Current Code:

let V = spawn(command, [], {env: K, cwd: a1(), shell: true})

Required Fix:

let V = spawn(command, [], {
  env: K,
  cwd: a1(),
  shell: true,
  windowsHide: process.platform === 'win32'
})

Precedent:

This exact fix was already implemented in:

  • claude-agent-sdk-typescript (Issue anthropics/anthropic-sdk-typescript#103)
  • Standard Node.js practice for Windows subprocess spawning

Why Workarounds Don't Work:

All attempted workarounds fail because:

  • PowerShell -WindowStyle Hidden → cmd.exe spawns first before PowerShell
  • VBScript wrappers → Can't handle stdin properly (hooks need JSON input via stdin)
  • Batch files with start /b → Still creates initial cmd.exe window
  • PATH shims → Would also flash windows

The ONLY solution is fixing the spawn call at the source.

Impact Scope:

This affects:

  • ✅ All Windows users of Claude Code
  • ✅ Every tool execution (Bash, Read, Write, etc.)
  • ✅ Every plugin hook execution (SessionStart, UserPromptSubmit, PostToolUse, Stop)
  • ✅ MCP server startups via hooks

Business Impact:

For professional Windows users, this makes Claude Code nearly unusable. The constant window flashing:

  • Disrupts typing mid-sentence
  • Breaks focus during code reviews
  • Makes screen recording unprofessional
  • Prevents use in client-facing environments

Request:

Could this be prioritized for the next patch release? The fix is a one-line change that would immediately improve UX for all Windows users. I'm happy to test a beta build if that would help.

Environment:

  • OS: Windows 11 64-bit
  • Claude Code version: v2.1.2
  • Plugin: claude-mem v9.0.0
  • Terminal: PowerShell 7.x

Thank you for considering this!

thinkhalo avatar Jan 11 '26 18:01 thinkhalo

Hi team — adding an update since my duplicate report (#16880) was closed.

I can still reproduce the same “console window flash” on Windows when tools run, now on the VS Code extension as well:

  • Claude Code for VS Code extension: 2.1.11
  • OS: Windows 11
  • Where it happens: VS Code (integrated terminal / Claude panel) — every Bash/tool invocation triggers a brief node.exe/console window flash

The worst part is that the flashing window steals foreground focus while it appears. During that moment I can’t interact with VS Code (keyboard input gets interrupted / clicks can be lost), so it effectively blocks other work. This is not just distracting — it actively breaks workflow.

Could you share the current status and when you expect a fix (e.g., a target version or timeframe)? Thanks.

Assist-Frontier avatar Jan 18 '26 09:01 Assist-Frontier

This is extraordinarily disruptive when using CC on Win11. One workaround is to use an admin terminal but doing so creates its own downstream issues and shouldn't be necessary. This is seriously impacting workflow - desperate for a fix.

Update: Another workaround for those finding this really annoying; commands run by agents don't appear to trigger the flashing cmd window issue (at least for me on win11, Terminal, CC CLI, non-admin account), so if you can delegate a task via agents I recommend doing so.

jphoenix-dev avatar Jan 20 '26 07:01 jphoenix-dev

FYI I was plagued by this issue (it was immensely annoying) and finally today I got it fixed, this did the trick (note I have my git installed via scoop):

{
  "autoUpdatesChannel": "stable",
  "env": {
    "SHELL": "C:\\Users\\redacted\\scoop\\apps\\git\\2.52.0\\bin\\bash.exe"
  }
}

DamianReeves avatar Jan 25 '26 22:01 DamianReeves

Omg, please fix this - its pretty much impossible to use Claude Code in a windows env with this popup.

I may need to try @DamianReeves workaround.

Jetski5822 avatar Jan 27 '26 03:01 Jetski5822

I also suffer from this issue, and it makes Claude Code nearly unusable. I may give up usage of it entirely, or always run it on a 2nd desktop.

I experience this through CMD line Claude, as well Claude through VSCode

I had no luck attempting @DamianReeves 's workaround

blueberrynotstraw avatar Jan 29 '26 19:01 blueberrynotstraw

This is so annoying. Constantly having terminal windows flashing up when I'm working is a pain. Can we please have a fix for this?

Clinteastman avatar Feb 04 '26 12:02 Clinteastman

Same issue here. Using Claude Desktop (not CLI) on Windows 11 with working directory on WSL (\wsl.localhost\Ubuntu\home...).

Every message triggers a visible /usr/bin/bash --login -i -c cygpath -u \wsl.localhost... window for git repo detection. The window flashes briefly and steals focus, making it very disruptive.

Attempted workarounds (none worked):

Setting SHELL to cmd.exe in ~/.claude/settings.json Setting SHELL to powershell.exe Removing SHELL env entirely The windowsHide: true fix on child_process.spawn() would resolve this.

Environment:

Windows 11 Claude Desktop (latest) Git for Windows installed (C:\Program Files\Git\cmd\git.exe) Working directory: WSL Ubuntu via \wsl.localhost\

jarrieta86 avatar Feb 10 '26 21:02 jarrieta86

Also experiencing the same issue here, rendering Claude Code incredibly tedious to use. Using Claude Code CLI (native installer) on Windows 11

Every Bash tool execution spawns a visible Git Bash window (/usr/bin/bash --login -i -c) that flashes open and closed. The window steals focus mid-typing, making the experience very disruptive.

Attempted workarounds (none worked):

  • Setting CLAUDE_CODE_SHELL to powershell in ~/.claude/settings.json
  • Setting CLAUDE_CODE_SHELL to pwsh (PowerShell Core, freshly installed)
  • Setting Windows Terminal as default terminal app
  • Launching Claude Code from pwsh instead of default terminal

The windowsHide: true fix on child_process.spawn() would resolve this.

Environment:

  • Windows 11 Enterprise 10.0.26100
  • Claude Code native installer (~/.local/bin/claude.exe)
  • Git for Windows installed (AppData\Local\Programs\Git)
  • PowerShell Core installed
  • Windows Terminal as default terminal

rsparacia avatar Feb 17 '26 16:02 rsparacia

Regression: not present in 2.1.42, confirmed in 2.1.47

This issue appears to be a regression introduced between v2.1.42 and v2.1.47. On v2.1.42, no CMD window flashing or focus stealing occurs during tool execution. On v2.1.47, every tool call spawns a visible console window that steals keyboard focus.

Timing aligns with the new "session environment" / shell snapshotting mechanism introduced in v2.1.45, which also caused other Windows regressions (#26481, #26610, #26746). The new shell mechanism likely changed how child processes are spawned, dropping the windowsHide flag or spawning via a different code path that doesn't suppress console windows.

Environment:

  • OS: Windows 11 (MSYS2 / Git Bash)
  • Terminal: Windows Terminal
  • Working version: v2.1.42
  • Broken version: v2.1.47

ilude avatar Feb 19 '26 16:02 ilude

This issue appears to have been fixed, at least for me (Win 11, CC CLI, v2.1.50 but v2.1.47 also worked) - CC is saying it can see windowsHide: true" in the bash shell spawn and I'm not getting flashing cmd windows on tool usage on my non-admin user account. Can't see anything in the changelog, but great its addressed.

Edit: worth noting I'm still on the original npm version of CC CLI, not the new "native" install approach, in case that makes a difference.

jphoenix-dev avatar Feb 23 '26 12:02 jphoenix-dev

Linking this here: https://github.com/anthropics/claude-code/issues/28138#issuecomment-3959696822

Is this going to get addressed? I am stuck on 2.1.42 which seems to be the last working version before this bug was introduced!

I dug into it and here is what I can tell based on the available info to the public:

Windows: Console window flashing regression introduced in v2.1.45

Since v2.1.45, every tool call, hook execution, and MCP server startup on Windows spawns a visible cmd.exe/conhost.exe window that flashes on screen and steals keyboard focus. v2.1.42 is the last version without this behavior.

This has been reported independently by many users across 14+ issues over the past two months with no official response. Posting this as a consolidated comment with root cause analysis to hopefully get some traction.

What happens

When Claude Code executes any tool (Bash, Grep, Glob, Read, etc.), runs a hook, or starts an MCP server, a black console window briefly appears and steals keyboard focus. If you're typing in another application, keystrokes get swallowed. If you have hooks running on every prompt or tool call, the flashing is nearly continuous. It makes Claude Code effectively unusable on Windows without pinning to v2.1.42.

Root cause analysis

The regression aligns precisely with the introduction of the session environment / shell snapshotting mechanism in v2.1.45. Here's the evidence:

  1. v2.1.27 originally fixed console window flashing by adding windowsHide: true to child_process.spawn() calls
  2. v2.1.45 introduced shell snapshotting — a mechanism that captures and replays the user's shell environment. This created new spawn call sites that don't carry the windowsHide: true fix from v2.1.27
  3. The error message "Session environment not yet supported on Windows" (#26610) confirms the feature shipped without full Windows support
  4. The onecmd leak in $SHELLOPTS (#26481) shows the snapshotting mechanism uses bash -o onecmd to capture environment, and this flag leaks into user sessions
  5. Technical investigation in #27115 confirmed that windowsHide: true IS set in 12 places in the binary, but the ConPTY/SEA binary context causes conhost.exe allocation anyway — the new spawn paths introduced by shell snapshotting likely bypass or override these settings

Additional changes in v2.1.45 that may contribute:

  • "Propagating API provider environment variables to tmux-spawned processes" — if env construction was refactored, spawn options may have been lost
  • "Improved memory usage for shell commands that produce large output" — likely touched spawn call sites

v2.1.47 made things worse with "Fixed hooks silently failing on Windows by using Git Bash instead of cmd.exe" (#25981), which created yet another spawn path. That same version also introduced hook path mangling on Windows (#26746) where backslash separators get stripped.

Related issues

Primary reports:

  • #14828 — Console window flashing when executing tools (9 👍, 13 comments, open since Dec 2025)
  • #27115 — Plugin hooks spawn visible cmd.exe/conhost.exe despite windowsHide:true
  • #28138 — Bash commands spawn visible black console windows
  • #20814 — Constant console window popups and zombie node.exe processes
  • #19391 — Windows popup issue

Duplicate/related reports:

  • #19012 — Hook commands cause brief console window flash (contains COMSPEC wrapper workaround)
  • #17230 — Feature request: add windowsHide option for hooks
  • #16880 — Console window flashes on every Bash tool execution (closed as dup)
  • #15572 — Console windows flash, missing windowsHide option (closed as dup)
  • #24708 — MCP stdio servers flash visible CMD windows (closed as dup)
  • #26440 — Bash popup at startup due to -i flag in cygpath call (closed as dup)
  • #21375 — Bun console window appears when starting Claude Code
  • #23229 — Persistent bun.exe terminal window with EPERM error

Same-root-cause regressions from v2.1.45:

  • #26481 — Bash tool returns exit code 1 (onecmd in SHELLOPTS)
  • #26610 — "Session environment not yet supported on Windows"
  • #26746 — Hook paths broken (backslash stripping)

Workarounds

Workaround Effectiveness
Pin to v2.1.42 + DISABLE_AUTOUPDATER=1 Fully works, but stuck on old version
Custom COMSPEC wrapper (details in #19012) Fully works, requires compiling a C++ GUI-subsystem exe
Set CLAUDE_CODE_GIT_BASH_PATH to C:\Program Files\Git\bin\bash.exe Works for some users
Use WSL instead of native Windows Works but changes the whole workflow
Disable plugin hooks (claude-mem, etc.) Reduces frequency but doesn't eliminate

What a fix probably looks like

Based on community investigation, the fix needs to ensure windowsHide: true (or the Win32 CREATE_NO_WINDOW flag) is set on all child_process.spawn() and child_process.exec() calls — including the ones introduced by the shell snapshotting mechanism in v2.1.45 and the hook execution path changed in v2.1.47. The MCP SDK also has a bug where windowsHide is conditional on "type" in process which only returns true in Electron, so it's effectively always false in Node.js (#24708).

Environment

  • Windows 11 (also reported on Windows 10)
  • Claude Code v2.1.45+ (last working: v2.1.42)
  • Affects: CLI (VS Code extension and Claude Desktop also reported in some issues but unverified)
  • Terminals tested: Windows Terminal, VS Code integrated terminal, cmd.exe, PowerShell

ilude avatar Feb 25 '26 19:02 ilude

cmd-exe-hydra.png — cut off one window, two more shall take its place

Tell me you don't use windows to develop claude code without saying you don't use windows!

Just try opening the start menu or typing while this is going on....

ilude avatar Feb 25 '26 20:02 ilude

Update: Narrowed down the hook-specific flashing on v2.1.59 (npm). Internal tool calls do not flash with hooks disabled — the regression appears to be specifically on the hook execution spawn path where windowsHide/CREATE_NO_WINDOW was lost in v2.1.45+.

Any hook command that spawns a separate Windows console-subsystem binary (like uv.exe or uvw.exe) triggers a visible conhost.exe window. Commands that run inside the existing bash process (echo, python) do not flash. This is consistent with v2.1.42 working — the hooks called uv run on both versions, but v2.1.42 suppressed the console allocation.

Workaround: use bare python instead of uv run in hook commands.

Full testing details: #28138 comment.

ilude avatar Feb 26 '26 15:02 ilude

A fix is available as a Claude Code plugin: powershell-default

Install:

/plugin marketplace add cruzlauroiii/claude-code
/plugin install powershell-default@cruzlauroiii-plugins

Adds a native Pwsh tool (shows as Pwsh(...) in the UI). Commands use PowerShell syntax directly. When enabled, Bash tool is blocked. Works on any OS with PowerShell 7+.

PR: https://github.com/anthropics/claude-code/pull/35761

cruzlauroiii avatar Mar 18 '26 14:03 cruzlauroiii

Additional data: Procmon analysis reveals burst spawns on session start

Environment: Windows 11 Enterprise 10.0.26200, Claude Code 2.1.78, Claude Desktop

Finding: The problem is not just the 10s polling — it's burst spawns

Using Process Monitor (Sysinternals), I captured all Process Create events from Claude.exe. Two distinct patterns:

1. Background polling (always present, minor annoyance)

Claude.exe (PID 29504) runs git status --porcelain every 10 seconds. Each spawns git.exe → conhost.exe (-ForceV1) → git.exe (mingw64). This is 3 processes × 6/min = ~18 console windows per minute.

2. Session/dialog start burst (the real problem — ~20 windows at once)

When a new session or conversation starts, Claude fires a burst of 10-15 processes within ~500ms:

0:08:37,019  git status --porcelain
0:08:37,034  git --version
0:08:37,058  git rev-parse --verify HEAD
0:08:37,182  gh auth status --hostname github.com
0:08:37,293  git rev-parse --verify origin/main
0:08:37,372  git merge-base origin/main HEAD
0:08:37,446  git rev-list --left-right --count origin/main...HEAD
0:08:37,516  git diff --numstat -M <commit>
0:08:37,524  git diff --no-ext-diff -M --no-color <commit>
0:08:37,532  git diff --name-status -M <commit>

Then seconds later:

0:08:58,336  claude.exe plugin marketplace list --json
0:08:58,463  git status --porcelain
0:08:58,512  gh auth status --hostname github.com
0:08:59,452  claude.exe plugin marketplace update claude-plugins-official

And from a child Claude.exe (PID 40412):

0:09:25,440  cmd.exe /c "python --version"
0:09:25,557  cmd.exe /c "python --version"
0:09:25,605  cmd.exe /c "python --version"
0:09:25,664  cmd.exe /c "python --version"
0:09:25,703  cmd.exe /c "python --version"

5× python --version checks in 260ms!

Summary

Pattern Frequency Processes per burst Visual impact
git status polling Every 10s 3 (git→conhost→git) 1 flash
Session start On new dialog ~15-20 ~20 simultaneous flashes
Plugin checks On session start 5-7 5-7 flashes
Python version probe On session start 5 5 flashes

Important: disabling all hooks does NOT fix this

I disabled all project hooks (SessionStart, PreToolUse, PostToolUse) and all plugin hooks (hookify, context-mode, security-guidance). The flashing persists — it's caused by Claude Code's own internal subprocess spawns, not by user hooks.

Suggested priorities

  1. All internal spawn()/execFile() calls for git, gh, python, and claude.exe subprocesses need windowsHide: true (or CREATE_NO_WINDOW)
  2. The python --version probe running 5 times is likely a bug — should be cached after first check
  3. Consider batching the session-start git queries or running them sequentially to reduce the simultaneous window count

kamiletar avatar Mar 20 '26 21:03 kamiletar

Still experiencing this on v2.1.87 (Windows 11, Git Bash shell).

Impact: Every hook execution (PreToolUse, PostToolUse, Stop, SessionStart) spawns node.exe via child_process without windowsHide: true, causing a visible terminal flash. MCP stdio servers using npx also flash at session start.

What we've done to mitigate (but can't fully fix):

  • Consolidated 7 hooks into 2 unified scripts (~60% fewer spawns per tool call)
  • Removed Read from PreToolUse matcher (~50% fewer hook invocations)
  • Merged 3 Stop hooks into 1 (sound + dream + kanban in one script)
  • Pre-installed MCP packages globally to reduce npx download time
  • Removed unused MCP servers

What's still flashing: Every remaining hook spawn (2 per Edit/Write/Bash, 1 per Stop, 1 per SessionStart) and MCP stdio server connections at boot.

The fix we need: windowsHide: true on all child_process.spawn() calls for hooks and MCP stdio servers on Windows. This is a one-line fix per spawn call.

Elie-Simard avatar Mar 29 '26 15:03 Elie-Simard