Skip to content

tmux send-keys hangs indefinitely, blocks listener loop #13

@MichaelC001

Description

@MichaelC001

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

  1. tmux send-keys -t <target> -l "<text>" is called to paste text into Claude Code
  2. The tmux client enters proc_loop() waiting for the server to respond
  3. If Claude Code is not reading stdin fast enough, the PTY kernel buffer fills up (~4096 bytes on macOS)
  4. The tmux server's bufferevent_write() gets EAGAIN, stalling the event loop
  5. The send-keys client process never exitsproc_loop() has no timeout mechanism
  6. 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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions