Fix: Windows Console Window Suppression for GUI Applications (Issue #606)#612
Open
gspeter-max wants to merge 6 commits intoanthropics:mainfrom
Open
Fix: Windows Console Window Suppression for GUI Applications (Issue #606)#612gspeter-max wants to merge 6 commits intoanthropics:mainfrom
gspeter-max wants to merge 6 commits intoanthropics:mainfrom
Conversation
ROOT CAUSE: Windows GUI apps (no console) spawn child processes with visible console windows by default. CHANGES: - Add _should_suppress_console_window() helper function - Uses GetConsoleWindow() to detect parent console status - Returns True only on Windows when parent has no console IMPACT: Foundation for passing CREATE_NO_WINDOW flag to subprocess calls. FILES MODIFIED: - src/claude_agent_sdk/_internal/transport/subprocess_cli.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ROOT CAUSE: anyio.open_process() in connect() didn't pass CREATE_NO_WINDOW, causing visible console windows on Windows GUI apps. CHANGES: - Convert inline kwargs to dict format - Conditionally add creationflags on Windows when parent has no console - Uses _should_suppress_console_window() helper IMPACT: Windows GUI apps (PyInstaller console=False) no longer show flashing console windows when creating agent sessions. FILES MODIFIED: - src/claude_agent_sdk/_internal/transport/subprocess_cli.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ROOT CAUSE: _check_claude_version() didn't pass CREATE_NO_WINDOW, causing console window flash during version check. CHANGES: - Convert inline kwargs to dict format - Conditionally add creationflags on Windows when parent has no console - Uses _should_suppress_console_window() helper IMPACT: Windows GUI apps no longer show console flash during version check. FILES MODIFIED: - src/claude_agent_sdk/_internal/transport/subprocess_cli.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ROOT CAUSE: No tests for _should_suppress_console_window() helper function. CHANGES: - Add TestShouldSuppressConsoleWindow test class - Test non-Windows platforms return False - Test Windows with/without console using mocks - Uses pytest.mark.skipif for Windows-specific tests IMPACT: Ensures console detection logic works correctly across platforms. FILES MODIFIED: - tests/test_windows_console.py (new) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ROOT CAUSE: Need to verify CREATE_NO_WINDOW is actually passed to subprocesses. CHANGES: - Add TestWindowsSubprocessCreation integration tests - Test connect() passes creationflags when no console - Test _check_claude_version() passes creationflags when no console - Mock _should_suppress_console_window to simulate GUI app IMPACT: Confirms the fix works end-to-end on Windows. FILES MODIFIED: - tests/test_windows_integration.py (new) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ROOT CAUSE: pyright type checking issues after adding console detection. CHANGES: - Add type: ignore comments for CREATE_NO_WINDOW (Windows-only constant) - Add type: ignore comments for **kwargs expansion (pyright false positive) IMPACT: Passes static type checking. FILES MODIFIED: - src/claude_agent_sdk/_internal/transport/subprocess_cli.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
Closing - will resubmit to correct location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Windows Console Window Suppression for GUI Applications (Issue #606)
Summary
Fixes Windows GUI applications (PyInstaller
console=False) spawning visible console windows when the SDK spawnsclaude.exesubprocesses.Problem
When a Windows GUI application (no console attached) uses the Claude Agent SDK, spawning
claude.execauses Windows to automatically create a visible console window for the child process. This results in unwanted flashing console windows.Root Cause:
subprocess.Popen(called viaanyio.open_process()) on Windows withoutcreationflagsdefaults to creating a new console when the parent has none.Solution
Detect when running on Windows without an attached console, then pass
subprocess.CREATE_NO_WINDOWflag toanyio.open_process()calls. Applied to both:connect()method)_check_claude_version()method)Implementation
1. Console Detection Helper
2. Applied in Both Subprocess Locations
Main subprocess (connect method):
Version check subprocess (_check_claude_version method):
Tests Included in PR
Unit Tests (
tests/test_windows_console.py)Falseon non-Windows platformsTrueon Windows when no console (via mock)Falseon Windows when console exists (via mock)Integration Tests (
tests/test_windows_integration.py)connect()passesCREATE_NO_WINDOWwhen GUI mode detected_check_claude_version()passesCREATE_NO_WINDOWwhen GUI mode detectedVerification Code Used for Testing
Below is the comprehensive verification code used to test this fix:
How to Test on Windows
Option 1: Run the Test Suite
Option 2: Create a GUI Test App
Build with PyInstaller:
Expected: No console windows flash when spawning
claude.exeOption 3: Test with Pythonw
Verification Results
Files Changed
src/claude_agent_sdk/_internal/transport/subprocess_cli.py(+56, -8)_should_suppress_console_window()helperconnect()to passCREATE_NO_WINDOW_check_claude_version()to passCREATE_NO_WINDOWtests/test_windows_console.py(+44, new file)tests/test_windows_integration.py(+89, new file)CREATE_NO_WINDOWflag passingPlatform Notes
Related
ctypes.windll.kernel32.GetConsoleWindow()for detectionsubprocess.CREATE_NO_WINDOW(0x08000000) for suppression