From 25ad70f8fadf75148ed67d95e15e83b35e7b1641 Mon Sep 17 00:00:00 2001 From: Austin Gregg-Smith Date: Sat, 31 Oct 2026 10:19:25 +0000 Subject: [PATCH 1/4] fix(terminal): turn off modifyOtherKeys and focus reports after a session Claude Code switches on xterm modifyOtherKeys and focus reports in the container. When the session ended without its own reset reaching the terminal, both stayed on: Ctrl-C reached bash as ESC[27;5;99~, readline typed ";5;99~" into the line, and the next Enter ran it. The restore dl writes after every session now also writes ESC[>4;0m and ESC[?1004l. Both are sets, so they change nothing on a terminal that is already in the default state. Release 0.64.2. --- CHANGELOG.md | 11 +++++++++++ README.md | 4 ++-- rust/Cargo.lock | 10 +++++----- rust/Cargo.toml | 2 +- rust/devlaunch-runner/src/terminal.rs | 25 +++++++++++++++++++++++++ rust/dl/tests/terminal.rs | 20 +++++++++++++++++++- 6 files changed, 63 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edac459d..58887eae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.64.2] - 2026-10-31 + +### Fixed + +- **Ctrl-C works at the shell again after a session that ends without cleaning up.** + Claude Code switches on xterm `modifyOtherKeys` and focus reports in the container. + When the session ended without its own reset reaching the terminal, both stayed on: + Ctrl-C reached bash as `ESC[27;5;99~`, so it typed `;5;99~` into the line instead of + cancelling it, and focus changes printed `^[[I` and `^[[O`. The restore `dl` writes + after every session now also turns off both modes. + ## [0.64.1] - 2026-10-30 ### Added diff --git a/README.md b/README.md index 9af628eb..e73eeddf 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ one argument instead of a clone, a config file and a build command. [![GitHub pull-requests merged](https://badgen.net/github/merged-prs/blooop/devlaunch)](https://github.com/blooop/devlaunch/pulls?q=is%3Amerged) [![GitHub release](https://img.shields.io/github/release/blooop/devlaunch.svg)](https://GitHub.com/blooop/devlaunch/releases/) [![PyPI](https://img.shields.io/pypi/v/devlaunch)](https://pypi.org/project/devlaunch/) -[![Conda](https://img.shields.io/badge/conda-v0.64.1-brightgreen?logo=anaconda)](https://prefix.dev/channels/blooop/packages/devlaunch) +[![Conda](https://img.shields.io/badge/conda-v0.64.2-brightgreen?logo=anaconda)](https://prefix.dev/channels/blooop/packages/devlaunch) [![License](https://img.shields.io/github/license/blooop/devlaunch)](https://opensource.org/license/mit/) [![Platform](https://img.shields.io/badge/platform-linux--64-blue)](https://github.com/blooop/devlaunch/releases) [![Pixi Badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json)](https://pixi.sh) @@ -350,7 +350,7 @@ clone, and [docs/cleanup.md](docs/cleanup.md) says what it carries one past and ```bash $ dl --version -dl 0.64.1 +dl 0.64.2 ``` `--devcontainer ` picks a non-default `devcontainer.json`. A bare name means diff --git a/rust/Cargo.lock b/rust/Cargo.lock index b12c09d0..95594668 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -438,7 +438,7 @@ dependencies = [ [[package]] name = "devlaunch-core" -version = "0.64.1" +version = "0.64.2" dependencies = [ "devlaunch-runner", "devlaunch-test-support", @@ -458,7 +458,7 @@ dependencies = [ [[package]] name = "devlaunch-runner" -version = "0.64.1" +version = "0.64.2" dependencies = [ "libc", "portable-pty", @@ -467,7 +467,7 @@ dependencies = [ [[package]] name = "devlaunch-test-support" -version = "0.64.1" +version = "0.64.2" dependencies = [ "devlaunch-runner", "serde", @@ -509,7 +509,7 @@ dependencies = [ [[package]] name = "dl" -version = "0.64.1" +version = "0.64.2" dependencies = [ "clap", "devlaunch-core", @@ -527,7 +527,7 @@ dependencies = [ [[package]] name = "dla" -version = "0.64.1" +version = "0.64.2" dependencies = [ "devlaunch-test-support", "dl", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ec058417..6d4e13a9 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -11,7 +11,7 @@ members = [ # The single source of the version (docs/rust-rewrite-plan.md: cutover ships # 0.1.0, version read from Cargo.toml). [workspace.package] -version = "0.64.1" +version = "0.64.2" edition = "2024" license = "MIT" repository = "https://github.com/blooop/devlaunch" diff --git a/rust/devlaunch-runner/src/terminal.rs b/rust/devlaunch-runner/src/terminal.rs index 1bc6d01f..8ab1eba1 100644 --- a/rust/devlaunch-runner/src/terminal.rs +++ b/rust/devlaunch-runner/src/terminal.rs @@ -71,6 +71,14 @@ /// child of `dl`'s is reaped is that child's, and nobody else's to lose. A /// caller that violates the contract is damaged by the first pop and no further /// by the rest, which is why counting them buys nothing. +/// - `ESC [ > 4 ; 0 m` — xterm `modifyOtherKeys` off. Claude Code switches it on, +/// and while it is on Ctrl-C arrives as `ESC [ 27;5;99 ~`, not as the byte that +/// raises SIGINT. Readline takes the `ESC [ 27` and types `;5;99~` into the +/// line, so Ctrl-C at the prompt no longer cancels it, and the next Enter runs +/// it: reported on 2026-10-31 as `dla ;5;99~;5;99~exit`. It is a set, not a +/// push, so writing it on a terminal already at 0 changes nothing. +/// - `ESC [ ? 1004 l` — focus reports off, or each focus change prints `^[[I` or +/// `^[[O` at the prompt. Claude Code switches this on as well. /// - `ESC [ ? 2004 l` — bracketed paste off, or a paste arrives wrapped in /// `ESC [ 200 ~` markers that the shell prints instead of obeying. /// - `ESC [ ? 1000 l` … `ESC [ ? 1015 l` — the mouse tracking modes and the three @@ -81,6 +89,8 @@ pub(crate) const RESTORE: &str = concat!( "\x1b[?1047l", // alternate screen off "\x1b[4;0m", // xterm modifyOtherKeys off + "\x1b[?1004l", // focus reports off "\x1b[?2004l", // bracketed paste off "\x1b[?1000l", // mouse: normal tracking off "\x1b[?1002l", // mouse: button-event tracking off @@ -182,6 +192,21 @@ mod tests { ); } + /// The 2026-10-31 report: Claude Code died holding `modifyOtherKeys` and focus + /// reports, and Ctrl-C at the shell typed `;5;99~` into the line instead of + /// cancelling it. + #[test] + fn the_restore_turns_off_the_modes_claude_code_switches_on() { + assert!( + RESTORE.contains("\x1b[>4;0m"), + "modifyOtherKeys: {RESTORE:?}" + ); + assert!( + RESTORE.contains("\x1b[?1004l"), + "focus reports: {RESTORE:?}" + ); + } + /// Every sequence is a complete CSI: introducer, parameters, final byte. A /// truncated one would be printed as text by the terminal, which is the /// failure this module exists to prevent. diff --git a/rust/dl/tests/terminal.rs b/rust/dl/tests/terminal.rs index 3508f9aa..afe56447 100644 --- a/rust/dl/tests/terminal.rs +++ b/rust/dl/tests/terminal.rs @@ -38,6 +38,14 @@ const MAIN: &str = "devlaunch-main-3j1t"; const KEYBOARD_PUSH: &str = "\x1b[>1u"; const KEYBOARD_POP: &str = "\x1b[ Date: Sat, 31 Oct 2026 10:23:34 +0000 Subject: [PATCH 2/4] fix: restore set modifyOtherKeys to 0 instead of resetting it CSI > 4 m resets the resource to its initial value, so a user's modifyOtherKeys: 1 survives a session. --- rust/devlaunch-runner/src/terminal.rs | 11 ++++++----- rust/dl/tests/terminal.rs | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/rust/devlaunch-runner/src/terminal.rs b/rust/devlaunch-runner/src/terminal.rs index 8ab1eba1..57ece049 100644 --- a/rust/devlaunch-runner/src/terminal.rs +++ b/rust/devlaunch-runner/src/terminal.rs @@ -71,12 +71,13 @@ /// child of `dl`'s is reaped is that child's, and nobody else's to lose. A /// caller that violates the contract is damaged by the first pop and no further /// by the rest, which is why counting them buys nothing. -/// - `ESC [ > 4 ; 0 m` — xterm `modifyOtherKeys` off. Claude Code switches it on, +/// - `ESC [ > 4 m` — xterm `modifyOtherKeys` back to its initial value, which is +/// off unless the user's resources say otherwise. Claude Code switches it on, /// and while it is on Ctrl-C arrives as `ESC [ 27;5;99 ~`, not as the byte that /// raises SIGINT. Readline takes the `ESC [ 27` and types `;5;99~` into the /// line, so Ctrl-C at the prompt no longer cancels it, and the next Enter runs -/// it: reported on 2026-10-31 as `dla ;5;99~;5;99~exit`. It is a set, not a -/// push, so writing it on a terminal already at 0 changes nothing. +/// it: reported on 2026-10-31 as `dla ;5;99~;5;99~exit`. `ESC [ > 4 ; 0 m` +/// would force it to 0 and lose a user's `modifyOtherKeys: 1`. /// - `ESC [ ? 1004 l` — focus reports off, or each focus change prints `^[[I` or /// `^[[O` at the prompt. Claude Code switches this on as well. /// - `ESC [ ? 2004 l` — bracketed paste off, or a paste arrives wrapped in @@ -89,7 +90,7 @@ pub(crate) const RESTORE: &str = concat!( "\x1b[?1047l", // alternate screen off "\x1b[4;0m", // xterm modifyOtherKeys off + "\x1b[>4m", // xterm modifyOtherKeys reset "\x1b[?1004l", // focus reports off "\x1b[?2004l", // bracketed paste off "\x1b[?1000l", // mouse: normal tracking off @@ -198,7 +199,7 @@ mod tests { #[test] fn the_restore_turns_off_the_modes_claude_code_switches_on() { assert!( - RESTORE.contains("\x1b[>4;0m"), + RESTORE.contains("\x1b[>4m"), "modifyOtherKeys: {RESTORE:?}" ); assert!( diff --git a/rust/dl/tests/terminal.rs b/rust/dl/tests/terminal.rs index afe56447..aed4346b 100644 --- a/rust/dl/tests/terminal.rs +++ b/rust/dl/tests/terminal.rs @@ -42,7 +42,7 @@ const KEYBOARD_POP: &str = "\x1b[ Date: Sat, 31 Oct 2026 10:26:59 +0000 Subject: [PATCH 3/4] fix: cargo fmt failed on the modifyOtherKeys assert --- rust/devlaunch-runner/src/terminal.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/rust/devlaunch-runner/src/terminal.rs b/rust/devlaunch-runner/src/terminal.rs index 57ece049..5310070c 100644 --- a/rust/devlaunch-runner/src/terminal.rs +++ b/rust/devlaunch-runner/src/terminal.rs @@ -198,10 +198,7 @@ mod tests { /// cancelling it. #[test] fn the_restore_turns_off_the_modes_claude_code_switches_on() { - assert!( - RESTORE.contains("\x1b[>4m"), - "modifyOtherKeys: {RESTORE:?}" - ); + assert!(RESTORE.contains("\x1b[>4m"), "modifyOtherKeys: {RESTORE:?}"); assert!( RESTORE.contains("\x1b[?1004l"), "focus reports: {RESTORE:?}" From de56c9eed5ed14dfa988e87b8630f2982b78ad3a Mon Sep 17 00:00:00 2001 From: Austin Gregg-Smith Date: Sat, 31 Oct 2026 11:37:24 +0000 Subject: [PATCH 4/4] docs: name modifyOtherKeys and focus reports where the restore is described Review follow-ups on #718: docs/cli.md and the terminal.rs module doc now name the two modes, the ;5;99~ symptom and the manual printf. The module doc says ESC[>4m is a reset, not an off. The CHANGELOG entry links #718. --- CHANGELOG.md | 3 ++- docs/cli.md | 18 ++++++++++++------ rust/devlaunch-runner/src/terminal.rs | 13 +++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58887eae..28fcab1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 When the session ended without its own reset reaching the terminal, both stayed on: Ctrl-C reached bash as `ESC[27;5;99~`, so it typed `;5;99~` into the line instead of cancelling it, and focus changes printed `^[[I` and `^[[O`. The restore `dl` writes - after every session now also turns off both modes. + after every session now also turns off both modes + ([#718](https://github.com/blooop/devlaunch/pull/718)). ## [0.64.1] - 2026-10-30 diff --git a/docs/cli.md b/docs/cli.md index 96de7d7f..19f8acca 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -272,8 +272,8 @@ one of devpod's ssh-config context options names a different one. Set ### Getting the terminal back when a session dies badly A terminal is not only a stream. A full screen program switches modes on in the -emulator for its own use, the kitty keyboard protocol, bracketed paste, mouse -reporting, the alternate screen, and is expected to switch them off again on the +emulator for its own use, the kitty keyboard protocol, xterm `modifyOtherKeys`, +focus reports, bracketed paste, mouse reporting, the alternate screen, and is expected to switch them off again on the way out. One that is killed never gets the chance, and those modes live in your terminal rather than in the connection, so nothing between the program and the glass undoes them. @@ -285,22 +285,28 @@ broken: ssh restores the tty settings on its way out, so the shell still echoes and still edits lines, and yet Ctrl-C does nothing and ordinary keys print things like `9;133u` at the prompt. Those are kitty keyboard protocol key reports, still switched on. Ctrl-C is one of them, arriving as an escape sequence instead of as -the byte that raises SIGINT. +the byte that raises SIGINT. Claude Code also switches on xterm `modifyOtherKeys` +and focus reports. With those left on, Ctrl-C at the prompt types `;5;99~` into +the line instead of cancelling it, so the next Enter runs that line, and each +focus change prints `^[[I` or `^[[O`. `dl` is the last process holding that terminal, so `dl` repairs it. Every session ends with a short restore written to the terminal, over either transport, and the interrupt handler writes the same thing before it exits. It goes out after a clean session too, because ssh's exit status does not say whether the far end cleaned up after itself. That costs nothing: every sequence in it is chosen for -doing nothing when the mode it names is already off. The one obvious candidate +doing nothing when the mode it names is already off. `ESC [ > 4 m` is a reset, +not an off: it puts `modifyOtherKeys` back to your terminal's configured value. +The one obvious candidate that is not, `ESC [ ? 1049 l`, is left out on purpose, because it restores the cursor as well as the screen and would scramble the display on every ordinary exit. Nothing is written when `dl`'s own output is not a terminal, so `dl -- ls > files.txt` keeps its output free of escape sequences. If you are ever left with a -wrecked terminal some other way, `printf '\033[4m\033[?1004l'` undoes `modifyOtherKeys` and focus +reports, and `reset` undoes everything. ### `--rm`: the throwaway workspace diff --git a/rust/devlaunch-runner/src/terminal.rs b/rust/devlaunch-runner/src/terminal.rs index 5310070c..2c7bca61 100644 --- a/rust/devlaunch-runner/src/terminal.rs +++ b/rust/devlaunch-runner/src/terminal.rs @@ -3,8 +3,8 @@ //! A child that inherits this process's stdout inherits the *terminal*, and a //! terminal is not only a stream: it holds modes an application switches on for //! its own use and is expected to switch off again on the way out. The kitty -//! keyboard protocol, bracketed paste, mouse reporting and the alternate screen -//! all live in the emulator, not in the connection and not in the tty driver, so +//! keyboard protocol, xterm `modifyOtherKeys`, focus reports, bracketed paste, +//! mouse reporting and the alternate screen all live in the emulator, not in the connection and not in the tty driver, so //! nothing between the application and the glass undoes them. //! //! An application that exits normally undoes its own. One that is *killed* never @@ -28,7 +28,12 @@ //! badly, because "did the remote die without cleaning up" is not a question //! ssh's exit status answers. That is only safe if a restore costs nothing when //! there was nothing to restore, so each sequence below was chosen for being -//! idempotent, and the one obvious candidate that is *not* was left out: +//! idempotent, and the one obvious candidate that is *not* was left out. One +//! sequence is a reset rather than an off: `ESC [ > 4 m` puts `modifyOtherKeys` +//! back to the terminal's configured value, so it also undoes a value the user's +//! own shell set before `dl` ran. +//! +//! The candidate left out: //! //! `ESC [ ? 1049 l` is the usual way to leave the alternate screen, and it is //! also a DECRC — xterm's ctlseqs defines it as "Use Normal Screen Buffer and @@ -76,7 +81,7 @@ /// and while it is on Ctrl-C arrives as `ESC [ 27;5;99 ~`, not as the byte that /// raises SIGINT. Readline takes the `ESC [ 27` and types `;5;99~` into the /// line, so Ctrl-C at the prompt no longer cancels it, and the next Enter runs -/// it: reported on 2026-10-31 as `dla ;5;99~;5;99~exit`. `ESC [ > 4 ; 0 m` +/// it: reported on 2026-10-31 as `dla ;5;99~;5;99~;5;99~;5;99~exit`. `ESC [ > 4 ; 0 m` /// would force it to 0 and lose a user's `modifyOtherKeys: 1`. /// - `ESC [ ? 1004 l` — focus reports off, or each focus change prints `^[[I` or /// `^[[O` at the prompt. Claude Code switches this on as well.