opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Provide means to disable Ctrl-C

Open hwacookie opened this issue 3 months ago • 13 comments

Maybe it's just me, but using opencode under windos in WezTerm or Microsofts Terminal App is nearly impossible for me if I cannot stop opencode from crashing whenever I press Ctrl+C. I can live with this not doing what its supposed to do (Copy to clipboard), but simply quitting the program is really bad. Now, I have read about keybindings and the possibility to set an action to "none", (default for "quit" is Ctrl+C), but this does not help because (I guess) Ctrl+C is captured somewhere before it even reaches the keyboard handler. This is what I see in the terminal:

panic: close of closed channel

goroutine 1 [running]: github.com/sst/opencode/internal/components/status.(*statusComponent).Cleanup(0xc00020a1e0) /home/runner/work/opencode/opencode/packages/tui/internal/components/status/status.go:319 +0x25 github.com/sst/opencode/internal/tui.Model.Cleanup(...) /home/runner/work/opencode/opencode/packages/tui/internal/tui/tui.go:948 main.main() /home/runner/work/opencode/opencode/packages/tui/cmd/opencode/main.go:166 +0xce9

hwacookie avatar Oct 06 '25 20:10 hwacookie

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

  • #1455: Similar terminal state corruption and Ctrl-* key handling issues
  • #2232: Related Ctrl+C behavior problems with prompt handling
  • #2512: Issues with Ctrl-C interrupts and exit behavior

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

github-actions[bot] avatar Oct 06 '25 20:10 github-actions[bot]

hm isn't ctrl+c used to stop programs? It shouldn't be causing a panic we will need to check that out but when doing a ctrl + c on a running program, doesn't the kernel send a SIGINT or whatever the windows equivalent is?

rekram1-node avatar Oct 06 '25 20:10 rekram1-node

to copy things you should be able to drag select with your cursor to copy user & assistant messages, in next version of tui the copy behavior will be better right now it is poor

rekram1-node avatar Oct 06 '25 20:10 rekram1-node

@hwacookie , CTRL+C is meant to exit the application. You can configure Wezterm to use another bind to copy and paste. I use Ctrl+Shift+C and Ctrl+Shift+V to copy and paste respectively

from https://github.com/sageil/wezterm/blob/main/README.md

	{ key = "c", mods = "CTRL|SHIFT", action = act.CopyTo("ClipboardAndPrimarySelection") },
	{ key = "v", mods = "CTRL|SHIFT", action = act.PasteFrom("Clipboard") },

sageil avatar Oct 07 '25 02:10 sageil

Thanks for the hints, I know that Ctrl+C is used to interrupt applications (especially CLI apps) in the Linux/Unix world. However, having that behaviour is very unusual for a Windows user, especially since the Ctrl+C, Ctrl+V keystrokes are "hardwired" for copy/paste operations. Having this abort the app is a real bad UX, especially since the session is not automatically continued upon restart. Two other things: e.g. nano does NOT simply "die" when pressing Ctrl+C. Heck, not even opencode itself simply dies upon Ctrl+C - but only when I use it under WSL. The "drop-dead" behaviour only occurs when being used in Windows Terminal (or WezTerm, and probably others as well)

@sageil : No, I think this is not correct: Yes, Ctrl+C is one of the keybindings that is used to exit the applications, but the documentation also mentions that it is possible to redefine that key to something else, so Ctrl+C should then NOT exit the application anymore. I think, opencode does not even "handle" or "see" the Ctrl+C at all, at least thats what I'd guess from the stacktrace that I get when the app terminates. I suppose they'd need to integrate a "Break" handler or something like that, I remember I had to do something like that for my Java-apps as well: https://stackoverflow.com/questions/1611931/catching-ctrlc-in-java I suppose the same applies to go programs as well?!

hwacookie avatar Oct 07 '25 10:10 hwacookie

Ok, half an hour of waiting opencode work done, and here we have the results... Let me copy the file answer with default Windows copy short-cut "Ctrl+C", oops, it terminated opencode... how do I now restore the session to recovered the lost job?

Thorium avatar Oct 29 '25 09:10 Thorium

I do know the old MS-DOS Ctrl+Shift+Insert and Shift+Insert works, it's just that last 25 years have rewired my brain to try first the Windows standard.

Edit: It works if you press it quickly, it asks for confirm, but pressing long and hard, then it dies immediately

Thorium avatar Oct 29 '25 09:10 Thorium

@Thorium you can use /sessions to navigate to previous sessions all the work is persisted to disk

rekram1-node avatar Oct 29 '25 15:10 rekram1-node

I've configured my Wezterm to behave in 1 of 2 ways when control-C is pressed:

  1. When any text is selected, it copies it.

  2. If no text is selected, it does the normal ctrl-C, which on linux distros stops the current process (sends SIGTERM to it).

Here is the part of my wezterm config that makes this work:

https://github.com/pmarreck/dotconfig/blob/yolo/wezterm/wezterm.lua#L133

Personal bias: Just don't use Windows unless you are gaming. It's going to constantly be an uphill battle for any sort of real development work these days, unless you are doing PURELY Windows-focused dev (which pretty much doesn't apply to anything anymore UNLESS you are building Windows games). You can trivially configure any AMD/Intel box to dual-boot Linux alongside Windows, with the added benefit of 1) fewer distractions from windows games since rebooting is a pain, 2) the entire huge library of linux open source software available to you without having to force WSL to work with graphical apps properly 3) you get access to really cool stuff like new sliding-window managers such as Niri (for Wayland-based) or PaperWM (for Gnome-based) that are completely unavailable on either macos or windows

/end-rant

pmarreck avatar Oct 29 '25 16:10 pmarreck

I've configured my Wezterm to behave in 1 of 2 ways when control-C is pressed:

  1. When any text is selected, it copies it.
  2. If no text is selected, it does the normal ctrl-C, which on linux distros stops the current process (sends SIGTERM to it).

I'd love this to be the default behaviour config.

Thorium avatar Nov 01 '25 08:11 Thorium

Agreed on those 2 for natural feeling Windows defaults

Hona avatar Nov 16 '25 22:11 Hona

to copy things you should be able to drag select with your cursor to copy user & assistant messages, in next version of tui the copy behavior will be better right now it is poor

Seriously? We are the data, not your brain. I do not use opencode because this quirk makes me think if you can't figure this out what else is really wrong with your thinking.

u-dadashek avatar Dec 01 '25 15:12 u-dadashek

I've configured my Wezterm to behave in 1 of 2 ways when control-C is pressed:

  1. When any text is selected, it copies it.
  2. If no text is selected, it does the normal ctrl-C, which on linux distros stops the current process (sends SIGTERM to it).

Here is the part of my wezterm config that makes this work:

https://github.com/pmarreck/dotconfig/blob/yolo/wezterm/wezterm.lua#L133

Personal bias: Just don't use Windows unless you are gaming. It's going to constantly be an uphill battle for any sort of real development work these days, unless you are doing PURELY Windows-focused dev (which pretty much doesn't apply to anything anymore UNLESS you are building Windows games). You can trivially configure any AMD/Intel box to dual-boot Linux alongside Windows, with the added benefit of 1) fewer distractions from windows games since rebooting is a pain, 2) the entire huge library of linux open source software available to you without having to force WSL to work with graphical apps properly 3) you get access to really cool stuff like new sliding-window managers such as Niri (for Wayland-based) or PaperWM (for Gnome-based) that are completely unavailable on either macos or windows

/end-rant

This product has a reasonable chance of adoption by me if the folks running the software do not overlay. You may spend time in rabbit holes, I prefer not to. Ctrl-C is just a very large domain on the keyboard to start fighting over when opencode's adoption might be part of the mission. If not, whatever keep the charm - lose the user.

u-dadashek avatar Dec 01 '25 15:12 u-dadashek