From 1a07352034cc9fe43faf71f182832d2a5adb671e Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Tue, 29 Jul 2025 00:59:16 +0200 Subject: [PATCH] Fix broken shell configuration imposed by Claude Code (sets COMSPEC to Git-Bash on Windows) --- src/serena/agent.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/serena/agent.py b/src/serena/agent.py index fe6a9091..66394d62 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -181,6 +181,8 @@ class SerenaAgent: log.info("Available projects: {}".format(", ".join(self.serena_config.project_names))) log.info(f"Loaded tools ({len(self._all_tools)}): {', '.join([tool.get_name_from_cls() for tool in self._all_tools.values()])}") + self._check_shell_settings() + # determine the base toolset defining the set of exposed tools (which e.g. the MCP shall see), # limited by the Serena config, the context (which is fixed for the session) and JetBrains mode tool_inclusion_definitions: list[ToolInclusionDefinition] = [self.serena_config, self._context] @@ -225,6 +227,16 @@ class SerenaAgent: except Exception as e: log.error(f"Error activating project '{project}' at startup: {e}", exc_info=e) + def _check_shell_settings(self) -> None: + # On Windows, Claude Code sets COMSPEC to Git-Bash (often even with a path containing spaces), + # which causes all sorts of trouble, preventing language servers from being launched correctly. + # So we make sure that COMSPEC is unset if it has been set to bash specifically. + if platform.system() == "Windows": + comspec = os.environ.get("COMSPEC", "") + if "bash" in comspec: + os.environ["COMSPEC"] = "" # force use of default shell + log.info("Adjusting COMSPEC environment variable to use the default shell instead of '%s'", comspec) + def _ide_context_tool_inclusion_definitions(self, project_root_or_name: str | None) -> list[ToolInclusionDefinition]: """ In the IDE assistant context, the agent is assumed to work on a single project, and we thus