Skip to content

Fix: Image paste/upload does not work under WSL (Windows Subsystem for Linux) - #5644

Closed
Waxime64 wants to merge 112 commits into
openai:mainfrom
Waxime64:wsl-image
Closed

Waxime64 wants to merge 112 commits into
openai:mainfrom
Waxime64:wsl-image

Conversation

@Waxime64

@Waxime64 Waxime64 commented Oct 24, 2025 •

Copy link
Copy Markdown
Contributor

Related issue: #4683 #3939 #2292
Area: codex-cli (image handling / clipboard & file uploads)
Platforms affected: WSL (Ubuntu on Windows 10/11). No behavior change on native Linux/macOS/Windows.

Summary

This PR fixes image pasting and file uploads when running codex-cli inside WSL. Previously, image operations failed silently or with permission errors because paths weren't properly mapped between Windows and WSL filesystems.

Root cause

The CLI assumed native Linux/Windows environments and didn't handle the WSL↔Windows boundary:

  • Used Linux paths for files that lived on the Windows host
  • Missing path normalization between Windows (C:...) and WSL (/mnt/c/...)
  • Clipboard access failed under WSL

Why CTRL + V doesn't work in WSL terminals:

Most WSL terminal emulators (Windows Terminal, ConEmu, etc.) intercept Ctrl+V at the terminal level to paste text from the Windows clipboard. This keypress never reaches the CLI application itself, so our clipboard image handler never gets triggered. Users need Ctrl+Alt+V.

Changes

  1. WSL detection & path mapping
  • Detects WSL by checking /proc/sys/kernel/osrelease and WSL_INTEROP env var
  • Maps Windows drive paths to WSL mount paths (C:... → /mnt/c/...)
  1. Clipboard fallback for WSL
  • When clipboard access fails under WSL, falls back to PowerShell to extract images from Windows clipboard
  • Saves to temp file and maps the path back to WSL
  1. UI improvements
  • Shows ctrl + alt + v hint on WSL (many terminals intercept plain ctrl + v)
  • Better error messages for unreadable images

Tests

Manual validation (WSL2, Windows 11)

  • Paste an image from clipboard → works (bytes path).
  • Drag a PNG/JPG from C:\Users\...\Pictures into the terminal → works (WSL fallback copies to temp and uploads).
  • Drag a file from the WSL filesystem (/home/<user>/Downloads/foo.png) → works (no fallback needed).
  • Very large image (12–20 MB) → works; progress and completion messages are correct.
  • Non-image file → correctly rejected with helpful error.

Performance

  • Negligible overhead. The fallback adds a single FS copy to a temp file only when needed.
  • Direct streaming remains the default.

Files changed

  • protocol/src/lib.rs - Added platform detection module
  • protocol/src/models.rs - Added WSL path mapping for local images
  • protocol/src/platform.rs - New module with WSL detection utilities
  • tui/src/bottom_pane/chat_composer.rs - Added base64 data URL support and WSL path mapping
  • tui/src/bottom_pane/footer.rs - WSL-aware keyboard shortcuts
  • tui/src/clipboard_paste.rs - PowerShell clipboard fallback

How to reproduce the original bug (pre-fix)

  1. Run codex-cli inside WSL2 on Windows.
  2. Try to paste an image from the Windows clipboard or drag an image from C:\... into the terminal.
  3. Observe that the image is not attached (silent failure) or an error is logged; no artifact reaches the tool.

How to verify the fix

  1. Build this branch and run codex-cli inside WSL2.
  2. Paste from clipboard and drag from both Windows and WSL paths.
  3. Confirm that the image appears in the tool and the CLI shows a single concise info line (no warning unless fallback was used).

I’m happy to adjust paths, naming, or split helpers into a separate module if you prefer.

@github-actions

github-actions Bot commented Oct 24, 2025 •

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


3 out of 4 committers have signed the CLA.
✅ (Waxime64)[https://github.com/Waxime64]
✅ (dylan-hurd-oai)[https://github.com/dylan-hurd-oai]
✅ (etraut-openai)[https://github.com/etraut-openai]
❌ @codex CLI
Codex CLI seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@Waxime64

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 24, 2025
@Waxime64

Copy link
Copy Markdown
Contributor Author

Hi maintainers 👋

This PR fixes image paste/upload under WSL (see #4683).
Could you please approve and run the workflows for this first-time-contributor PR and assign a reviewer with write access?

I've validated locally (build + clippy + fmt + tests).
Happy to adjust anything you’d like. Thanks!

@Waxime64

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Waxime64

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tui/src/clipboard_paste.rs Resolved
@Waxime64

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Waxime64

Waxime64 commented Oct 26, 2025 •

Copy link
Copy Markdown
Contributor Author

image I copy
image

Codex-Cli with CTRL + ALT + V work on Windows 11 Professionnel
image

@Waxime64

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Waxime64

Copy link
Copy Markdown
Contributor Author

@codex run build-test and Check for spelling errors

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Note

To use Codex here, create an environment for this repo.

@Waxime64

Copy link
Copy Markdown
Contributor Author

@codex run build-test and Check for spelling errors

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Note

To use Codex here, create an environment for this repo.

@Waxime64

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@Waxime64

Copy link
Copy Markdown
Contributor Author

@codex say « I have read the CLA Document and I hereby sign the CLA »

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Note

To use Codex here, create an environment for this repo.

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Note

To use Codex here, create an environment for this repo.

@andrewmaspero

Copy link
Copy Markdown

Please approve this Codex Team... we really need this... it's very fustrating to use on WSL atm.. this will help UX and DX...

@andrewmaspero

Copy link
Copy Markdown

@Waxime64 Looks like it's failing here Error: Committers of Pull Request number 5644 have to sign the CLA 📝

Might need to re-do the "I have read the CLA Document and I hereby sign the CLA" again ?

Great work by the way.. this will be fantastic.. once implemented. :)

@Waxime64

Waxime64 commented Nov 16, 2025 •

Copy link
Copy Markdown
Contributor Author

@Waxime64 Looks like it's failing here Error: Committers of Pull Request number 5644 have to sign the CLA 📝

Might need to re-do the "I have read the CLA Document and I hereby sign the CLA" again ?

Great work by the way.. this will be fantastic.. once implemented. :)

The problem isn't me didn't sign, but Codex ... I can't sign for him. I write issue

3 out of 4 committers have signed the CLA.
✅ (Waxime64)[https://github.com/Waxime64]
✅ (dylan-hurd-oai)[https://github.com/dylan-hurd-oai]
✅ (etraut-openai)[https://github.com/etraut-openai]
❌ @codex CLI

@Waxime64

Copy link
Copy Markdown
Contributor Author

Merge to gpt 5.1 codex

image

@Waxime64

Waxime64 commented Nov 16, 2025 •

Copy link
Copy Markdown
Contributor Author

@Waxime64 Looks like it's failing here Error: Committers of Pull Request number 5644 have to sign the CLA 📝

Might need to re-do the "I have read the CLA Document and I hereby sign the CLA" again ?

Great work by the way.. this will be fantastic.. once implemented. :)

If you can't wait. Get my Git branch
start WSL on your Windows
go in Git Clone directory and go in codex-rs
write this for build: cargo build -p codex-tui --bin codex-tui
install with: sudo install -m 0755 target/release/codex-tui /usr/local/bin/codex
After go in your project directory where you want to use codex
Start codex with: /usr/local/bin/codex

CTRL+ALT+V for paste image from clipboard

@Waxime64

Copy link
Copy Markdown
Contributor Author

recheck

@Waxime64

Copy link
Copy Markdown
Contributor Author

New release: #6793

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants