Skip to content

Bug Report: TUI "Copied to clipboard" toast cannot be disabled #21542

@1353604736

Description

@1353604736

Description

Bug Report: TUI "Copied to clipboard" toast cannot be disabled

Summary

The OpenCode TUI shows a "Copied to clipboard" toast notification whenever text is selected in the terminal, even when the OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT environment variable is set. This creates a duplicate copy experience when using terminals like PowerShell that already have built-in copy-on-select functionality.

Environment

  • Operating System: Windows (PowerShell)
  • OpenCode Version: Latest
  • Terminal: PowerShell (with built-in copy-on-select)

Description

PowerShell and other modern terminals provide built-in copy-on-select functionality. When using OpenCode TUI, selecting text triggers an additional copy operation and displays a "Copied to clipboard" toast notification in the top-right corner. This results in:

  1. Duplicate copying (both PowerShell and TUI copy to clipboard)
  2. Unwanted toast notifications that clutter the UI
  3. Poor user experience for users who prefer terminal-native copy behavior

Expected Behavior

When OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT=1 is set, the TUI should:

  • Not perform any copy operations on text selection
  • Not display "Copied to clipboard" toast notifications
  • Allow the terminal's native copy-on-select behavior to work exclusively

Actual Behavior

The environment variable OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT=1 only partially works:

  • Keyboard and mouse event copy behavior is disabled
  • However, the onCopySelection callback still triggers and shows the toast notification

Root Cause Analysis

The issue is in packages/opencode/src/cli/cmd/tui/app.tsx at lines 336-344 1 :

renderer.console.onCopySelection = async (text: string) => {
  if (!text || text.length === 0) return

  await Clipboard.copy(text)
    .then(() => toast.show({ message: "Copied to clipboard", variant: "info" }))
    .catch(toast.error)

  renderer.clearSelection()
}

This callback doesn't check the OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT flag before executing, unlike other parts of the codebase that do check this flag 2 .

Steps to Reproduce

  1. Open PowerShell terminal
  2. Set environment variable: $env:OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT=1
  3. Start OpenCode TUI: opencode tui
  4. Select any text in the terminal
  5. Observe that "Copied to clipboard" toast still appears in top-right corner

Suggested Fix

Add environment variable check to the onCopySelection callback:

renderer.console.onCopySelection = async (text: string) => {
  if (!text || text.length === 0) return
  if (Flag.OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT) return // Add this line

  await Clipboard.copy(text)
    .then(() => toast.show({ message: "Copied to clipboard", variant: "info" }))
    .catch(toast.error)

  renderer.clearSelection()
}

Impact

This issue affects all users using terminals with built-in copy-on-select functionality (PowerShell, Windows Terminal, etc.) and creates a frustrating duplicate copy experience.

Additional Context

The environment variable OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT is intended to provide Windows Terminal-like behavior where:

  • Ctrl+C copies and dismisses selection
  • Esc dismisses selection
  • Other key input dismisses selection and is passed through

However, due to this bug, the toast notification still appears even when this mode is enabled.

Notes

  • This is a code-level issue that cannot be worked around through configuration
  • The fix is straightforward and involves adding one line to check the environment variable
  • Similar environment variable checks are already implemented elsewhere in the codebase

How to submit this issue:

  1. Go to github.com/anomalyco/opencode/issues
  2. Click "New issue"
  3. Choose "Bug report" template
  4. Copy and paste the content above into the issue description
  5. Fill in any additional required fields
  6. Submit the issue

Wiki pages you might want to explore:

Citations

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingneeds:complianceThis means the issue will auto-close after 2 hours.opentuiThis relates to changes in v1.0, now that opencode uses opentuiwindows

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions