Skip to content

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

@tobwen

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

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