Skip to content

fix(terminal): send ESC d for Option+Forward-Delete on macOS (#21491) - #33296

Merged
nwparker merged 3 commits into
mainfrom
nwparker/agint-21491
Oct 25, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/agint-21491

Conversation

@nwparker

@nwparker nwparker commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​63 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​63
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​40 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33

ELI5

On macOS, Option + Forward-Delete (⌥⌦, fn+⌥+⌫ on laptops) in an Orca terminal now deletes the word to the right of the cursor. Before this change it wiped everything to the end of the line in Claude Code, and in a shell it could print a stray ~.

This builds on #21893 by @bbingz and keeps their commit. The follow-up commit limits the change to macOS.

Root cause

xterm.js encodes Alt+Delete as CSI 3;3~, and Orca had no policy mapping for it. That differs from how readline and Claude Code read the key:

  • Claude Code 2.1.310 treats CSI 3;3~ as kill-to-end-of-line and treats ESC d as forward-kill-word (PTY probe below).
  • iTerm2's "Natural Text Editing" preset maps ⌥⌦ (f728-0x80000) to Esc+d (iTerm2/plists/PresetKeyMappings.plist). Orca already copies the rest of that preset: ⌥⌫ → ESC DEL, ⌥←/→ → ESC b/f, ⌘⌫ → ^U.
  • Ghostty sends CSI 3;3~ (ghostty/src/input/function_keys.zig:85) and has no ⌥⌦ default in Config.zig. Terminal.app's keyMappings.plist has no ~F728 entry.

What changed

  • terminal-shortcut-policy.ts: when kitty keyboard is inactive, Option+Delete (not numpad) sends ESC d on macOS. The existing Alt+Backspace branch already sends ESC DEL.
  • When kitty is negotiated, the key is left to xterm's native encoding, as Alt+Backspace and Alt+Arrow already are. Codex pushes CSI >7u, so it gets CSI 3;3~ and handles it as Alt+Delete (codex-rs/tui/src/bottom_pane/textarea.rs delete_forward_word_with_without_alt_modifier).
  • Change from fix(terminal): translate Option/Alt + Forward-Delete to readline forward-kill-word (#21491) #21893: Linux and Windows keep xterm's native CSI 3;3~. That is what VTE, xterm and Ghostty send there. On a local ConPTY, ESC d would arrive in PSReadLine as Alt+D, which is a different key.
  • The test file was trimmed to three cases: the macOS mapping, the Linux/Windows passthrough, and the kitty deferral.

Verification

I ran each real TUI under node-pty with @xterm/headless (the kitty-capable xterm.js that Orca uses), typed alpha beta gamma, pressed Ctrl+A, then sent the bytes:

TUI ESC d (new macOS bytes) CSI 3;3~ (old bytes)
Claude Code 2.1.310 ❯ beta gamma line cleared (bug)
Codex 0.164.0 (pushes kitty >7u) › beta gamma › beta gamma
opencode 2.0.16 ┃ beta gamma ┃ beta gamma

I got the same Claude results under tmux. With TERM_PROGRAM=Orca, Claude does not push kitty flags, so it takes the legacy path that this fix covers.

Risk

The change is small and macOS-only. A user whose shell binds CSI 3;3~ itself (for example zsh bindkey '^[[3;3~') will now get readline's ESC d (kill-word) instead. That matches iTerm2's preset.

Fixes #21491
Supersedes #21893

Co-authored-by: Bing.Z [email protected]

bbingz and others added 2 commits October 24, 2026 15:51
…o macOS

Ghostty, VTE, xterm and ConPTY send CSI 3;3~ for Alt+Delete, and local
PSReadLine would see ESC d as Alt+D, so only macOS mirrors iTerm2's
Natural Text Editing ESC d. Trim the regression test to the platform split.

Co-authored-by: Bing.Z <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 17d405ae-cf7e-4f32-93bf-5a05d5153fd2
Commits

Reviewing files that changed from the base of the PR and between 2aae457 and ec666e0.

Files selected for processing: 4
  • src/renderer/src/components/terminal-pane/terminal-keyboard-runtime.ts
  • src/renderer/src/components/terminal-pane/terminal-keyboard-shortcut-matching.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-forward-delete.test.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…ull-screen apps

vim/nano read ESC d as Escape + d (vim leaves insert mode with a pending
delete). Send ESC d only when the pane is on the normal buffer (shells,
inline agents) or a known agent owns it (foreground process, live hook row,
launch config, or agent title).
@nwparker
nwparker merged commit cae5e98 into main Oct 25, 2026
39 checks passed
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.

[Bug]: Option + Forward-Delete deletes to end of line in Claude code, types ~ in terminal

2 participants