#4025·herdr

OSC 4 palette reply fragments leak into the focused pane when Herdr runs inside tmux 3.6 (macOS)

Author: ConnerV42Created Sep 13, 2026Updated Sep 30, 2026
Labelsbugmaintainer-neededp2macosinput

Symptom

Text like this appears in the focused pane's input (here: Claude Code's prompt), typically after the outer terminal regains focus:

e4/e4e4/e4e4;rgb:0000/afaf/d7d7ffafaf/ffff/5f5fd7/ffff/8787d7d7/5    f5f/5f5fff/afaf/0000

Those are tails of OSC 4;<n>;rgb:… palette replies (xterm-256 cube/gray values).

herdr-client.log at the same moments:

WARN herdr::raw_input: flushing lone escape after input timeout; if this follows an alt chord or focus switch it may reach the pane as plain esc bytes=[27]

Environment

  • Herdr 0.9.0 (stable), macOS (Darwin 25.6, Apple Silicon)
  • Outer terminal: Alacritty → tmux 3.6b (focus-events on) → herdr client in a tmux pane
  • Local session, not remote

Mechanism (from reading v0.9.0 source)

  1. tmux focus-events on forwards ESC[I to the pane → RawInputEvent::OuterFocusGained → outcome.query_host_appearance → Herdr writes ESC[?996n (terminal_theme::HOST_COLOR_SCHEME_QUERY_SEQUENCE).
  2. tmux 3.6 implements mode 2031 and answers ESC[?997;1n → RawInputEvent::HostColorSchemeChanged → outcome.query_host_theme = true unconditionally (src/client/shell/input.rs).
  3. write_host_terminal_theme_query calls host_terminal_theme_query_sequence(should_query_host_terminal_palette()); platform/macos.rs returns true, so Herdr emits 256 × ESC]4;<n>;?ESC\ in one burst — on every focus gain.
  4. tmux 3.6 changed OSC 4 handling: "If tmux receives a palette request (OSC 4) in a pane and the palette entry has not been set, send a request to the most recently used client and forward any response instead" (tmux issue 4665). Each of the 256 queries becomes an async round-trip to Alacritty; replies are relayed back one at a time with arbitrary gaps.
  5. RawInputByteFramer only holds incomplete ESC]10; / ESC]11; replies (starts_with_incomplete_default_color_response). An incomplete ESC]4;… reply at a read boundary hits RAW_INPUT_IDLE_FLUSH_TIMEOUT_MS = 10, gets discarded (discard_until = Osc) or, when the chunk was a bare ESC, flushed as a plain escape (the WARN above). The remainder of that reply then arrives without an introducer and is forwarded to the focused pane as ordinary text.

The same class of bug was fixed for WSL/ConPTY by skipping the palette burst entirely (#2440); macOS-under-tmux has no such exemption, and #549's split-reply fix covers only OSC 10/11.

Suggested fixes

  • Hold incomplete ESC]4; replies the same way OSC 10/11 are held while host_color_replies_awaited > 0, with a longer timeout than 10 ms (tmux forwarding easily exceeds that).
  • Or skip the 256-entry palette burst when TERM_PROGRAM=tmux (like the WSL exemption), and/or only re-query the palette when the reported appearance actually changed rather than on every HostColorSchemeChanged.

Workarounds that stop the recurrence

  • set -g focus-events off in .tmux.conf (removes the per-focus trigger; the burst on Herdr client start remains).
  • Run Herdr directly in the outer terminal instead of inside tmux.