Skip to content

[Bug]: OSC 52 clipboard copying fails when window/block not focused #2845

@robottwo

Description

@robottwo

Describe the bug

Wave Terminal's OSC 52 (clipboard) implementation requires both window and block focus, which breaks application-initiated clipboard copying when the terminal doesn't have focus. This causes issues with tools like OpenCode/Claude Code that use OSC 52 for programmatic clipboard operations.

To Reproduce

  1. Open Wave Terminal
  2. Run a terminal application that uses OSC 52 to copy text (e.g., OpenCode, tmux with OSC 52 enabled, Neovim with clipboard integration)
  3. Trigger a copy operation from the application
  4. The copy fails silently if Wave Terminal window or the specific block doesn't have focus

Example test:

printf '\033]52;c;%s\a' "$(echo -n 'test copy' | base64)"

This works in iTerm2, Alacritty, kitty, and other terminals regardless of focus state, but fails in Wave Terminal when the window/block isn't focused.

Expected behavior

OSC 52 clipboard writes should succeed regardless of terminal focus state. The security model for OSC 52 is already well-established:

  • Most terminals allow writes without focus (standard behavior)
  • Reads (query with ?) are blocked for security (which Wave correctly does)
  • Size limits prevent abuse (Wave has appropriate 75KB limit)

This is particularly important for:

  • AI coding assistants (OpenCode, Cursor, etc.) that copy code snippets
  • Terminal multiplexers (tmux, screen) with clipboard integration
  • Remote editing workflows (Vim/Neovim over SSH)

Code Reference

The focus check is in frontend/app/view/term/termwrap.ts:

function handleOsc52Command(data: string, blockId: string, loaded: boolean, termWrap: TermWrap): boolean {
    if (!loaded) {
        return true;
    }
    const isBlockFocused = termWrap.nodeModel ? globalStore.get(termWrap.nodeModel.isFocused) : false;
    if (!document.hasFocus() || !isBlockFocused) {
        console.log("OSC 52: rejected, window or block not focused");
        return true;  // ← This rejects valid clipboard operations
    }
    // ... rest of implementation is correct
}

Suggested Fix

Remove the focus check for OSC 52 writes. The existing size limits and query blocking provide adequate security:

function handleOsc52Command(data: string, blockId: string, loaded: boolean, termWrap: TermWrap): boolean {
    if (!loaded) {
        return true;
    }
    // Remove: if (!document.hasFocus() || !isBlockFocused) check
    
    // Keep all existing validation (size limits, query blocking, etc.)
    // ...
}

Desktop

  • OS: macOS 15.2
  • Wave Terminal: v0.13.1 (but affects all versions with OSC 52 support)
  • Also affects: Linux, Windows

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions