write text AppleScript delivery causes phantom image re-attachment in TUI (v2.1.59+)
Description
When text is injected into a Claude Code session via iTerm2's AppleScript write text command, the TUI re-attaches a phantom image from the session's image history alongside the delivered text. The delivered text appears as [Pasted text #N +M lines] and a previously submitted image appears as [Image #N] (↑ to select) — without any user action.
This started after upgrading from Claude Code 2.1.58 to 2.1.62 (auto-update via stable channel). The behavior does not occur in 2.1.58.
Reproduction Steps
- Open Claude Code in an iTerm2 tab
- Submit a message that includes an image (e.g., paste a screenshot path)
- From a separate process, inject text into the same session via AppleScript:
``applescript``
tell application "iTerm2"
repeat with w in windows
repeat with t in tabs of w
repeat with s in sessions of t
if profile name of s is "YourProfile" then
tell s to write text "Hello from automation" without newline
end if
end repeat
end repeat
end repeat
end tell
- Observe: the injected text appears as
[Pasted text #N]AND a previously submitted image reappears as[Image #N] (↑ to select)in the input bar
Expected Behavior
Only the injected text should appear in the input bar. No image from session history should be re-attached.
Actual Behavior
The injected text appears as [Pasted text #N +M lines] AND a phantom [Image #N] (↑ to select) appears alongside it, re-attaching a previously submitted image from the session's history.
Key Observations
- Manual Cmd+V paste does NOT trigger this behavior — only programmatic
write textvia AppleScript - The phantom image is always from the same session's history — a previously submitted image gets re-surfaced
- Frequency matches
write textinjection frequency — in our setup, an email delivery daemon injects text ~3-4 times/hour, and every injection produces a phantom image - Cross-session images observed — images submitted by the user in one tab's session appear as phantoms in a different tab's session after
write textinjection - Clipboard state is irrelevant — the phantom appears even when the system clipboard contains no text/image path (verified via
osascript -e 'clipboard info'showing only TIFF/PNG image data, no text)
Environment
- Claude Code version: 2.1.62 (stable channel, native installer)
- Previously working version: 2.1.58
- OS: macOS 26.3 (Darwin 25.3.0), Apple Silicon
- Terminal: iTerm2 (Build 3.5.x)
- Platform: macOS
Likely Regression Range
The /copy command introduced in v2.1.59 added clipboard state management to the TUI. This is the only change in the 2.1.58→2.1.62 range that touches clipboard/paste infrastructure. The phantom image behavior may be a side effect of that feature's input classification logic.
Related Issues
- #29365 — Intermittent image paste failures (50-60% success rate), attributed to "race condition or focus management issue in TUI clipboard event handling"
- #15553 — Programmatic input submission challenges; documents that Ink's
ink-text-inputcomponent differentiates between physical Enter and programmatic\r/\n - #13183 — Bracketed paste mode mishandling
Impact
This affects any automation that uses iTerm2's write text to programmatically deliver text to Claude Code sessions. In our case, a 19-agent multi-agent system with an email delivery daemon — phantom images appear in teammate sessions 3-4 times per hour, disrupting workflow.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗