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: