Skip to content

Option + backspace does not delete the last word #4341

Closed

Description

@markusylisiurunen

What version of Codex is running?

codex-cli 0.42.0

Which model were you using?

Any model (e.g. gpt-5-codex)

What platform is your computer?

Darwin 24.6.0 arm64 arm

What steps can reproduce the bug?

  1. Open codex and write a few words into the prompt.
  2. Move the cursor to a word boundary and press option + backspace.

What is the expected behavior?

The last word should be deleted, ending at the cursor position.

What do you see instead?

Only a single character gets deleted, as if option is not pressed at all.

Additional information

I am using Ghostty as my terminal, but the same bug happens in the macOS' own Terminal app as well.

Activity

  1. added
    bug
    on Sep 27, 2025
  2. markusylisiurunen commented on Sep 27, 2025

    @markusylisiurunen
    Author

    Most of the other common text editing shortcuts work as expected:

    • option + left/right arrow moves the cursor one word at a time.
    • cmd + left/right arrow moves the cursor to the beginning or end of line.
    • cmd + backspace deletes the entire line.
  3. markusylisiurunen commented on Sep 27, 2025

    @markusylisiurunen
    Author

    There actually seems to be a test case in place for this exact key combination:

    fn delete_backward_word_alt_keys() {

    Codex works as expected when I explicitly set Ghostty keybinding to this:

    keybind = alt+backspace=text:\x1b\x7f
    

    Perhaps the issue is that the ALT modifier is not somehow either passed or parsed correctly.

  4. Schreezer commented on Oct 5, 2025

    @Schreezer

    thanks a lot for the solution 'Codex works as expected when I explicitly set Ghostty keybinding to this:

    keybind = alt+backspace=text:\x1b\x7f' ; both codex and qwen are working as expected now

  5. added
    TUI
    on Nov 12, 2025
  6. Cornelivl commented on Dec 10, 2025

    @Cornelivl

    So have you also found a solution to selecting. When using cmd+a it selects the whole chat. cmd+shift+arrow doesn't seem to work even when setting it in terminal/cursor shortcuts. Does this work differently for you?

  7. camc314 commented on Jan 29, 2026

    @camc314

    Ok,I debugged into this, and here's what I found.

    on macos:

    Key Combination Actual Behaviour Expected Behaviour
    right option + backspace delete line delete line
    right command + backspace delete word delete word
    left command + backspace delete line delete line
    left option + backspace delete char delete word
    left control + backspace delete char no special behaviour (delete char)

    Here's a patch that fixes ths issue (codex's contributing.md doesn't allow external PRs without permission)

    patch.diff
    git diff --staged
    diff --git a/codex-rs/tui/src/bottom_pane/textarea.rs b/codex-rs/tui/src/bottom_pane/textarea.rs
    index 0235f7a9c..d3d0a5112 100644
    --- a/codex-rs/tui/src/bottom_pane/textarea.rs
    +++ b/codex-rs/tui/src/bottom_pane/textarea.rs
    @@ -294,6 +294,11 @@ impl TextArea {
                     code: KeyCode::Backspace,
                     modifiers: KeyModifiers::ALT,
                     ..
    +            }
    +            | KeyEvent {
    +                code: KeyCode::Backspace,
    +                modifiers: KeyModifiers::CONTROL,
    +                ..
                 } => self.delete_backward_word(),
                 KeyEvent {
                     code: KeyCode::Backspace,

    This paatch aligns the behaviour with browsers/other CLI worlkflows.

    EDIT: somehow after fixing and testing the patch, it's working now in some of my codex instances - but not others 🤷

  8. etraut-openai commented on Jan 29, 2026

    @etraut-openai
    Contributor

    @camc314, thanks for the analysis. Have you done any testing with other terminal emulator apps? We need to ensure broad compatibility across many terminals on all supported platforms, which is what makes issues like this difficult.

  9. camc314 commented on Jan 29, 2026

    @camc314

    Have you done any testing with other terminal emulator apps?

    I've tried https://ghostty.org and VSCode, and both appear to have the same behaviour.

    Apple's terminal doesn't appear to send the key modifiers to the TUI (in here, the modifiers are always empty)

    Here are some other references that might be helpful:

  10. fcoury commented on Feb 19, 2026

    @fcoury
    Contributor

    This is a limitation of how Terminal.app handles this key combination.

    In Terminal.app:

    1. Open Terminal → Settings (or Preferences)
    2. Go to Profiles → Keyboard
    3. Check "Use Option as Meta key"
    Image

    This makes Option+Backspace send ESC + Backspace (\x1b\x7f) instead of just Backspace (\x7f). Most shells interpret that as "delete word backward."

    If you only want to remap that specific combo (without making Option a full Meta key), you can add a custom mapping in the same Keyboard tab:

    1. Click the + button
    Image
    1. Set the key to Delete with the Option modifier
    2. Set the action to "Send text:"
    Image
    1. Click the empty field
    Image
    1. Type Esc first, it will add "\033" to the field
    2. Then type Delete (or Backspace on non-Apple/external keyboards), it will add "\177" to the field
    Image
    1. Click OK

    The "Use Option as Meta key" approach is simpler but changes the behavior of all Option+key combos. The custom mapping approach is surgical — it only affects Option+Backspace.

  11. jgarvin commented on Mar 27, 2026

    @jgarvin

    I can confirm that:

    1. the same issue exists with kitty terminal on linux using ctrl+backspace (backward delete word) and ctrl+shift+backspace (forward delete word)
    2. neither claude code nor gemini CLI have this issue, both shortcuts work. It's a codex problem, not a terminal or OS problem.
  12. costular commented on Apr 10, 2026

    @costular

    I confirm it's happening on Ghostty

  13. etraut-openai commented on Nov 9, 2026

    @etraut-openai
    Contributor

    (response from codex)

    In Codex CLI 0.167.0, Option+Backspace (Alt+Backspace) and Ctrl+W are both bound to delete the previous word. If Option+Backspace still deletes one character, run /keymap debug and press it once. Plain backspace would explain the single-character deletion. If the inspector shows alt-backspace and editor.delete_backward_word, but the composer still deletes only one character, please share the inspector output and your Codex and terminal versions. Default editor bindings

    For Ghostty, the reporter confirmed this explicit binding works:

    keybind = alt+backspace=text:\x1b\x7f

    In Apple Terminal, try enabling Settings → Profiles → Keyboard → Use Option as Meta key. Ctrl+W is also available if you prefer to keep your terminal settings as they are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    TUIbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions