Literal ^[[I escape sequence printed to terminal when reattaching to a background session

Open 💬 0 comments Opened Jul 5, 2026 by av-bw

Description

When switching back to a terminal tab running a Claude Code background session (bg) after being away, the raw escape sequence ^[[I is printed as literal text instead of being interpreted by the terminal, right before the session's "currently running as a background agent" message.

Steps to reproduce

  1. Start a Claude Code session, background it (bg / detach)
  2. Switch away to another terminal tab for a while
  3. Switch back to the tab with the backgrounded session
  4. Observe garbled output at the top, e.g.:
^[[ISession <uuid> is currently running as a background agent (bg). Use `claude agents` to find and attach to it, or add --fork-session to branch off a copy.

[worker crashed (exit 1 — exit_with_message) — respawning…]

Expected

No raw escape codes printed to terminal; the reattach message should render cleanly.

Environment

  • macOS (Darwin), iTerm2 (or default Terminal)
  • Multiple Claude Code bg sessions open across tabs

Notes

Suspect this is a focus-reporting escape sequence (\x1b[I, DECSET 1004) leaking through on reattach, possibly a PTY raw-mode / buffering issue when the worker process respawns. Workaround: running reset in the terminal clears it.

View original on GitHub ↗