Windows: Hook commands cause brief console window flash
Problem
On Windows, hook commands (both SessionStart and statusLine) cause a brief console window flash when they spawn Node.js or other console applications.
This happens because the child process is spawned without the windowsHide option.
Expected Behavior
Hook commands should run invisibly without any visible window flash.
Suggested Fix
When spawning hook commands on Windows, use the windowsHide: true option in Node.js spawn/exec:
const { spawn } = require('child_process');
spawn(command, args, {
windowsHide: true, // Hides the console window on Windows, ignored on other platforms
// ... other options
});
This option is cross-platform safe - it's ignored on macOS/Linux.
Current Workarounds
- VBS wrapper (for hooks that don't need stdout):
``vbs``
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "node script.js", 0, False
- Using .cmd files - reduces but doesn't eliminate the flash
Neither workaround fully solves the problem for statusLine which requires stdout capture.
Environment
- OS: Windows 11
- Claude Code version: v2.1.12
- Shell: PowerShell
Related
This affects any Windows user with custom hooks that run console applications (Node.js, Python, etc.).
11 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Update: Findings from Testing
After testing various approaches, discovered that different hook types behave differently:
Key Finding
| Hook Type | Spawn Behavior |
node -eFlash? ||-----------|---------------|------------------|
| statusLine | stdin/stdout piped | No flash ✓ |
| SessionStart | Detached spawn | Flash on Windows ✗ |
Working Workarounds
For statusLine -
node -eworks without flash:For SessionStart on Windows - requires
mshtatrick:Request
Adding
windowsHide: trueto the spawn options for SessionStart (and other detached hooks) would:The fact that statusLine already doesn't flash suggests the infrastructure supports it - it may just need to be applied to SessionStart and similar hooks.
Related
Working solution documented in glittercowboy/get-shit-done#144
Anthropic please fix this, it's really annoying and we want to use claude-mem.
Not only do the windows flash, but the main CC window also sometimes crashes when using claude-mem.
I've found a bulletproof solution that completely eliminates the console flash without modifying Claude Code's source. Full research report with technical details: https://claude.ai/public/artifacts/0cd072dd-5e18-4362-9a5b-a184d9dde894
The Root Cause
When Claude Code spawns hooks with
child_process.spawn(..., {shell: true}), Node.js invokescmd.exevia theCOMSPECenvironment variable. The console window flash happens atCreateProcesstime—before any JavaScript executes—which is whywindowsHide: truedoesn't help.The Solution
cmd.exeand place it in a user directory (e.g.,C:\Users\<user>\.claude\cmd.exe)COMSPECto point to this wrapper before launching Claude Codecmd.exewithCREATE_NO_WINDOWflag and forwards stdio⚠️ Critical Discovery: The Wrapper MUST Be Named
cmd.exeNode.js uses this regex to detect cmd.exe:
/^(?:.*\\)?cmd(?:\.exe)?$/iIf you name it
hiddencmd.exe, Node.js will:-cinstead of/d /s /c(breaking cmd.exe syntax)Implementation
hiddencmd.cpp (compile as GUI subsystem):
Build (MSVC):
Build (MinGW-w64):
Launcher integration (set COMSPEC before launching Claude Code):
Why This Works
What Doesn't Work
| Approach | Why It Fails |
|----------|--------------|
|
windowsHide: true| Window created before option is read ||
NODE_OPTIONSpreload | Same—too late ||
nodew.exe| Can't write to stdout || Patching cli.js | Reverted on updates, still flashes |
| Job Objects | Can't enforce
CREATE_NO_WINDOWon children || PATH-based shim | Windows resolves cmd.exe from System32 first |
For me, the fix came when they updated claude-mem plugin.
Is it Claude-mem? - That actually sounds right because it happened when I installed Claude-mem. I can't remember what fixed it completely at first, but all I remember is that I put in this prompt to my AI and then it was fixed in 2 mins.
Either way there has to be a way to use Claude-mem because it didn't get that popular without it working.
It also happened before I installed Claude-mem too, it's actually funny how you mentioned that.
Oh, you got it fixed, cool.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.