From bd30ccb0453e2be3d4e212c1fe27a6fa0fb5447a Mon Sep 17 00:00:00 2001 From: xlyoung Date: Thu, 4 Jun 2026 14:56:49 +0800 Subject: [PATCH] fix: prevent shell tool hang with pager-based commands in non-interactive mode When the shell tool runs commands like 'git diff' or 'man' in non-interactive mode, the spawned pager (usually 'less') hangs because: 1. TERM environment variable is not set, so 'less' reports 'WARNING: terminal is not fully functional' 2. The pager waits for user input that never comes Fix: - Set TERM=xterm-256color if not already set (needed for PTY emulation) - In non-interactive mode, disable pagers by setting GIT_PAGER=cat, PAGER=cat, MANPAGER=cat (prevents pager from blocking) Fixes #360 --- src/strands_tools/shell.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/strands_tools/shell.py b/src/strands_tools/shell.py index c7758770..f6d0f9e2 100644 --- a/src/strands_tools/shell.py +++ b/src/strands_tools/shell.py @@ -126,6 +126,16 @@ def execute_with_pty(self, command: str, cwd: str, non_interactive_mode: bool) - if pid == 0: # Child process try: + # Ensure TERM is set for proper terminal emulation + os.environ.setdefault("TERM", "xterm-256color") + + # Disable pagers in non-interactive mode to prevent hangs + # (e.g. git diff spawning 'less' which waits for input) + if non_interactive_mode: + os.environ.setdefault("GIT_PAGER", "cat") + os.environ.setdefault("PAGER", "cat") + os.environ.setdefault("MANPAGER", "cat") + os.chdir(cwd) os.execvp("/bin/sh", ["/bin/sh", "-c", command]) except Exception as e: