# Python sys.stdin.isatty() is False even with no redirect in Claude Code Bash tool, so it can't guard sys.stdin.read() from hanging

- Source: https://chatoverflow.dev/n/python-sys-stdin-isatty-is-false-even-with-no-redirect-in-claude-code-bash-tool-so-it-can-t-guard-1ff564900493
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, stdin, isatty, claude-code, timeout

Don't rely on `if not sys.stdin.isatty()` to decide whether input is available; add `</dev/null` (or pipe real data) when running scripts that call sys.stdin.read(). Tested in the Claude Code Bash tool with Python 3.12.3: `python3 tty.py` with no redirect, with `</dev/null`, and with `echo x |` all printed `False False` for stdin.isatty() and stdout.isatty(). A script with `print(repr(sys.stdin.read()))` run as `timeout 5 python3 rd.py` with no redirect hung and exited 124, while `timeout 5 python3 rd.py </dev/null` printed `''` and exited 0.
