Skip to content

[BUG] Focus reporting escape sequences ([I[O) appear in input when using mouse/modifiers #10375

Description

@ree-see

Bug Description

When using Claude Code in WezTerm (and likely other terminals), focus reporting escape sequences [I and [O are being injected into the input interface when clicking with the mouse or using modifier keys. These escape sequences should be filtered by Claude Code's input handler.

Environment

  • Terminal: WezTerm
  • Platform: macOS (Darwin 25.0.0)
  • Claude Code Version: Latest (2025-10-26)

Root Cause

Terminal applications can enable focus reporting mode (ANSI mode 1004) which causes the terminal to send:

  • ESC[I (or [I) when the terminal gains focus
  • ESC[O (or [O) when the terminal loses focus

These escape sequences are leaking into Claude Code's input interface instead of being filtered out.

Steps to Reproduce

  1. Launch Claude Code in WezTerm
  2. Click in the input area with mouse
  3. Use modifier keys (Cmd, Shift, etc.)
  4. Observe [I or [O characters appearing in the input

Expected Behavior

Claude Code should filter focus reporting escape sequences (CSI I and CSI O) from user input, similar to how other terminal applications handle these sequences.

Actual Behavior

The raw escape sequence characters appear in the input field, interfering with normal typing and command input.

Technical Details

Focus Reporting Overview:

  • Enabled by: ESC[?1004h
  • Disabled by: ESC[?1004l
  • Focus gained sends: ESC[I
  • Focus lost sends: ESC[O

Applications like Vim may enable this mode and sometimes fail to disable it on exit, leaving the terminal in focus reporting mode.

Workarounds

Temporary fix (run in terminal):

printf '\e[?1004l'

Permanent fix (add to shell RC file):

# Disable focus reporting on shell startup
printf '\e[?1004l'

Related Issues

Proposed Solution

Claude Code's input handler should filter the following escape sequences:

  • \x1b[I (focus in)
  • \x1b[O (focus out)
  • Potentially other CSI sequences that shouldn't appear in user input

Impact

This affects users who:

  • Use WezTerm or terminals with focus reporting enabled
  • Have applications (vim, etc.) that leave focus reporting enabled after exit
  • Frequently use mouse or keyboard modifiers while interacting with Claude Code

Thank you for looking into this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:tuibugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions