claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Shift+Enter Does Not Insert New Line in WSL on Windows 10

Open sap2me opened this issue 6 months ago • 11 comments

Environment Platform (select one):

Anthropic API

AWS Bedrock

Google Vertex AI

Other: Claude CLI

Claude CLI version: 1.0.2 (Claude Code)

Operating System: Windows 10 (10.0.19045.3803)

Terminal: Windows Terminal (WSL)

WSL version: 2.4.13.0

Kernel version: 5.15.167.4-1

WSLg version: 1.0.65

Shell: bash

Bug Description Pressing Shift+Enter inside Claude CLI running in WSL on Windows 10 does not insert a new line. Instead, it behaves the same as pressing Enter, which prematurely submits the current input. This prevents users from writing multiline prompts or code blocks.

Steps to Reproduce Open Claude CLI (claude) in WSL (bash shell) using Windows Terminal

Start typing a multiline prompt or code

Press Shift+Enter expecting a newline

Input is submitted instead of moving to the next line

Expected Behavior Shift+Enter should insert a new line, allowing users to write properly formatted multiline input without submitting prematurely.

Actual Behavior Shift+Enter submits the input, just like Enter, making multiline prompts impossible.

Additional Context This affects productivity when writing structured prompts or code snippets. Reproducible consistently on a clean WSL 2 environment with Windows 10. Would be helpful to support standard multiline input behavior.

sap2me avatar May 23 '25 10:05 sap2me

Same issue, very annoying. Makes it hard to talk to Claude. Also loving the extension, thanks team

StephenBadger avatar May 23 '25 16:05 StephenBadger

@sap2me I'm using their recommendation \ + return in order to add new lines.

related https://github.com/anthropics/claude-code/issues/729

heat avatar May 23 '25 23:05 heat

@sap2me I'm using their recommendation \ + return in order to add new lines.

related #729

But this isn’t the solution. In every work you are using shift + enter for a new line and this is for years like this. Really hard to train yourself to use something else for a new line

isi2010 avatar May 30 '25 14:05 isi2010

I tried adding this:

[
    {
        "key": "shift+enter",
        "command": "type",
        "args": {
            "text": "\n"
        },
        "when": "claudeCode.chatInputFocused"
    }
]

to keybindings.json and it made no difference. This is super annoying. I'm wasting so many tokens on half finished prompts. I'm starting to compose prompts on a text file and copy and paste, but it makes the workflow slower.

pupeno avatar Jun 01 '25 10:06 pupeno

I think I see what the problem is. Claude Code adds the key binding inside WSL and it needs to be outside. It adds:

[
    {
        "key": "shift+enter",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            "text": "\\\r\n"
        },
        "when": "terminalFocus"
    }
]

to /home/pupeno/.config/Code/User/keybindings.json inside the Linux Claude Code is running into, instead to the correct one of the VSCode that is running, which in my case it's C:\Users\pupeno\AppData\Roaming\Code\User\keybindings.json.

pupeno avatar Jun 01 '25 10:06 pupeno

@pupeno I think that's part of the issue. In my setup, adding that keybinding to the correct keybindings.json file left me with an extra \ when I hit shift+enter:

Image

The keybinding below works most of the time, but sometimes I am still left with the hanging \:

[
  {
    "key": "shift+enter",
    "command": "runCommands",
    "args": {
      "commands": [
        {
          "command": "workbench.action.terminal.sendSequence",
          "args": {
            "text": "\\"
          }
        },
        {
          "command": "workbench.action.terminal.sendSequence",
          "args": {
            "text": "\n"
          }
        }
      ]
    },
    "when": "terminalFocus"
  }
]

So it looks like Claude Code doe snot handle the \ Enter sequence properly if it's sent too quickly

gusbicalho avatar Jun 01 '25 18:06 gusbicalho

@pupeno I think that's part of the issue. In my setup, adding that keybinding to the correct keybindings.json file left me with an extra \ when I hit shift+enter:

Image

The keybinding below works most of the time, but sometimes I am still left with the hanging \:

[ { "key": "shift+enter", "command": "runCommands", "args": { "commands": [ { "command": "workbench.action.terminal.sendSequence", "args": { "text": "\" } }, { "command": "workbench.action.terminal.sendSequence", "args": { "text": "\n" } } ] }, "when": "terminalFocus" } ] So it looks like Claude Code doe snot handle the \ Enter sequence properly if it's sent too quickly

You're a freaking SAVIOR!

mathwcst-bitlyft avatar Jun 23 '25 20:06 mathwcst-bitlyft

Yeah, I also get the "\". I'm just accepting it until the people at Anthropics improve this.

pupeno avatar Jun 23 '25 21:06 pupeno

I think I see what the problem is. Claude Code adds the key binding inside WSL and it needs to be outside. It adds:

[
    {
        "key": "shift+enter",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            "text": "\\\r\n"
        },
        "when": "terminalFocus"
    }
]

to /home/pupeno/.config/Code/User/keybindings.json inside the Linux Claude Code is running into, instead to the correct one of the VSCode that is running, which in my case it's C:\Users\pupeno\AppData\Roaming\Code\User\keybindings.json.

Thanks! this fixed it for me.

Noir-Lime avatar Jun 27 '25 08:06 Noir-Lime

If you are WSL2 user and use Claude Code under Windows Terminal in Windows 11, then you can use CTRL+BACKSPACE (kill word) and SHIFT+ENTER (enter new line) the following way (in Windows Terminal settings, then bottom left Open JSON file, then inside "actions" block add in the beginning):

{"command": {"action": "sendInput", "input": "\n"}, "keys": "shift+enter"}, {"command": {"action": "sendInput", "input": "\u0017"}, "keys": "ctrl+backspace"},

Now you can work like a proper human being ;)

dkarelov avatar Jun 27 '25 14:06 dkarelov

@dkarelov you are a champion 👍 this worked a treat

thomascgray avatar Jun 27 '25 21:06 thomascgray

None of the other solutions worked for me in the VSCode terminal (bash). This is the only approach that worked for me:

// VSC's keybindings.json
// Rule 1: Prevent conflicting commands from running.
    {
        "key": "shift+enter",
        "command": "-workbench.action.terminal.runSelectedText",
        "when": "terminalFocus && !terminalTextSelected"
    },
    // Rule 2: Send the shell's line-continuation syntax.
    {
        "key": "shift+enter",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            // Send a literal backslash (\\) and a newline (\n).
            "text": "\\\n"
        },
        "when": "terminalFocus"
    }

In WSL2, something completely blocks all attempts to modify the key bindings using bind or any other system tools. I tried many different approaches, but the two JSON objects above are the only thing that worked to create the shift+enter behavior in VSCode's terminal and Claud Code's VSCode plugin terminal.

JuliaBonita avatar Jul 01 '25 20:07 JuliaBonita

None of the other solutions worked for me in the VSCode terminal (bash). This is the only approach that worked for me:

// VSC's keybindings.json
// Rule 1: Prevent conflicting commands from running.
    {
        "key": "shift+enter",
        "command": "-workbench.action.terminal.runSelectedText",
        "when": "terminalFocus && !terminalTextSelected"
    },
    // Rule 2: Send the shell's line-continuation syntax.
    {
        "key": "shift+enter",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            // Send a literal backslash (\\) and a newline (\n).
            "text": "\\\n"
        },
        "when": "terminalFocus"
    }

In WSL2, something completely blocks all attempts to modify the key bindings using bind or any other system tools. I tried many different approaches, but the two JSON objects above are the only thing that worked to create the shift+enter behavior in VSCode's terminal and Claud Code's VSCode plugin terminal.

It worked. Thank you!

tsytskanovich avatar Jul 20 '25 08:07 tsytskanovich

None of the other solutions worked for me in the VSCode terminal (bash). This is the only approach that worked for me:

// VSC's keybindings.json
// Rule 1: Prevent conflicting commands from running.
    {
        "key": "shift+enter",
        "command": "-workbench.action.terminal.runSelectedText",
        "when": "terminalFocus && !terminalTextSelected"
    },
    // Rule 2: Send the shell's line-continuation syntax.
    {
        "key": "shift+enter",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            // Send a literal backslash (\\) and a newline (\n).
            "text": "\\\n"
        },
        "when": "terminalFocus"
    }

In WSL2, something completely blocks all attempts to modify the key bindings using bind or any other system tools. I tried many different approaches, but the two JSON objects above are the only thing that worked to create the shift+enter behavior in VSCode's terminal and Claud Code's VSCode plugin terminal.

This has the same problem as the solution that was mentioned here: https://github.com/anthropics/claude-code/issues/1262#issuecomment-2926962304 That will add a backslash at the end of every line.

This is the only solution that works flawlessly (no backslash) on Windows + WSL + VSCode terminal: https://github.com/anthropics/claude-code/issues/2754#issuecomment-3064554102

vitmantug avatar Jul 27 '25 10:07 vitmantug

Fix working for Code on Fedora https://gist.github.com/ben-alkov/1329c25db38cf2ea7ae9ea7fdaf10d3a

ben-alkov avatar Aug 12 '25 17:08 ben-alkov

Related and solution for people on Linux/Ubuntu (I think, at least works for me): https://github.com/anthropics/claude-code/issues/5760#issue-3321991860

simon-ami avatar Aug 14 '25 12:08 simon-ami

No fix for MacOS? still getting the backslash -_-

rublev avatar Sep 08 '25 01:09 rublev

For MacOS and Cursor IDE, the path of the keybinding is "/Users/benyamin/Library/Application Support/Cursor/User/keybindings.json".

In my case, when I open the Claude Code using Cursor/VSCode extension, the Shift + Enter doesn't add a new line. But when I open the Claude Code via terminal or the terminal inside the IDE, it works well.

An alternative solution in this situation in MacOS is using Option + Enter

agn-7 avatar Sep 21 '25 06:09 agn-7

For MacOS and Cursor IDE, the path of the keybinding is "/Users/benyamin/Library/Application Support/Cursor/User/keybindings.json".

In my case, when I open the Claude Code using Cursor/VSCode extension, the Shift + Enter doesn't add a new line. But when I open the Claude Code via terminal or the terminal inside the IDE, it works well.

An alternative solution in this situation in MacOS is using Option + Enter

I'm also having exactly the same issue in MacOS.

kevin-on avatar Sep 27 '25 12:09 kevin-on