From 6fff967b5e6551b5eae2797c20f527caa8c3ff3e Mon Sep 17 00:00:00 2001 From: Dickson Tsai Date: Sat, 17 Jan 2026 06:10:06 +0000 Subject: [PATCH] Hide subprocess terminal window on Windows On Windows, spawning a subprocess creates a visible console window by default. This change adds the CREATE_NO_WINDOW flag when spawning the Claude CLI subprocess on Windows, which hides the terminal window and improves the user experience, especially for GUI applications. The fix applies to both the main subprocess spawn in connect() and the version check subprocess in _check_claude_version(). Fixes #480 --- .../_internal/transport/subprocess_cli.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py index a4882db1..a152b263 100644 --- a/src/claude_agent_sdk/_internal/transport/subprocess_cli.py +++ b/src/claude_agent_sdk/_internal/transport/subprocess_cli.py @@ -6,6 +6,7 @@ import platform import re import shutil +import subprocess import sys import tempfile from collections.abc import AsyncIterable, AsyncIterator @@ -36,6 +37,13 @@ # Other platforms have much higher limits _CMD_LENGTH_LIMIT = 8000 if platform.system() == "Windows" else 100000 +# Platform-specific process creation flags +# On Windows, CREATE_NO_WINDOW prevents a visible console window from appearing +# when spawning the CLI subprocess, which improves UX for GUI applications +_CREATION_FLAGS = ( + subprocess.CREATE_NO_WINDOW if sys.platform == "win32" and hasattr(subprocess, "CREATE_NO_WINDOW") else 0 +) + class SubprocessCLITransport(Transport): """Subprocess transport using Claude Code CLI.""" @@ -408,6 +416,7 @@ async def connect(self) -> None: cwd=self._cwd, env=process_env, user=self._options.user, + creationflags=_CREATION_FLAGS, ) if self._process.stdout: @@ -636,6 +645,7 @@ async def _check_claude_version(self) -> None: [self._cli_path, "-v"], stdout=PIPE, stderr=PIPE, + creationflags=_CREATION_FLAGS, ) if version_process.stdout: