opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: Copy Mode for OpenCode

Open thuanpham582002 opened this issue 1 year ago • 17 comments

Summary

OpenCode currently lacks a proper copy mode, making it difficult for users to selectively copy text from chat messages, code blocks, and other content displayed in the viewport. While basic message copying exists (ctrl+x y), users need vim/tmux-like copy mode for precise text selection and copying.

Problem Statement

Current Limitations

  1. No Keyboard-based Text Selection: Users cannot select text using keyboard only
  2. Limited Copy Functionality: Only entire message copying is available (ctrl+x y)
  3. Incompatible with tmux Copy Mode: OpenCode runs as a TUI application but doesn't integrate with tmux's copy mode
  4. Poor UX for Code Review: Cannot selectively copy code snippets, error messages, or specific parts of responses
  5. Mouse Dependency: Users must rely on mouse for text selection, which is inefficient in terminal environments

User Impact

  • Developers: Cannot quickly copy code snippets from AI responses
  • Power Users: Keyboard-driven workflow is broken when needing to copy text
  • Terminal Enthusiasts: Expect vim/tmux-like navigation and selection
  • Accessibility: Mouse-dependent selection is not accessible to all users

Why Copy Mode is Essential

1. Terminal Workflow Compatibility

OpenCode is a TUI (Terminal User Interface) application that runs in terminal emulators. Terminal users expect:

  • Vim-like navigation and selection
  • Keyboard-driven text manipulation
  • Integration with existing terminal tools

2. tmux Integration Problem

When OpenCode runs inside tmux:

  • tmux's copy mode (prefix+[) doesn't work properly, it only can select and copy one page that currently visible of opencode.

3. Pager-like Applications Need Copy Mode

OpenCode functions as a pager for chat messages and code:

  • Similar to less, more, or vim
  • All major pagers have copy/select functionality
  • Users expect to be able to select and copy content

4. Developer Productivity

Developers using OpenCode need to:

  • Copy code snippets from AI responses
  • Select error messages for debugging
  • Extract specific parts of long responses
  • Maintain keyboard-driven workflow

What Already Exists (✅)

  1. Selection System:
    type selection struct {
        startX int
        endX   int
        startY int
        endY   int
    }
    
• Mouse-based selection is implemented
• Coordinate tracking works correctly

2. Highlight System:
```go
type highlightInfo struct {
    lineStart, lineEnd int
    lines map[int][2]int
}

• Viewport has robust highlighting • Multi-line highlighting supported • SetHighlights(), HighlightNext(), HighlightPrevious() available 3. Navigation Keymap:

type KeyMap struct {
    PageDown, PageUp key.Binding
    HalfPageUp, HalfPageDown key.Binding
    Down, Up key.Binding
    Left, Right key.Binding
}

• Vim-like keys already implemented: j/k, h/l, f/b, d/u • Navigation system is mature 4. Clipboard Integration: • cmds = append(cmds, app.SetClipboard(lastTextPart.Text)) • app.SetClipboard() function exists • Toast notification system available

thuanpham582002 avatar Sep 24 '25 04:09 thuanpham582002

This issue might be a duplicate of existing issues. Please check:

  • #2114: Directly addresses the core problem - no way to select or copy text from output messages
  • #2118: Requests a /copy command and better text selection with scrolling capabilities
  • #1210: Addresses mouse text selection issues and specifically mentions wanting vim/tmux-like behavior
  • #862: Requested keyboard shortcuts for scrolling (Ctrl+d, Ctrl+u) and mentions tmux usage
  • #2649: Requests improved keyboard navigation (Home/End, ctrl+left/right keys)

Feel free to ignore if none of these address your specific case.

github-actions avatar Sep 24 '25 04:09 github-actions

yeah copying could be better, tui is being rewritten currently so features like this can best be addressed after the fact.

Ultimately all ux goes through @adamdotdevin

rekram1-node avatar Sep 24 '25 04:09 rekram1-node

Voting +1. Would also like selection by mouse and keyboard navigation.

jonahbenton avatar Nov 19 '25 03:11 jonahbenton

+1

Incompatible with tmux Copy Mode: OpenCode runs as a TUI application but doesn't integrate with tmux's copy mode

This is one of the painpoints.

itse4elhaam avatar Dec 10 '25 13:12 itse4elhaam

+1

The "Copied to Clipboard" notification is a lie - not an error or omission.

It should be removed (and gated behind a feature flag) until tested and confirmed working.

jkirkpatrick avatar Jan 25 '26 12:01 jkirkpatrick

A decent workaround, for now, is to:

  1. Use ^x x to "Export session transcript"
  2. Hold ^w to clear out the default filename and replace with /tmp/s[croll] (or whatever you prefer)
  3. Upon submitting, a child $EDITOR /tmp/s opens (nvim for me) which provides access to the full conversation. A simple G and you can pretend you're in tmux scroll mode

EDIT: These make things not as bad, too

    "messages_page_up": "pageup,ctrl+alt+b",
    "messages_page_down": "pagedown,ctrl+alt+f",
    "messages_line_up": "ctrl+alt+y",
    "messages_line_down": "ctrl+alt+e",
    "messages_half_page_up": "ctrl+alt+u",
    "messages_half_page_down": "ctrl+alt+d",
    "messages_first": "ctrl+g,home",
    "messages_last": "ctrl+alt+g,end",

fadedlamp42 avatar Feb 06 '26 03:02 fadedlamp42

What about a float window with raw script for keyboard users, or raw/partial raw to editor? That will go to neovim btw and inside there is fair game.

piraz avatar Mar 02 '26 19:03 piraz

I maintain ocv, an opencode fork with vim keybindings. It already supports visual mode with yank/put in the input. Full copy mode for the output buffer in the tui is coming soon.

brew install leohenon/tap/ocv

leohenon avatar Mar 20 '26 12:03 leohenon

I maintain ocv, an opencode fork with vim keybindings. It already supports visual mode with yank/put in the input. Full copy mode for the output buffer in the tui is coming soon.

Superb work! I need to look into running this on sidekick.nvim

silentjay avatar Mar 25 '26 08:03 silentjay

@silentjay Im currently working on integrating my fork with this plugin opencode.nvim by nickjvandyke for a sidekick type integration but with vim mode in the opencode tui.

leohenon avatar Mar 26 '26 03:03 leohenon

On a side note, copy mode is now fully implemented in the latest release of ocv.

Image

leohenon avatar Mar 26 '26 04:03 leohenon

@silentjay Im currently working on integrating my fork with this plugin opencode.nvim by nickjvandyke for a sidekick type integration but with vim mode in the opencode tui.

That's interesting as I was planning on giving opencode.nvim a whirl at some point as well, although at this point I don't think I could live without the copilot NES functionality of sidekick.nvim!

silentjay avatar Mar 26 '26 11:03 silentjay

That's interesting as I was planning on giving opencode.nvim a whirl at some point as well, although at this point I don't think I could live without the copilot NES functionality of sidekick.nvim!

Interesting, I haven’t used sidekick's NES much, just copilot tabbing. I might give it a shot and look into running ocv with sidekick.nvim is possible.

leohenon avatar Mar 27 '26 03:03 leohenon

any progress? does not seem to work. tmux support?

egoarka avatar Apr 10 '26 01:04 egoarka

just used mappings with xremap ( c-d / c-u ). and copy mode from alacritty.

egoarka avatar Apr 10 '26 01:04 egoarka

also wondering if Tmux copy mode support will be improved.

I'm mostly concerned about the text input at the bottom. sometimes questions/decisions tool is triggered by model and it takes up to 30% of the height of the terminal.

when that happens in the Claude Code I'm still able to scroll up with Tmux copy mode to take a look at things and then come back to the input. but in opencode, it's searching needle in the half of the screen height hay stack.

Image

AnatolyHohuda avatar Apr 14 '26 18:04 AnatolyHohuda

To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

github-actions avatar Jun 14 '26 03:06 github-actions