Skip to content

The agent that grows with you

feat(cli): double ESC discards the draft, even mid-stream

CK iRonin.ITc1ec39416037
diff --git a/cli.py b/cli.py
index c1d5ada5562..8cf25b13f56 100644
--- a/cli.py
+++ b/cli.py
@@ -15592,6 +15592,32 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
event.app.invalidate()
return
+ @kb.add('escape', 'escape', filter=~_modal_prompt_active)
+ def handle_double_escape(event):
+ """Double ESC: discard the current draft and any attached images.
+
+ Matches Claude Code / Gemini CLI, where double-Esc is the
+ clear-the-composer gesture. It works while the agent is
+ streaming, which is the gap Ctrl+C leaves: Ctrl+C interrupts a
+ running turn and only clears the draft when idle, so mid-stream
+ there was no way to discard a half-typed prompt.
+
+ The draft is appended to history first, so Up recalls it — the
+ same undo affordance Claude Code provides, and the reason this
+ is safe to bind to a key pressed by reflex.
+
+ Single ESC is the prefix for Alt sequences (escape+enter,
+ escape+g, escape+v), so prompt_toolkit's escape-timeout keeps
+ those distinct from the double press. Modal prompts bind ESC
+ eagerly and are excluded here so cancel still wins.
+ """
+ buf = event.app.current_buffer
+ if not (buf.text or cli_ref._attached_images):
+ return
+ buf.reset(append_to_history=bool(buf.text))
+ cli_ref._attached_images.clear()
+ event.app.invalidate()
+
@kb.add('c-z')
def handle_ctrl_z(event):
"""Handle Ctrl+Z - suspend process to background (Unix only)."""