Skip to content

TUI mouse control characters appear after CTRL+C with --continue #16564

Closed

Description

@tobwen

Description

Summary

When using TUI with --continue multiple times and exiting with CTRL+C, mouse control characters appear on subsequent runs in certain terminal emulators. The terminal enters an inconsistent state where mouse movements produce escape sequences.

Expected Behavior

Terminal should remain in consistent state after CTRL+C exit. Mouse control characters should not appear on subsequent runs.

Actual Behavior

After exiting with CTRL+C and restarting with --continue, mouse movements produce escape sequences like:

^[[<35;9734M
^[[<35;9834M
^[[<35;9934M

The characters vary depending on mouse position and movement direction.

Affected Environments

This issue only occurs in certain terminal emulators. Tested and confirmed affected:

  • Windows with MinTTY
  • Windows with PuTTY
  • Other terminal emulators with incomplete TTY state restoration

Root Cause

The problematic commit 3ebebe0 introduced a try/finally block around tui() call that caused double cleanup:

const tuiPromise = tui({
  ...,
  onExit: stop,
})

try {
  await tui({..., onExit: stop})
} finally {
  await stop()  // Called again!
}

When CTRL+C is pressed:

  1. onExit: stop is called inside tui()
  2. finally { await stop() } is called outside tui()

This double cleanup corrupts the TTY state, leaving mouse tracking active when it should be disabled. Some terminal emulators are more sensitive to this TTY state corruption than others.

Related Issues

This issue prevents proper usage of the TUI across multiple sessions with --continue in certain terminal environments.

Plugins

none during debugging

OpenCode version

1.2.17, 1.2.18, 1.2.19, 1.2.20, 1.2.21, dev

Steps to reproduce

  1. Run opencode TUI with --continue
  2. Exit with CTRL+C
  3. Run opencode TUI again with --continue
  4. Observe mouse control characters appearing when moving the mouse

Screenshot and/or share link

Image

Operating System

Debian Linux, Trixie, 64-bit

Terminal

Windows: MinTTY, PuTTY

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Mar 8, 2026
  2. github-actions commented on Mar 8, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

    • TUI broken in tmux after 1.2.17 (found root cause) #16351: Same root cause commit (3ebebe0a9) identified, same symptom of mouse escape sequences being injected into the TUI after CTRL+C exit — that issue also notes the double-cleanup/TTY corruption pattern and affects the same version range (1.2.17+). The main difference here is the Windows terminal emulator context (MinTTY, PuTTY).

    You may want to add your findings there or reference it, as the fix tracked in #16351 would likely resolve this as well.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopentuiThis relates to changes in v1.0, now that opencode uses opentui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions