{"repo":"NousResearch/hermes-agent","public_id":"22379","display_label":"Classic Hermes CLI multiline newline shortcuts not inserting newlines","summary":"Members consistently concern key combinations such as Shift+Enter, Ctrl+J, Alt/Option+Enter, and Ctrl+Enter submitting the prompt or failing to insert a newline in the classic Hermes CLI. They span several environments (WSL, SSH, macOS, Warp, Windows Terminal), and include both bug reports and proposed fixes.","subsystem":"hermes_cli","kind":"bug","counts":{"members":13,"open_issues":1,"open_issues_distinct":1,"open_prs":2,"closed_issues":4,"merged_prs":1,"attempt_prs":7},"landed_fix":{"status":"merged_to_main","basis":"structural","pr":22777,"merged_at":"2026-05-09T19:48:14+00:00"},"resolution":{"state":"partially_resolved","by":"pr-22777"},"freshness":{"state":"stale","last_verified_at":"2026-05-09T19:48:14+00:00","is_stale":true},"grouping":{"backbone":"STRUCTURAL_PARTIAL","link_density":0.12102564102564102},"fix_edges":[{"issue_number":22379,"pr_number":22777,"tier":"verified","basis":"closing_ref","confidence":0.95,"recoverable_from_timeline":true,"pr_merged_at":"2026-05-09T19:48:14+00:00"}],"members":[{"kind":"issue","number":22379,"title":"Ctrl+Enter newline submits prompt over SSH/WSL because c-j is bound as submit","url":null,"state":"closed"},{"kind":"issue","number":22908,"title":"[Bug]: Shift+Enter no longer inserts a newline in classic Hermes CLI","url":null,"state":"open"},{"kind":"issue","number":23573,"title":"[Feature]: When using Hermes Agent in WSL, I used to be able to press **Ctrl+J** to wrap lines when entering commands, but this no longer works now. Currently, **Ctrl+J**, **Shift+Enter**, and **Alt+Enter** all fail to create a new line.","url":null,"state":"closed"},{"kind":"issue","number":24837,"title":"[Bug][Regression]: Shift+Enter / Option+Enter submit prompt instead of inserting newline on Hermes CLI (not --tui) since 0.13.0","url":null,"state":"closed"},{"kind":"issue","number":25568,"title":"[Bug]: Shift+Enter triggers send instead of newline","url":null,"state":"closed"},{"kind":"pr","number":22777,"title":"fix(cli): make Ctrl+Enter insert newline on WSL/SSH/Windows Terminal","url":null,"state":"merged","close_reason":{"category":"merged"},"merged":true,"is_fix_pr":true,"fix_tier":"verified","files_changed":["cli.py","hermes_cli/pt_input_extras.py","tests/cli/test_cli_init.py","tests/cli/test_ctrl_enter_newline.py"],"fix_hunks":[{"file":"cli.py","hunks":["@@ -72,9 +72,10 @@\n     _STEADY_CURSOR = None\n \n try:\n-    from hermes_cli.pt_input_extras import install_shift_enter_alias\n+    from hermes_cli.pt_input_extras import install_shift_enter_alias, install_ctrl_enter_alias\n     install_shift_enter_alias()\n-    del install_shift_enter_alias\n+    install_ctrl_enter_alias()\n+    del install_shift_enter_alias, install_ctrl_enter_alias\n except Exception:\n     pass\n import threading","@@ -1862,6 +1863,37 @@ def _strip_leaked_bracketed_paste_wrappers(text: str) -> str:\n )\n \n \n+def _preserve_ctrl_enter_newline() -> bool:\n+    \"\"\"Detect environments where Ctrl+Enter must produce a newline, not submit.\n+\n+    Native Windows, WSL, SSH sessions, and Windows Terminal all send Ctrl+Enter\n+    as bare LF (c-j). On those terminals c-j must NOT be bound to submit;\n+    binding it to submit makes Ctrl+Enter (intended as 'newline like Alt+Enter')\n+    submit instead. Local POSIX TTYs that deliver Enter as LF (docker exec,\n+    some thin PTYs without SSH) still need c-j bound to submit, so we keep\n+    that binding for those.\n+\n+    See issue #22379.\n+    \"\"\"\n+    if sys.platform == \"win32\":\n+        return True\n+    if any(os.environ.get(v) for v in (\"SSH_CONNECTION\", \"SSH_CLIENT\", \"SSH_TTY\")):\n+        return True\n+    if os.environ.get(\"WT_SESSION\"):\n+        return True\n+    if \"microsoft\" in os.environ.get(\"WSL_DISTRO_NAME\", \"\").lower():\n+        return True\n+    # WSL detection — env vars can be scrubbed under sudo, also peek /proc.\n+    for p in (\"/proc/version\", \"/proc/sys/kernel/osrelease\"):\n+        try:\n+            with open(p, \"r\", encoding=\"utf-8\", errors=\"ignore\") as f:\n+                if \"microsoft\" in f.read().lower():\n+                    return True\n+        except OSError:\n+            continue\n+    return False\n+\n+\n def _bind_prompt_submit_keys(kb, handler) -> None:\n     \"\"\"Bind terminal Enter forms to the submit handler.\n ","@@ -1869,13 +1901,15 @@ def _bind_prompt_submit_keys(kb, handler) -> None:\n     some thin PTYs (docker exec, certain SSH flavors) deliver Enter as LF\n     instead of CR — without this, Enter appears dead on those terminals.\n \n-    On Windows, Windows Terminal delivers Ctrl+Enter as a distinct c-j key\n-    while plain Enter is c-m, so we leave c-j unbound here — it becomes the\n-    multi-line newline keystroke, giving Windows users an Enter-involving\n-    newline without any terminal settings changes.\n+    Exception: on Windows, WSL, SSH sessions, and Windows Terminal,\n+    c-j is the wire encoding of Ctrl+Enter (a distinct keystroke from\n+    plain Enter / c-m). We leave c-j unbound there so the c-j newline\n+    handler registered separately can fire — giving the user an\n+    Enter-involving newline keystroke without terminal settings changes.\n+    See _preserve_ctrl_enter_newline() and issue #22379.\n     \"\"\"\n     kb.add(\"enter\")(handler)\n-    if sys.platform != \"win32\":\n+    if sys.platform != \"win32\" and not _preserve_ctrl_enter_newline():\n         kb.add(\"c-j\")(handler)\n \n ","@@ -10855,18 +10889,19 @@ def handle_alt_enter(event):\n             \"\"\"\n             event.current_buffer.insert_text('\\n')\n \n-        if sys.platform == \"win32\":\n+        if _preserve_ctrl_enter_newline():\n             @kb.add('c-j')\n-            def handle_ctrl_enter_newline_windows(event):\n-                \"\"\"Ctrl+Enter inserts a newline on Windows.\n-\n-                Windows Terminal delivers Ctrl+Enter as LF (c-j), distinct\n-                from plain Enter (c-m). This binding makes Ctrl+Enter the\n-                Windows equivalent of Alt+Enter, giving an Enter-involving\n-                newline keystroke without requiring terminal settings changes.\n-                Ctrl+J (the raw LF keystroke) also triggers this by virtue\n-                of being the same key code — a harmless side effect since\n-                Ctrl+J has no conflicting Hermes binding.\n+            def handle_ctrl_enter_newline(event):\n+                \"\"\"Ctrl+Enter inserts a newline on Windows, WSL, SSH, and WT.\n+\n+                Windows Terminal (incl. WSL/SSH sessions through it) delivers\n+                Ctrl+Enter as LF (c-j), distinct from plain Enter (c-m). This\n+                binding makes Ctrl+Enter the equivalent of Alt+Enter on those\n+                terminals, giving an Enter-involving newline keystroke\n+                without requiring terminal settings changes. Ctrl+J (the raw\n+                LF keystroke) also triggers this by virtue of being the same\n+                key code — a harmless side effect since Ctrl+J has no\n+                conflicting Hermes binding. See issue #22379.\n                 \"\"\"\n                 event.current_buffer.insert_text('\\n')\n "]},{"file":"hermes_cli/pt_input_extras.py","hunks":["@@ -49,3 +49,35 @@ def install_shift_enter_alias() -> int:\n             ANSI_SEQUENCES[seq] = alt_enter\n             changed += 1\n     return changed\n+\n+\n+def install_ctrl_enter_alias() -> int:\n+    \"\"\"Map Ctrl+Enter byte sequences to the (Escape, ControlM) key tuple\n+    that Alt+Enter produces, so the existing Alt+Enter newline handler\n+    fires for terminals that emit a distinct Ctrl+Enter.\n+\n+    Sequences mapped:\n+      - \"\\\\x1b[13;5u\"     — Kitty keyboard protocol / CSI-u, modifier=5 (Ctrl)\n+      - \"\\\\x1b[27;5;13~\"  — xterm modifyOtherKeys=2, modifier=5 (Ctrl)\n+      - \"\\\\x1b[27;5;13u\"  — alternate ordering some emitters use\n+\n+    Stock prompt_toolkit doesn't map any of these. Without this alias,\n+    Kitty/mintty/xterm-with-modifyOtherKeys users over SSH never get a\n+    Ctrl+Enter newline — the keystroke arrives as a raw CSI sequence that\n+    falls through to the default character-insert handler. See #22379.\n+\n+    Returns the number of sequences whose mapping was changed.\n+    \"\"\"\n+    try:\n+        from prompt_toolkit.input.ansi_escape_sequences import ANSI_SEQUENCES\n+        from prompt_toolkit.keys import Keys\n+    except Exception:\n+        return 0\n+\n+    alt_enter = (Keys.Escape, Keys.ControlM)\n+    changed = 0\n+    for seq in (\"\\x1b[13;5u\", \"\\x1b[27;5;13~\", \"\\x1b[27;5;13u\"):\n+        if ANSI_SEQUENCES.get(seq) != alt_enter:\n+            ANSI_SEQUENCES[seq] = alt_enter\n+            changed += 1\n+    return changed"]},{"file":"tests/cli/test_cli_init.py","hunks":["@@ -166,13 +166,14 @@ class TestPromptToolkitTerminalCompatibility:\n     def test_lf_enter_binds_to_submit_handler_posix(self):\n         \"\"\"Some thin PTYs deliver Enter as LF/c-j instead of CR/enter.\n \n-        On POSIX we keep the c-j → submit binding so Enter works on thin\n-        PTYs (docker exec, certain SSH configurations). On Windows c-j is\n-        reclaimed as the newline keystroke because Windows Terminal\n-        delivers Ctrl+Enter as LF, and we want an Enter-involving newline\n-        without requiring terminal-settings changes.\n+        On a bare local POSIX TTY (no SSH/WSL/WT) we keep c-j → submit so\n+        Enter works on thin PTYs (docker exec, certain ssh configurations).\n+        On Windows, WSL, SSH sessions, and Windows Terminal we leave c-j\n+        unbound here so it can be used as the Ctrl+Enter newline keystroke\n+        without conflicting with submit. See issue #22379.\n         \"\"\"\n         import sys as _sys\n+        import os as _os\n         from unittest.mock import patch as _patch\n         from prompt_toolkit.key_binding import KeyBindings\n ","@@ -181,14 +182,27 @@ def test_lf_enter_binds_to_submit_handler_posix(self):\n         def submit_handler(event):\n             return None\n \n-        # POSIX: both enter and c-j submit\n-        with _patch.object(_sys, \"platform\", \"linux\"):\n+        # Bare local POSIX (no SSH/WSL markers): both enter and c-j submit.\n+        with _patch.object(_sys, \"platform\", \"linux\"), \\\n+             _patch.dict(_os.environ, {}, clear=True), \\\n+             _patch(\"builtins.open\", side_effect=OSError(\"no /proc\")):\n             kb = KeyBindings()\n             _bind_prompt_submit_keys(kb, submit_handler)\n             bindings = {tuple(key.value for key in binding.keys): binding.handler for binding in kb.bindings}\n             assert bindings[(\"c-m\",)] is submit_handler\n             assert bindings[(\"c-j\",)] is submit_handler\n \n+        # POSIX over SSH: c-j stays free so Ctrl+Enter (sent as LF by\n+        # Windows Terminal / Kitty / mintty over SSH) inserts a newline.\n+        with _patch.object(_sys, \"platform\", \"linux\"), \\\n+             _patch.dict(_os.environ, {\"SSH_CONNECTION\": \"1.2.3.4 5 6.7.8.9 22\"}, clear=True), \\\n+             _patch(\"builtins.open\", side_effect=OSError(\"no /proc\")):\n+            kb = KeyBindings()\n+            _bind_prompt_submit_keys(kb, submit_handler)\n+            bindings = {tuple(key.value for key in binding.keys): binding.handler for binding in kb.bindings}\n+            assert bindings[(\"c-m\",)] is submit_handler\n+            assert (\"c-j\",) not in bindings\n+\n         # Windows: only enter submits; c-j is free for the newline binding\n         # added separately in the prompt setup.\n         with _patch.object(_sys, \"platform\", \"win32\"):"]},{"file":"tests/cli/test_ctrl_enter_newline.py","hunks":["@@ -0,0 +1,105 @@\n+\"\"\"Regression tests for issue #22379 — Ctrl+Enter newline over SSH/WSL.\n+\n+prompt_toolkit treats c-j (LF) as Enter on POSIX so thin PTYs (docker exec,\n+some BSD ssh) that send LF for plain Enter still work. But Windows Terminal\n+(native, WSL, and SSH-forwarded sessions) sends Ctrl+Enter as bare LF — same\n+byte. Without environment-aware gating, binding c-j to submit means\n+Ctrl+Enter submits instead of inserting a newline.\n+\n+These tests pin the gating predicate and the resulting binding behavior.\n+\"\"\"\n+\n+from __future__ import annotations\n+\n+import os\n+import sys\n+from unittest.mock import patch\n+\n+\n+def test_native_windows_preserves_newline():\n+    import cli as cli_mod\n+    with patch.object(sys, \"platform\", \"win32\"):\n+        assert cli_mod._preserve_ctrl_enter_newline() is True\n+\n+\n+def test_ssh_session_preserves_newline_on_linux():\n+    import cli as cli_mod\n+    with patch.object(sys, \"platform\", \"linux\"):\n+        with patch.dict(os.environ, {\"SSH_CONNECTION\": \"1.2.3.4 5 6.7.8.9 22\"}, clear=False):\n+            assert cli_mod._preserve_ctrl_enter_newline() is True\n+\n+\n+def test_ssh_tty_alone_preserves_newline():\n+    import cli as cli_mod\n+    with patch.object(sys, \"platform\", \"linux\"):\n+        # Strip out anything that might leak truth\n+        with patch.dict(os.environ, {\"SSH_TTY\": \"/dev/pts/0\"}, clear=True):\n+            assert cli_mod._preserve_ctrl_enter_newline() is True\n+\n+\n+def test_wsl_distro_name_preserves_newline():\n+    import cli as cli_mod\n+    with patch.object(sys, \"platform\", \"linux\"):\n+        with patch.dict(os.environ, {\"WSL_DISTRO_NAME\": \"Ubuntu-Microsoft\"}, clear=True):\n+            assert cli_mod._preserve_ctrl_enter_newline() is True\n+\n+\n+def test_windows_terminal_session_preserves_newline():\n+    import cli as cli_mod\n+    with patch.object(sys, \"platform\", \"linux\"):\n+        with patch.dict(os.environ, {\"WT_SESSION\": \"abc-def\"}, clear=True):\n+            assert cli_mod._preserve_ctrl_enter_newline() is True\n+\n+\n+def test_pure_local_linux_does_not_preserve():\n+    \"\"\"A bare local Linux TTY (no SSH/WSL/WT) keeps c-j → submit so docker exec\n+    style Enter-as-LF stays usable.\"\"\"\n+    import cli as cli_mod\n+    # Stub out /proc reads — those are the WSL fallback signal.\n+    with patch.object(sys, \"platform\", \"linux\"):\n+        with patch.dict(os.environ, {}, clear=True):\n+            with patch(\"builtins.open\", side_effect=OSError(\"no /proc\")):\n+                assert cli_mod._preserve_ctrl_enter_newline() is False\n+\n+\n+def test_proc_version_microsoft_marker_preserves_newline():\n+    \"\"\"WSL detection via /proc when env vars are scrubbed (sudo etc.).\"\"\"\n+    import cli as cli_mod\n+    from io import StringIO\n+    with patch.object(sys, \"platform\", \"linux\"):\n+        with patch.dict(os.environ, {}, clear=True):\n+            real_open = open\n+            def _fake_open(path, *args, **kwargs):\n+                if \"/proc/version\" in str(path) or \"/proc/sys/kernel/osrelease\" in str(path):\n+                    return StringIO(\"Linux version 5.15.167.4-microsoft-standard-WSL2\")\n+                return real_open(path, *args, **kwargs)\n+            with patch(\"builtins.open\", side_effect=_fake_open):\n+                assert cli_mod._preserve_ctrl_enter_newline() is True\n+\n+\n+# ---------------------------------------------------------------------------\n+# install_ctrl_enter_alias() — ANSI sequence mappings for enhanced terminals\n+# ---------------------------------------------------------------------------\n+\n+\n+def test_install_ctrl_enter_alias_maps_csi_u_sequences():\n+    \"\"\"Kitty / xterm modifyOtherKeys / mintty Ctrl+Enter sequences alias to\n+    Alt+Enter (Escape, ControlM) so the existing newline handler fires.\"\"\"\n+    from hermes_cli.pt_input_extras import install_ctrl_enter_alias\n+    from prompt_toolkit.input.ansi_escape_sequences import ANSI_SEQUENCES\n+    from prompt_toolkit.keys import Keys\n+\n+    install_ctrl_enter_alias()\n+    alt_enter = (Keys.Escape, Keys.ControlM)\n+    for seq in (\"\\x1b[13;5u\", \"\\x1b[27;5;13~\", \"\\x1b[27;5;13u\"):\n+        assert ANSI_SEQUENCES.get(seq) == alt_enter, (\n+            f\"Ctrl+Enter sequence {seq!r} not mapped to Alt+Enter tuple\"\n+        )\n+\n+\n+def test_install_ctrl_enter_alias_idempotent():\n+    \"\"\"Running it twice doesn't double-count or break.\"\"\"\n+    from hermes_cli.pt_input_extras import install_ctrl_enter_alias\n+    install_ctrl_enter_alias()\n+    second = install_ctrl_enter_alias()\n+    assert second == 0  # no further changes after first install\n"]}]},{"kind":"pr","number":22911,"title":"fix(cli): preserve classic multiline on macOS","url":null,"state":"closed","close_reason":{"refs":[{"kind":"commit","value":"c193fdffa24597132d0379b2a1eb61f118168eaf","number":0},{"kind":"commit","value":"cf8862cfa","number":0}],"category":"uncategorized","implication":"needs_llm"},"merged":false},{"kind":"pr","number":22983,"title":"fix(cli): restore Shift+Enter newline in classic Hermes CLI","url":null,"state":"closed","close_reason":{"category":"silent_close","implication":"active"},"merged":false},{"kind":"pr","number":23650,"title":"fix(cli): restore local shift-enter newline","url":null,"state":"closed","close_reason":{"refs":[{"kind":"commit","value":"e021ec5a2f9f","number":0}],"category":"uncategorized","implication":"needs_llm"},"merged":false},{"kind":"pr","number":23921,"title":"fix(cli): preserve LF as newline in Warp terminal (Shift+Enter regression #22908)","url":null,"state":"open","close_reason":{"category":"uncategorized","implication":"needs_llm"},"merged":false},{"kind":"pr","number":25111,"title":"fix(cli): preserve Ctrl-J newline on macOS","url":null,"state":"closed","close_reason":{"refs":[{"kind":"pr","value":"#22911","number":22911},{"kind":"pr","value":"#23448","number":23448},{"kind":"pr","value":"#22908","number":22908}],"category":"uncategorized","implication":"needs_llm"},"merged":false},{"kind":"pr","number":32860,"title":"fix(cli): preserve Ctrl-J newline in CR/LF terminals","url":null,"state":"open","close_reason":{"refs":[{"kind":"commit","value":"94b4ef5b9dd1c57dc9eab4cfbff007b0f777f3a9","number":0}],"category":"implemented_elsewhere","implication":"superseded"},"merged":false},{"kind":"pr","number":61215,"title":"fix(cli): enable standard multiline shortcuts","url":null,"state":"closed","close_reason":{"refs":[{"kind":"pr","value":"#86768","number":86768}],"category":"merged_via","implication":"superseded"},"merged":false}],"trust":{"default_tier":"verified","includes_suggested":false}}