Skip to content

fix: prevent shell tool hang with pager-based commands in non-interactive mode#494

Open
xlyoung wants to merge 1 commit into
strands-agents:mainfrom
xlyoung:fix/shell-pager-hang
Open

fix: prevent shell tool hang with pager-based commands in non-interactive mode#494
xlyoung wants to merge 1 commit into
strands-agents:mainfrom
xlyoung:fix/shell-pager-hang

Conversation

@xlyoung
Copy link
Copy Markdown

@xlyoung xlyoung commented Jun 4, 2026

Problem

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 → less reports WARNING: terminal is not fully functional
  2. The pager waits for user input that never comes → command hangs until timeout

Root Cause

In execute_with_pty(), the child process doesn't set TERM or disable pagers:

if pid == 0:  # Child process
    os.chdir(cwd)
    os.execvp("/bin/sh", ["/bin/sh", "-c", command])  # TERM not set, pagers enabled

Fix

  1. Set TERM=xterm-256color if not already set (needed for PTY emulation)
  2. In non-interactive mode, disable pagers by setting GIT_PAGER=cat, PAGER=cat, MANPAGER=cat
if pid == 0:
    os.environ.setdefault("TERM", "xterm-256color")
    if non_interactive_mode:
        os.environ.setdefault("GIT_PAGER", "cat")
        os.environ.setdefault("PAGER", "cat")
        os.environ.setdefault("MANPAGER", "cat")

Testing

All 30 shell tests pass.

Fixes #360

…tive 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 strands-agents#360
@xlyoung xlyoung requested a deployment to manual-approval June 4, 2026 06:57 — with GitHub Actions Waiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Shell tool hangs with "terminal is not fully functional" for pager-based commands

1 participant