From 1ece29e1fdec6937cfc2a95cd8e037a7019d5b73 Mon Sep 17 00:00:00 2001 From: gastown/crew/jack Date: Sat, 10 Jan 2026 23:27:37 -0800 Subject: [PATCH] fix(tmux): send Escape before Enter for vim mode compatibility NudgeSession and NudgePane now send Escape key before Enter to exit vim INSERT mode if enabled. Harmless in normal mode. Fixes #307 Co-Authored-By: Claude Opus 4.5 --- internal/tmux/tmux.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/tmux/tmux.go b/internal/tmux/tmux.go index afa03fd0..117beacb 100644 --- a/internal/tmux/tmux.go +++ b/internal/tmux/tmux.go @@ -281,7 +281,7 @@ func (t *Tmux) SendKeysDelayedDebounced(session, keys string, preDelayMs, deboun // NudgeSession sends a message to a Claude Code session reliably. // This is the canonical way to send messages to Claude sessions. -// Uses: literal mode + 500ms debounce + separate Enter. +// Uses: literal mode + 500ms debounce + ESC (for vim mode) + separate Enter. // Verification is the Witness's job (AI), not this function. func (t *Tmux) NudgeSession(session, message string) error { // 1. Send text in literal mode (handles special characters) @@ -292,7 +292,12 @@ func (t *Tmux) NudgeSession(session, message string) error { // 2. Wait 500ms for paste to complete (tested, required) time.Sleep(500 * time.Millisecond) - // 3. Send Enter with retry (critical for message submission) + // 3. Send Escape to exit vim INSERT mode if enabled (harmless in normal mode) + // See: https://github.com/anthropics/gastown/issues/307 + _, _ = t.run("send-keys", "-t", session, "Escape") + time.Sleep(100 * time.Millisecond) + + // 4. Send Enter with retry (critical for message submission) var lastErr error for attempt := 0; attempt < 3; attempt++ { if attempt > 0 { @@ -318,7 +323,12 @@ func (t *Tmux) NudgePane(pane, message string) error { // 2. Wait 500ms for paste to complete (tested, required) time.Sleep(500 * time.Millisecond) - // 3. Send Enter with retry (critical for message submission) + // 3. Send Escape to exit vim INSERT mode if enabled (harmless in normal mode) + // See: https://github.com/anthropics/gastown/issues/307 + _, _ = t.run("send-keys", "-t", pane, "Escape") + time.Sleep(100 * time.Millisecond) + + // 4. Send Enter with retry (critical for message submission) var lastErr error for attempt := 0; attempt < 3; attempt++ { if attempt > 0 {