fix: Claude Code TUI falls back to non-interactive mode in cmux (no PTY allocated) (#4001)
Closed
MO
6mo ago+176+176+012345678901234567890123456789-4-4-0123456789
# Summary
- Wrap
exec "$REAL_CLAUDE"calls inResources/bin/claudewith/usr/bin/script -q /dev/nullvia a newexec_real_claudehelper, so the Ink-based TUI sees a PTY on stdin. - Without this, cmux build variants that route child IO without a controlling terminal made Claude Code fall back to non-interactive mode. ## Testing
- Updated
tests/test_claude_wrapper_hooks.pyto cover the new exec path. - Verified the helper probes
/usr/bin/scriptfirst so a broken stdin can't regress claude into a "failed to start" state. ## Review Trigger (Copy/Paste as PR comment) ```text
@codex review
@coderabbitai review
@greptile-apps review
@cubic-dev-ai review
- [x] I tested the change locally
- [x] I added or updated tests for behavior changes
- [ ] I updated docs/changelog if needed
- [ ] I requested bot reviews after my latest commit (copy/paste block above or equivalent)
- [ ] All code review bot comments are resolved
- [ ] All human review comments are resolved Fixes #4001
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Keep Claude Code’s TUI interactive under `cmux` by allocating a PTY when stdin isn’t a terminal. Adds a safe `/usr/bin/script` exec path with probing to prevent non-interactive fallback (fixes #4001).
- **Bug Fixes**
- Added `exec_real_claude` in `Resources/bin/claude` and used it for all real `claude` execs (pass-through, hooks, session-id) to wrap with `/usr/bin/script -q /dev/null` when `IN_CMUX=1`, stdin is not a TTY, and `CMUX_CLAUDE_FORCE_PTY` != `0` (covers `claude` and `claude agents`).
- Probes `/usr/bin/script` with `/usr/bin/true` and falls back to direct exec if unavailable or unsafe to avoid start failures.
- Extended tests with a PTY allocation harness that asserts the real `claude` sees a TTY for both entry and `agents`, and verifies `CMUX_CLAUDE_FORCE_PTY=0` disables PTY allocation; skips when `/usr/bin/script` is missing.
<!-- End of auto-generated description by cubic. -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
* **Improvements**
* Ensures claude is launched with a proper terminal (PTY) across environments and build variants, improving interactive behavior, hook handling, and session handling; adds an opt-out for PTY allocation.
* **Tests**
* Adds regression tests verifying PTY allocation, successful terminal detection for real claude, and opt-out behavior across launch modes and CMUX socket states.
[](https://app.coderabbit.ai/change-stack/manaflow-ai/cmux/pull/4002)
<!-- end of auto-generated comment: release notes by coderabbit.ai -->