Skip to content

fix: gracefully handle non-TTY environments#1562

Open
nazt wants to merge 1 commit intonvbn:masterfrom
Soul-Brews-Studio:fix/non-tty-graceful-fallback
Open

fix: gracefully handle non-TTY environments#1562
nazt wants to merge 1 commit intonvbn:masterfrom
Soul-Brews-Studio:fix/non-tty-graceful-fallback

Conversation

@nazt
Copy link
Copy Markdown

@nazt nazt commented Mar 25, 2026

Summary

  • Auto-select first suggestion when stdin is not a TTY (CI, subprocess capture, editor integrations like Claude Code)
  • Harden getch() to catch termios.error instead of crashing in non-terminal contexts
  • Matches existing --yeah behavior — no new flags or config needed

Problem

When thefuck runs in a non-TTY context (e.g. piped through $() in a subprocess, CI pipelines, AI coding assistants), termios.tcgetattr() in getch() crashes with:

termios.error: (25, 'Inappropriate ioctl for device')

This happens because the interactive key-reading path is reached even when there's no terminal to read from.

Changes

  • thefuck/ui.py: Added _is_interactive() TTY check in select_command(). When no TTY is detected, auto-selects the first suggestion (same behavior as --yeah)
  • thefuck/system/unix.py: Hardened getch() to catch termios.error and return '\n' (auto-select) as a defense-in-depth fallback

Test plan

  • Verified _is_interactive() returns False in subprocess context
  • Verified getch() returns '\n' instead of crashing without TTY
  • Verified full thefuck flow works in non-TTY (auto-selects first suggestion)
  • Existing interactive behavior unchanged when TTY is present

🤖 Generated with Claude Code

When thefuck runs in a non-TTY context (e.g. Claude Code, CI pipelines,
editor integrations), termios.tcgetattr() crashes because there is no
terminal to query. This change:

- Adds TTY detection in ui.select_command() to auto-select the first
  suggestion when stdin is not a terminal, matching --yeah behavior
- Hardens getch() to catch termios.error and return a newline (auto-select)
  as a safety net if the interactive path is somehow reached without a TTY

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant