๐Ÿ› Running Textual/TUI apps with run_in_background=true breaks terminal state

Resolved ๐Ÿ’ฌ 3 comments Opened Nov 11, 2025 by JuanCS-Dev Closed Nov 15, 2025

Problem Description

When Claude Code runs a Textual/TUI application using the Bash tool with run_in_background=true, it permanently breaks the terminal state, making the IDE unusable.

Steps to Reproduce

  1. Have Claude Code run a Textual app (e.g., python3 app_textual.py)
  2. Use run_in_background=true parameter in Bash tool
  3. Terminal enters broken state with mouse tracking enabled
  4. All mouse movements generate escape sequences like: <0;56;13M<0;56;13m

Technical Details

What happens:

  • Textual apps activate alternate screen mode: \033[?1049h
  • Enable mouse tracking: \033[?1000h, \033[?1003h, \033[?1015h, \033[?1006h
  • When run in background, these terminal modes remain active
  • Terminal becomes permanently broken until manual reset

Impact:

  • User cannot type normally
  • Mouse generates garbage characters
  • IDE becomes unusable
  • Requires terminal restart or manual stty sane + reset

Proposed Solutions

Option 1: Detect TUI apps

  • Add heuristic to detect TUI/fullscreen apps
  • Warn Claude before using run_in_background=true
  • Suggest interactive execution instead

Option 2: Automatic cleanup

  • Add cleanup handler to BashOutput tool
  • Automatically send reset sequences when reading from TUI background process
  • Restore terminal state after background job completion

Option 3: Documentation

  • Add explicit warning in Bash tool documentation
  • Provide examples of what NOT to do
  • Suggest alternatives for testing UI apps

Workaround for Users

When terminal is broken:

stty sane
tput reset
printf '\033[?1049l\033[?25h\033[?1000l\033[?1003l\033[?1015l\033[?1006l'

Or simply: close the terminal tab and open a new one.

Environment

  • OS: Linux (Ubuntu)
  • Terminal: Claude Code integrated terminal
  • Affected tools: Bash with run_in_background=true
  • Affected apps: Any TUI framework (Textual, curses, py_cui, etc.)

Additional Context

This is a critical UX issue that makes Claude Code temporarily unusable. It would be great to have either:

  1. Automatic detection and prevention
  2. Automatic cleanup/recovery
  3. Clear warnings in the tool documentation

Related frameworks affected:

  • Textual
  • py_cui
  • curses
  • npyscreen
  • blessed
  • asciimatics
  • Any app using alternate screen buffer

View original on GitHub โ†—

This issue has 3 comments on GitHub. Read the full discussion on GitHub โ†—