diff --git a/src/poetry_plugin_shell/command.py b/src/poetry_plugin_shell/command.py index 234ac85..aa751c4 100644 --- a/src/poetry_plugin_shell/command.py +++ b/src/poetry_plugin_shell/command.py @@ -34,6 +34,14 @@ def handle(self) -> int: f"Virtual environment already activated: {self.env.path}" ) + # Only activate if not already inside a Poetry-spawned shell (avoid nesting). + if os.environ.get("POETRY_ACTIVE") == "1": + env = self.env + assert env.is_venv() + env = cast("VirtualEnv", env) + shell = Shell.get() + shell.activate(env) + return 0 self.line(f"Spawning shell within {self.env.path}")