codex - 💡(How to fix) Fix WSL image paste fallback fails when appendWindowsPath=false and Get-Clipboard returns null

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

  1. If the fallback fails, include diagnostic detail in the final error, e.g. whether no PowerShell executable was found or the script exited non-zero. Currently the user only sees the original arboard error, so it is hard to tell that the WSL fallback was attempted.

Root Cause

Root cause hypothesis

Code Example

[interop]
appendWindowsPath = false

---

Failed to paste image: no image on clipboard: The clipboard contents were not available in the requested format or the clipboard is empty.

---

/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe

---

Add-Type -AssemblyName System.Windows.Forms
[Windows.Forms.Clipboard]::ContainsImage()
$img = [Windows.Forms.Clipboard]::GetImage()

---

ContainsImage=True
ImageSize=813x520

---

TIMESTAMP
TARGETS
UTF8_STRING
TEXT

---

["powershell.exe", "pwsh", "powershell"]

---

/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe

---

Get-Clipboard -Format Image

---

/mnt/<drive>/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
/mnt/<drive>/Program Files/PowerShell/7/pwsh.exe

---

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$img = $null
if ([Windows.Forms.Clipboard]::ContainsImage()) {
    $img = [Windows.Forms.Clipboard]::GetImage()
}
if ($null -eq $img) {
    $img = Get-Clipboard -Format Image -ErrorAction SilentlyContinue
}
if ($null -eq $img) {
    exit 1
}

$p = [System.IO.Path]::Combine(
    [System.IO.Path]::GetTempPath(),
    [System.IO.Path]::GetRandomFileName() + ".png"
)
$img.Save($p, [System.Drawing.Imaging.ImageFormat]::Png)
Write-Output $p
RAW_BUFFERClick to expand / collapse

Codex CLI version

codex-cli 0.131.0

Platform

WSL2 Debian on Windows 11, terminal: kitty / xterm-kitty.

My WSL config has Windows PATH appending disabled:

[interop]
appendWindowsPath = false

WSL_INTEROP is still set, and Windows .exe files are executable by absolute path, so this is not the same as WSL interop being disabled.

Issue

Pasting an image into the Codex TUI fails with:

Failed to paste image: no image on clipboard: The clipboard contents were not available in the requested format or the clipboard is empty.

The Windows clipboard does contain an image. Verified from the same WSL environment by launching Windows PowerShell 5.1 via absolute path:

/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe

Using:

Add-Type -AssemblyName System.Windows.Forms
[Windows.Forms.Clipboard]::ContainsImage()
$img = [Windows.Forms.Clipboard]::GetImage()

Output showed:

ContainsImage=True
ImageSize=813x520

The Linux/X11 clipboard side only exposes text targets:

TIMESTAMP
TARGETS
UTF8_STRING
TEXT

and xclip -selection clipboard -t image/png -o reports that image/png is not available.

Root cause hypothesis

codex-rs/tui/src/clipboard_paste.rs has a WSL fallback in try_dump_windows_clipboard_image(), but it fails in this environment for two independent reasons:

  1. The fallback only tries command names:
["powershell.exe", "pwsh", "powershell"]

Those rely on PATH. With [interop] appendWindowsPath = false, none of them resolve, even though Windows PowerShell is executable by absolute path at:

/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
  1. The fallback script uses:
Get-Clipboard -Format Image

In this environment that returns $null, while [Windows.Forms.Clipboard]::GetImage() succeeds for the same clipboard image.

Suggested fix

For the WSL image paste fallback:

  1. After PATH-based candidates fail, try common absolute Windows PowerShell locations under WSL, for example:
/mnt/<drive>/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
/mnt/<drive>/Program Files/PowerShell/7/pwsh.exe

Ideally derive the mount root via wslpath -u 'C:\' or mounted drives instead of hard-coding only /mnt/c.

  1. Prefer the WinForms clipboard API, while keeping the existing cmdlet as a fallback:
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$img = $null
if ([Windows.Forms.Clipboard]::ContainsImage()) {
    $img = [Windows.Forms.Clipboard]::GetImage()
}
if ($null -eq $img) {
    $img = Get-Clipboard -Format Image -ErrorAction SilentlyContinue
}
if ($null -eq $img) {
    exit 1
}

$p = [System.IO.Path]::Combine(
    [System.IO.Path]::GetTempPath(),
    [System.IO.Path]::GetRandomFileName() + ".png"
)
$img.Save($p, [System.Drawing.Imaging.ImageFormat]::Png)
Write-Output $p
  1. When invoking pwsh, pass -STA; PowerShell Core defaults to MTA and WinForms clipboard APIs require STA. Windows PowerShell 5.1 is STA by default.

  2. If the fallback fails, include diagnostic detail in the final error, e.g. whether no PowerShell executable was found or the script exited non-zero. Currently the user only sees the original arboard error, so it is hard to tell that the WSL fallback was attempted.

Related

Possibly related to #7766, #7599, #15612, and #19143, but this report is specifically about the appendWindowsPath=false + Get-Clipboard -Format Image failure path on Codex CLI 0.131.0.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING