๐ 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
- Have Claude Code run a Textual app (e.g.,
python3 app_textual.py) - Use
run_in_background=trueparameter in Bash tool - Terminal enters broken state with mouse tracking enabled
- 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:
- Automatic detection and prevention
- Automatic cleanup/recovery
- Clear warnings in the tool documentation
Related frameworks affected:
- Textual
- py_cui
- curses
- npyscreen
- blessed
- asciimatics
- Any app using alternate screen buffer
This issue has 3 comments on GitHub. Read the full discussion on GitHub โ