Skip to content

[Feature Request] Add OSC52 clipboard support for copying selected text #415

@Iann29

Description

@Iann29

Add support for copying selected text to the system clipboard using OSC52 escape sequences, enabling clipboard functionality in terminal emulators that support this standard.

Problem

Currently, when using Codebuff CLI in terminal emulators like Ghostty, Kitty, iTerm2, or others:

  1. Text selection doesn't copy to clipboard - Even with copy-on-select = clipboard enabled in the terminal, selected text within Codebuff doesn't get copied to the system clipboard
  2. Standard copy shortcuts are intercepted - Ctrl+C and Ctrl+Shift+C are captured by Codebuff for other purposes (exit confirmation, etc.)
  3. Clipboard managers don't receive selections - Tools like cliphist, elephant-clipboard, or other clipboard history managers never see text selected within Codebuff

This happens because Codebuff is a TUI (Text User Interface) application that captures mouse events, preventing the terminal emulator from handling copy-on-select functionality.

Proposed Solution

Implement OSC52 clipboard support to automatically copy selected text to the system clipboard. The OSC52 escape sequence format is:

\e]52;c;<base64-encoded-text>\a

This is a widely-supported standard that works with:

  • Ghostty
  • Kitty
  • iTerm2
  • Alacritty
  • Windows Terminal
  • Many others

Use Cases

  1. Quick code copying - Users often want to copy code snippets, file paths, or command outputs from Codebuff responses to use elsewhere
  2. Clipboard history integration - Allow clipboard managers to track text copied from Codebuff
  3. Workflow efficiency - Eliminate the need to manually re-type or use workarounds to get text out of the TUI

Alternatives Considered

  • Using wl-copy/xclip directly - Requires external dependencies and doesn't work consistently across platforms
  • Dedicated copy keybinding - Would help, but copy-on-select behavior is more intuitive for terminal users
  • Writing to files - Current workaround, but adds unnecessary friction

Additional Context

  • Environment: Ghostty 1.2.3 on Arch Linux (Hyprland/Wayland)
  • Clipboard manager: elephant-clipboard (via Walker)
  • The terminal's copy-on-select works perfectly outside of Codebuff TUI, confirming this is a TUI-specific issue

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