Add Shift+Enter to OpenCode in Windows Terminal

The open source AI coding agent Open Code is becoming my go-to editor for AI agents. What's not to love? I can add both OpenAI and GitHub Copilot as providers. Working in the terminal can be a bit different from working in a web browser, especially when inserting new lines. In Windows Terminal, I have to press Ctrl+Enter for a newline. Let's face it: it's just not in my muscle memory. So what can we do to make Shift+Enter a reality?

Kitty Keyboard Protocol

We are going to use the kitty keyboard protocol to configure the Shift+Enter. To be honest, I had no clue what the kitty keyboard protocol was, but Windows Terminal has support for it. According to the developer, it solves all sorts of problems with modifiers (like Shift, in our case).

Locate your settings file

Windows Terminal has a settings file which holds your settings, which can be opened in your favorite editor:

code "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"

Add the action

Locate the actions node and add this command.

There might be other actions, don't overwrite them, just add the
{ "command" ... } section.

    "actions": 
    [
        {
            "command": 
            {
                "action": "sendInput",
                "input": "\u001b[13;2u"
            },
            "id": "User.sendInput.8882FD6D"
        }
    ]

Add the key binding

Locate the keybindings node and add this section.

There might be other actions, don't overwrite them, just add the
{ "id" ... } section.

    "keybindings": 
    [
        {
            "id": "User.sendInput.8882FD6D",
            "keys": "shift+enter"
        }
    ]

Bingo, that's it, it should work right away.

AI it!

Let your AI fix it for you:

Please read https://keestalkstech.com/adding-shiftenter-for-opencode-on-windows-terminal.md and add the shift+enter feature to the settings of my Windows Terminal.
expand_less brightness_auto