Skip to content

fix(help): quit less on Ctrl-C on Windows to avoid wedged terminal - #2969

Merged
max-sixty merged 1 commit into
mainfrom
fix/windows-pager-ctrl-c-2968
Jun 4, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/windows-pager-ctrl-c-2968

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

On Windows, wt <cmd> --help pipes its output through less. Pressing q exits cleanly, but pressing Ctrl-C leaves the terminal unresponsive (#2968). @ofek confirmed the key symptom: the less window disappears and the prompt is redrawn, but input no longer echoes.

Root cause: on Windows, Ctrl-C delivers a CTRL_C_EVENT to every process attached to the console — both less and the blocked wt parent (child.wait()). less is terminated before it restores the console input mode it switched into, and wt has no Windows console handler to coordinate teardown (signal forwarding is Unix-only). The console is left with echo / line-input disabled, so the shell looks wedged. q works because less then exits cleanly and restores the mode.

Approach in this PR

Pass -K (--quit-on-intr) to less via the LESS env var, Windows only. Per the less(1) manual, -K makes less exit on an interrupt (status 2) instead of returning to its prompt — routing Ctrl-C through the same clean-exit/deinit path as q, which restores the console.

This is deliberately the smallest change that targets the mechanism:

  • No new dependency, no FFI / SetConsoleCtrlHandler. I floated a Windows console-handler approach earlier in the thread; this avoids that entirely.
  • Windows-only. On Unix the signal forwarder already coordinates teardown, and many users rely on Ctrl-C returning less to its prompt rather than quitting — so that path is untouched.
  • compute_less_flags is split into a platform-parameterized core (compute_less_flags_for) so both branches are unit-tested on any host.

⚠️ Not verified on Windows — opening as a draft

I run in Linux CI and cannot exercise the Windows console teardown, so I have not confirmed this end-to-end on real hardware. The reasoning is grounded in the documented -K behavior and @ofek's confirmation that q (clean exit) restores the terminal, but the residual unknown is whether less completes its console-restore deinit before the concurrent CTRL_C_EVENT to wt matters in practice. I'm opening this as a draft at @ofek's request so a maintainer can see the concrete change and test it on Windows before deciding.

If it works, this is a one-flag fix. If -K proves insufficient (e.g. the restore races the parent's termination), the heavier console-handler route remains the fallback.

Testing

  • cargo test --bin wt compute_less_flags — 5 tests pass, covering both the Unix (-FRX) and Windows (-FRX -K) branches.
  • cargo clippy / cargo fmt --check clean.
  • Windows runtime behavior: unverified (see above).

#2968

On Windows, pressing Ctrl-C while `wt <cmd> --help` is showing its output
through `less` leaves the terminal unresponsive. Ctrl-C delivers a
CTRL_C_EVENT to every process attached to the console, so both `less` and
the blocked `wt` parent are terminated before `less` restores the console
input mode it switched into. Quitting with `q` works because `less` then
exits cleanly and restores the terminal.

Pass `-K` (--quit-on-intr) to `less` via the LESS env var on Windows only,
so Ctrl-C routes through the same clean-exit path as `q` (less exits with
status 2, running its normal deinit that restores the console). Unix is
unchanged: its signal forwarder already coordinates teardown, and Ctrl-C
returning less to its prompt is expected there.

Refactors compute_less_flags into a platform-parameterized core so both
branches are unit-testable on any host.

#2968

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@worktrunk-bot
worktrunk-bot marked this pull request as ready for review June 4, 2026 00:43
@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

@ofek confirmed on Windows that this fixes the wedged terminal — that closes the one gap I'd flagged as the reason for the draft (whether less completes its console-restore deinit before the concurrent CTRL_C_EVENT to wt matters in practice). It doesn't.

So I've marked this ready for review. The change is unchanged from what @ofek tested: -K (--quit-on-intr) added to LESS on Windows only, no new dependency or FFI, Unix path untouched.

@max-sixty over to you for the merge decision.

@max-sixty
max-sixty merged commit 56fe491 into main Jun 4, 2026
34 checks passed
@max-sixty
max-sixty deleted the fix/windows-pager-ctrl-c-2968 branch June 4, 2026 04:21
@max-sixty

Copy link
Copy Markdown
Owner

Thanks @ofek!

@worktrunk-bot should we have this flag everywhere? Can you explain the contours of the problem?

@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

@max-sixty good question — short answer: no, -K should stay Windows-only. Here's why.

The contours of the problem

When you run wt --help, we pipe the help text to a pager (less by default) and wt waits for it. The wedge happens when you press Ctrl-C while less is on screen. less puts the terminal into raw mode (no echo, alternate screen, etc.) and only restores it by running its deinit on a clean exit (q, or running off the end of a one-screen doc with -F). If less is killed before that deinit runs, the terminal is left in raw mode — no echo, no line editing — i.e. wedged (#2968).

Whether Ctrl-C kills less before it can deinit comes down to who handles the signal, and that's where the platforms diverge:

  • Unix — wt installs a signal_hook SIGINT/SIGTERM handler (src/signal_forwarder.rs) and coordinates teardown. The kernel delivers the tty Ctrl-C to the whole foreground process group; less catches it and, by its own default, returns to its prompt rather than quitting. You stay in the pager, and when you eventually q it deinits cleanly. No wedge, and Ctrl-C keeps its conventional "interrupt the current search/read, don't quit" meaning.

  • Windows — there are no POSIX signals or process groups, so the signal forwarder module is #[cfg(unix)] and doesn't exist here. Windows delivers a CTRL_C_EVENT concurrently to both less and wt. Nobody coordinates, so less is torn down racing its own console-restore — frequently losing — and the terminal is left wedged.

-K (--quit-on-intr) fixes this by telling less to treat Ctrl-C as a quit, routing it through the same clean-exit/deinit path as q. So the console gets restored.

Should we have it everywhere?

No, on two counts:

  1. Across platforms — on Unix, -K would be a behavior regression, not a fix. It would turn Ctrl-C-in-pager from "return to prompt" into "quit the pager," breaking muscle memory, and the wedge it guards against can't happen there anyway because the signal forwarder already coordinates a clean teardown. So it's specifically a stand-in for the Windows absence of that coordination.

  2. Across pagers, within Windows — the help pager is our only interactive pager (it owns the TTY and waits for the user). The other place we spawn less/delta — the diff preview in the switch picker (src/commands/picker/pager.rs) — runs non-interactively: output is captured, paging is forced off (--paging=never), and it's timeout-killed. It never holds the TTY for a user Ctrl-C, so it can't wedge and doesn't need -K.

So the flag is scoped exactly to the one place the problem exists: interactive less on Windows. The reasoning is captured in the compute_less_flags_for doc comment in src/help_pager.rs if you want it inline.

@max-sixty max-sixty mentioned this pull request Jun 9, 2026
max-sixty added a commit that referenced this pull request Jun 9, 2026
v0.57.0.

`cargo semver-checks` reports breaking library API changes: the squash
refactor (#2983) renamed `Repository::commit_subjects` to
`commit_message_details`, and the new `GitError::UnbornDefaultBranch`
variant (#2990) shifts the discriminants of the exhaustive `GitError`
enum. Neither is intentional public API, but together they force a minor
bump pre-1.0.

## CHANGELOG

### Improved

- **`wt step diff --branch`**: `wt step diff` gained a `-b`/`--branch`
flag, mirroring `wt step commit`, so the diff can target another
worktree's branch without leaving the current one. The branch must have
a checked-out worktree.
([#2995](#2995))

- **Squash templates can use commit bodies**: The squash commit-message
template gains an experimental `{{ commit_details }}` variable — a list
of `{ subject, body }` objects for the commits being squashed —
alongside the existing `{{ commits }}` (now documented as the commit
subjects). Templates can incorporate full commit bodies, not just
subject lines.
([#2983](#2983), thanks
@florianilch)

- **Recommended Claude Code commit command drops the `CLAUDECODE=`
prefix**: Claude Code removed the nested-session check that rejected
`claude -p` launched from inside another session, so the workaround is
gone. The recommended `[commit.generation]` command shown by `wt config
create` no longer carries a leading `CLAUDECODE=`, and `wt` no longer
strips `CLAUDECODE` from the environment before running
commit-generation commands.
([#2979](#2979))

### Fixed

- **Nushell wrapper installs where Nushell actually autoloads it**: `wt
config shell install nu` wrote `wt.nu` to
`$nu.default-config-dir/vendor/autoload`, which Nushell never autoloads
— on Linux the wrapper was written but silently never loaded, so `wt`
was never wrapped (it happened to work on macOS/Windows by coincidence
of path layout). It now installs to `$nu.vendor-autoload-dirs | last`,
and install/uninstall clean up any worktrunk wrapper stranded at the old
location. ([#2992](#2992),
thanks @nnutter for reporting)

- **Claude Code hooks work for Fish shell users**: The plugin's hook
commands used `${CLAUDE_PLUGIN_ROOT}` brace syntax, which Fish doesn't
expand; they now use `$CLAUDE_PLUGIN_ROOT`, so the activity and
worktree-lifecycle hooks fire correctly under Fish.
([#2962](#2962), thanks @amw)

- **Pager no longer wedges the terminal on Ctrl-C (Windows)**:
Interrupting the `--help` pager (`less`) with Ctrl-C on Windows could
leave the terminal in a broken state; `less` now quits cleanly on
interrupt. ([#2969](#2969),
thanks @ofek for reporting)

- **Clearer error when the default branch has no commits**: In a freshly
initialized repo whose default branch is unborn,
`merge`/`rebase`/`squash`/`push` (and the diff report) failed with
`Default branch main does not exist locally` plus a misleading hint to
reset the cached value. They now report that the branch has no commits
yet, without the wrong cache-reset suggestion.
([#2990](#2990))

- **`diagnostic.md` uploads as a gist again**: The `-vv` diagnostic
report inlined raw NUL bytes from NUL-separated git output, so `gh gist
create` rejected it as a binary file. Control bytes in the subprocess
preview are now escaped.
([#2991](#2991))

- **`wt list` tolerates a missing index file**: A repo with no
`<gitdir>/index` (nothing ever staged) made the temp-index probe fail; a
missing index is now treated as an empty one, matching git's own
behavior. ([#2884](#2884))

- **Inline code renders in `--help` section headings**: Terminal
`--help` showed literal backticks in headings authored with inline code
(e.g. the `wt config state logs` heading `Command log
(`commands.jsonl`)`). Headings now reduce inline code to plain text
under the heading's uniform style. The `--stage`/`--dry-run` subsection
headings in `wt step commit`/`squash` were also renamed to sentence case
("Staging", "Dry run").
([#3003](#3003))

### Documentation

- **`wt switch` docs give forge PR/MR URLs equal billing with
`pr:`/`mr:`**: The switch docs now present the full forge-URL form
alongside the `pr:N` shortcut.
([#2970](#2970))

- **New FAQ entry on moving uncommitted changes to a new worktree**.
([#3002](#3002))

### Internal

- **Bare-repo prompt opt-out stored as a hint**:
`worktrunk.skip-bare-repo-prompt` moved under the `worktrunk.hints.`
namespace, so it now lists under `wt config state hints` and clears with
`wt config state clear` (previously a top-level key that escaped both).
Clean cutover: users who already opted out are re-prompted once on their
next `wt switch --create` in a dotted-name bare repo.
([#3001](#3001))

> _This was written by Claude Code on behalf of max_
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.57.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes

### Improved

- **`wt step diff --branch`**: `wt step diff` gained a `-b`/`--branch` flag, mirroring `wt step commit`, so the diff can target another worktree's branch without leaving the current one. The branch must have a checked-out worktree. ([#2995](max-sixty/worktrunk#2995))

- **Squash templates can use commit bodies**: The squash commit-message template gains an experimental `{{ commit_details }}` variable — a list of `{ subject, body }` objects for the commits being squashed — alongside the existing `{{ commits }}` (now documented as the commit subjects). Templates can incorporate full commit bodies, not just subject lines. ([#2983](max-sixty/worktrunk#2983), thanks @florianilch)

- **Recommended Claude Code commit command drops the `CLAUDECODE=` prefix**: Claude Code removed the nested-session check that rejected `claude -p` launched from inside another session, so the workaround is gone. The recommended `[commit.generation]` command shown by `wt config create` no longer carries a leading `CLAUDECODE=`, and `wt` no longer strips `CLAUDECODE` from the environment before running commit-generation commands. ([#2979](max-sixty/worktrunk#2979))

### Fixed

- **Nushell wrapper installs where Nushell actually autoloads it**: `wt config shell install nu` wrote `wt.nu` to `$nu.default-config-dir/vendor/autoload`, which Nushell never autoloads — on Linux the wrapper was written but silently never loaded, so `wt` was never wrapped (it happened to work on macOS/Windows by coincidence of path layout). It now installs to `$nu.vendor-autoload-dirs | last`, and install/uninstall clean up any worktrunk wrapper stranded at the old location. ([#2992](max-sixty/worktrunk#2992), thanks @nnutter for reporting)

- **Claude Code hooks work for Fish shell users**: The plugin's hook commands used `${CLAUDE_PLUGIN_ROOT}` brace syntax, which Fish doesn't expand; they now use `$CLAUDE_PLUGIN_ROOT`, so the activity and worktree-lifecycle hooks fire correctly under Fish. ([#2962](max-sixty/worktrunk#2962), thanks @amw)

- **Pager no longer wedges the terminal on Ctrl-C (Windows)**: Interrupting the `--help` pager (`less`) with Ctrl-C on Windows could leave the terminal in a broken state; `less` now quits cleanly on interrupt. ([#2969](max-sixty/worktrunk#2969), thanks @ofek for reporting)

- **Clearer error when the default branch has no commits**: In a freshly initialized repo whose default branch is unborn, `merge`/`rebase`/`squash`/`push` (and the diff report) failed with `Default branch main does not exist locally` plus a misleading hint to reset the cached value. They now report that the branch has no commits yet, without the wrong cache-reset suggestion. ([#2990](max-sixty/worktrunk#2990))

- **`diagnostic.md` uploads as a gist again**: The `-vv` diagnostic report inlined raw NUL bytes from NUL-separated git output, so `gh gist create` rejected it as a binary file. Control bytes in the subprocess preview are now escaped. ([#2991](max-sixty/worktrunk#2991))

- **`wt list` tolerates a missing index file**: A repo with no `<gitdir>/index` (nothing ever staged) made the temp-index probe fail; a missing index is now treated as an empty one, matching git's own behavior. ([#2884](max-sixty/worktrunk#2884))

- **Inline code renders in `--help` section headings**: Terminal `--help` showed literal backticks in headings authored with inline code (e.g. the `wt config state logs` heading `Command log (`commands.jsonl`)`). Headings now reduce inline code to plain text under the heading's uniform style. The `--stage`/`--dry-run` subsection headings in `wt step commit`/`squash` were also renamed to sentence case ("Staging", "Dry run"). ([#3003](max-sixty/worktrunk#3003))

### Documentation

- **`wt switch` docs give forge PR/MR URLs equal billing with `pr:`/`mr:`**: The switch docs now present the full forge-URL form alongside the `pr:N` shortcut. ([#2970](max-sixty/worktrunk#2970))

- **New FAQ entry on moving uncommitted changes to a new worktree**. ([#3002](max-sixty/worktrunk#3002))

### Internal

- **Bare-repo prompt opt-out stored as a hint**: `worktrunk.skip-bare-repo-prompt` moved under the `worktrunk.hints.` namespace, so it now lists under `wt config state hints` and clears with `wt config state clear` (previously a top-level key that escaped both). Clean cutover: users who already opted out are re-prompted once on their next `wt switch --create` in a dotted-name bare repo. ([#3001](max-sixty/worktrunk#3001))

## Install worktrunk 0.57.0

### Install prebuilt binaries via shell script

```sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-installer.sh | sh && wt config shell install
```

### Install prebuilt binaries via powershell script

```sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-installer.ps1 | iex"; git-wt config shell install
```

### Install prebuilt binaries via Homebrew

```sh
brew install worktrunk && wt config shell install
```

## Download worktrunk 0.57.0

|  File  | Platform | Checksum |
|--------|----------|----------|
| [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-x86_64-apple-darwin.tar.xz.sha256) |
| [worktrunk-x86_64-pc-windows-msvc.zip](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-x86_64-pc-windows-msvc.zip.sha256) |
| [worktrunk-aarch64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-aarch64-unknown-linux-musl.tar.xz.sha256) |
| [worktrunk-x86_64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.57.0/worktrunk-x86_64-unknown-linux-musl.tar.xz.sha256) |



### Install via Cargo

```sh
cargo install worktrunk && wt config shell install
```

### Install via Winget (Windows)

```sh
winget install max-sixty.worktrunk && git-wt config shell install
```

### Install via AUR (Arch Linux)

```sh
paru worktrunk-bin && wt config shell install
```
</pre>
  <p>View the full release notes at <a href="https://github.com/max-sixty/worktrunk/releases/tag/v0.57.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.57.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!11171
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