My OpenCode plugin to stop it from quitting on Ctrl+C

My OpenCode plugin to stop it from quitting on Ctrl+C

Switching between Claude Code, Codex, and OpenCode means my muscle memory for Ctrl+C constantly gets me in trouble as I’m accidentally killing my OpenCode sessions and wiping my progress because I’m used to the safer behavior from Claude Code and Codex. To deal with that, I wrote an opencode-v2-double-ctrl-c, a tiny OpenCode v2 TUI plugin that stops OpenCode TUI from quitting on a single Ctrl+C.

The logic is simple. The first Ctrl+C never quits. If you have text typed, it stashes it first (restorable) instead of discarding it. If an agent run is in progress, it interrupts it – same as pressing Esc. Only when the prompt is empty and nothing is running then you get a “press again to exit” hint, and the second press within a defined short window quits the TUI. No network access, no files written, nothing running in the background.

Installation

opencode plugin add opencode-v2-double-ctrl-c

Configuration

If you don’t like default, tune the plugin in the OpenCode’s cli.json file:

{
  "plugins": [["opencode-v2-double-ctrl-c", { "window": 1500, "interrupt": true, "stash": true, "key": "ctrl+c" }]]
}
  • window (default 1500): How quickly the second press must follow to quit, in milliseconds. Lower is stricter. Must be > 0.
  • interrupt (default true): Empty prompt while the agent is running – stop the agent first (true), or offer to quit instead (false).
  • stash (default true): What happens to typed text on ctrl+c – save it for restore (true), or discard it (false).
  • key (default ctrl+c): Which key is guarded. Must be a non-empty key string.

What did it take to create the plugin

  1. GitHub repo – https://github.com/Tojaj/opencode-v2-double-ctrl-c
  2. npm package – https://www.npmjs.com/package/opencode-v2-double-ctrl-c with the opencode-plugin keyword, so it’s installable via opencode plugin add opencode-v2-double-ctrl-c.
  3. opencode.cafe submission
  4. opencode.im submission

The two plugin directories pick up future versions on their own. The opencode.im re-checks npm daily, and opencode.cafe doesn’t track versions at all so both these were a one-time errand.

All the dev work was done with OpenCode v2 TUI and Muse Spark 1.3 Contributor model.

And that was it. Enjoy!

Comments are closed.