Skip to content

Linux/Wayland: clipboard hangs after Ctrl-Z because wl-copy stays in OpenCode process group #42162

Closed as not planned

Description

@ryjen

Description

On Linux/Wayland, copying text from OpenCode and then suspending OpenCode with Ctrl-Z can leave the Wayland clipboard provider stopped.

The result is that pasting into the same terminal after suspending OpenCode hangs indefinitely.

This appears to happen because OpenCode spawns wl-copy in the same terminal process group. wl-copy then forks into the background to serve clipboard requests, but the clipboard-serving process remains in the same process group as OpenCode.

When Ctrl-Z is pressed, the terminal sends SIGTSTP to the foreground process group, stopping both OpenCode and the wl-copy clipboard provider.

The clipboard selection still references that stopped wl-copy process, so a subsequent paste waits on a provider that is suspended.

Running wl-copy in a separate session/process group with setsid fixes the issue completely.

Diagnosis

After reproducing the issue, wl-copy can be observed as stopped:

ps -o pid,ppid,pgid,sid,stat,tty,cmd -C wl-copy

The clipboard-serving wl-copy process has the same process group as OpenCode and its STAT contains T after Ctrl-Z.

Resuming the stopped wl-copy process with SIGCONT allows the paste to proceed again.

Confirmed workaround

Running OpenCode with a private wl-copy wrapper that creates a new session fixes the problem:

#!/usr/bin/env bash
exec setsid /path/to/real/wl-copy "$@"

With this wrapper scoped only to OpenCode:

  1. Copy from OpenCode.
  2. Press Ctrl-Z.
  3. Paste into the same terminal.

The paste works normally.

Likely cause

OpenCode currently invokes wl-copy using a normal child-process spawn.

wl-copy backgrounds itself by forking, but does not create a new process group/session, so the clipboard provider remains part of OpenCode's terminal job-control process group.

This means Ctrl-Z suspends the clipboard provider along with OpenCode.

Possible fix

For the Wayland wl-copy backend, spawn the clipboard process in a separate process group/session so that it is not affected by terminal job-control signals sent to OpenCode.

For example, on Unix this could be implemented using a detached child process / separate process group for wl-copy specifically.

This probably should not be applied indiscriminately to every clipboard command, only to backends such as wl-copy whose clipboard ownership outlives the original write operation.

Environment

  • OS: NixOS / Linux
  • Display server: Wayland
  • Compositor: Hyprland
  • Terminal: Alacritty
  • Clipboard backend: wl-copy / wl-clipboard

Related

#4283 reports more general Linux clipboard failures, but does not appear to cover this Ctrl-Z / process-group / SIGTSTP failure mode.

Plugins

headroom, serena

OpenCode version

1.18.17

Steps to reproduce

  1. Run OpenCode in a Wayland terminal.
  2. Copy some text from OpenCode.
  3. Press Ctrl-Z to suspend OpenCode.
  4. Paste into the shell that is now in the foreground in the same terminal.
  5. The paste hangs indefinitely.

Pasting into another terminal before suspending OpenCode works normally.

Screenshot and/or share link

No response

Operating System

NixOS 26

Terminal

Alacritty

Activity

  1. ryjen commented on Aug 13, 2026

    @ryjen
    Author

    The root cause has now been reproduced independently and patched upstream:

    The patch moves the background wl-copy provider into its own process group
    while keeping it in the same session.

    Regression testing confirms:

    • baseline: Ctrl-Z stops wl-copy and paste does not complete
    • patched: wl-copy survives Ctrl-Z and paste succeeds

    Depending on wl-clipboard upstream resolution, OpenCode may still want a
    compatibility workaround for older installed versions.

  2. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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

Metadata

Metadata

Assignees

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