-
Notifications
You must be signed in to change notification settings - Fork 15
tmux send-keys hangs indefinitely, blocks listener loop #13
Description
Related to #5 (Large text not sending).
I've been investigating a more severe version of this problem. tmux send-keys -l can hang indefinitely (not just slow — the process never exits), which blocks the entire listener getUpdates loop and prevents receiving any new Telegram messages.
What happens
tmux send-keys -t <target> -l "<text>"is called to paste text into Claude Code- The tmux client enters
proc_loop()waiting for the server to respond - If Claude Code is not reading stdin fast enough, the PTY kernel buffer fills up (~4096 bytes on macOS)
- The tmux server's
bufferevent_write()getsEAGAIN, stalling the event loop - The
send-keysclient process never exits —proc_loop()has no timeout mechanism - Our Go code calls
cmd.Run()which blocks forever waiting for the process
I found 5 stuck tmux send-keys processes on my machine, one running for 8+ hours.
Ghost messages
After killing the stuck processes, data already written to the tmux server's buffer remains in the PTY kernel buffer. When Claude Code eventually reads stdin, it processes this stale data as new prompts — executing commands the user never sent. This is a security concern since Claude may execute dangerous operations from ghost input.
What I've tried
- Added timeout via
exec.CommandContext— prevents listener hang, but doesn't prevent ghost messages - Sending Escape + Ctrl-U before each send-keys — clears TUI input, but can't flush kernel PTY buffer
- The PTY kernel buffer on macOS is not user-configurable
tmux internals
proc_loop()in proc.c has no timeout- Related tmux issues: send-keys commands are sporadically dropped tmux/tmux#1185, tmux
send-keysvery slow on FreeBSD tmux/tmux#1812, tmux frozen, ls or attach freezing as well tmux/tmux#2324
Environment
- macOS (Darwin), tmux 3.5a, Go
- Happens most often with photo messages (longer text + 2s delay before send-keys)
Any ideas on how to solve the ghost message problem? I've been thinking about this for a while and haven't found a clean solution.