Skip to content

fix(alias): inherit stdin so interactive children keep the tty - #2380

Merged
max-sixty merged 1 commit into
mainfrom
fix/alias-stdin-tty
Apr 22, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/alias-stdin-tty

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Summary

Alias execution piped the template context JSON into each child's stdin, displacing the controlling terminal. Interactive children like wt switch then saw a pipe and bailed with Interactive picker requires an interactive terminal. See #406 follow-up for the reproduction.

The fix is scoped to the single call site in run_one_command (src/commands/command_executor.rs) where CommandOrigin already distinguishes hooks from aliases:

  • CommandOrigin::Hook { .. } → keep piping context_json on stdin (documented contract, covered by test_post_create_json_stdin / test_post_start_json_stdin).
  • CommandOrigin::Alias { .. } → pass None; execute_shell_command now treats None as Stdio::inherit() so the child keeps the parent's tty.

No subcommand sniffing, no new configs, no change to for_each (which still opts into JSON-on-stdin).

Test plan

  • New regression test test_alias_inherits_stdin in tests/integration_tests/step_alias.rs — pipes a sentinel into wt, runs an alias of cat, asserts the sentinel (not the context JSON) reaches the alias body.
  • cargo test --test integration -- step_alias — all 67 tests pass, including the new one.
  • cargo test --test integration -- test_post_create_json_stdin test_post_start_json_stdin — hook JSON-on-stdin still works.
  • cargo test --test integration -- post_start post_create for_each — 70 tests pass.
  • cargo clippy --all-targets — clean.

🤖 Generated with Claude Code

Alias execution piped the template context JSON into each child's stdin,
displacing the controlling terminal. Interactive children like `wt switch`
then saw a pipe and failed the `stdin().is_terminal()` guard with
"Interactive picker requires an interactive terminal".

Hooks still get the documented JSON-on-stdin contract; aliases now leave
stdin alone. The hook/alias split already exists as `CommandOrigin` at the
single call site, so no subcommand sniffing is needed.

Fixes #406 follow-up reported by @KieranP.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@worktrunk-bot worktrunk-bot mentioned this pull request Apr 22, 2026
@max-sixty
max-sixty merged commit e1f2fbd into main Apr 22, 2026
23 checks passed
@max-sixty
max-sixty deleted the fix/alias-stdin-tty branch April 22, 2026 03:21
max-sixty added a commit that referenced this pull request May 2, 2026
The comparison table in `extending.md` covered invocation, positional
handling, approval flags, source filters, and template-context extras —
but never said anything about stdin. Hooks have always received the
template context as JSON on stdin (documented in `hook.md`), and since
#2380 aliases inherit the parent's stdin so pipes pass through and
interactive TUIs (`wt switch`) keep the tty. Adding a row makes the
contract discoverable from the aliases page rather than only from the
CHANGELOG.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
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.

2 participants