Skip to content

Conversation

@Waxime64
Copy link
Contributor

@Waxime64 Waxime64 commented Nov 17, 2025

Related issues:

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.

Visual Result

image

Last Rust-Cli

image

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

WSL detection & path mapping

  • Detects WSL by checking /proc/sys/kernel/osrelease and the WSL_INTEROP env var
  • Maps Windows drive paths to WSL mount paths (C:\.../mnt/c/...)

Clipboard fallback for WSL

  • When clipboard access fails under WSL, falls back to PowerShell to extract images from the Windows clipboard
  • Saves to a temp file and maps the path back to WSL

UI improvements

  • Shows Ctrl+Alt+V hint on WSL (many terminals intercept plain Ctrl+V)
  • Better error messages for unreadable images

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. 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.

How to try this branch

If you want to try this before it’s merged, you can use my Git branch:

Repository: https://github.com/Waxime64/codex.git
Branch: wsl-image-2

  1. Start WSL on your Windows machine.
  2. Clone the repository and switch to the branch:
    git clone https://github.com/Waxime64/codex.git
    cd codex
    git checkout wsl-image-2
    # then go into the Rust workspace root, e.g.:
    cd codex-rs
  3. Build the TUI binary:
    cargo build -p codex-tui --bin codex-tui --release
  4. Install the binary:
    sudo install -m 0755 target/release/codex-tui /usr/local/bin/codex
  5. From the project directory where you want to use Codex, start it with:
    cd /path/to/your/project
    /usr/local/bin/codex

On WSL, use CTRL+ALT+V to paste an image from the Windows clipboard into the chat.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 17, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Waxime64
Copy link
Contributor Author

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

@Waxime64
Copy link
Contributor Author

I close #5644 and create new PR. Last version have too many commit and merge

@Waxime64
Copy link
Contributor Author

@codex

@chatgpt-codex-connector
Copy link
Contributor

Note

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

@Waxime64 Waxime64 changed the title Fix: Image paste/upload does not work under WSL (Windows Subsystem for Linux) WSL: Paste image does not work Nov 18, 2025
@Loongphy
Copy link

I close #5644
*

and create new PR. Last version have too many commit and merge

why not use force push? There's no need to open a new PR for the same implementation.

However, it seems the Codex team hasn’t really prioritized Windows support — even though both the community and the team themselves have provided fixes #6046 .

@Waxime64
Copy link
Contributor Author

I close #5644
*
and create new PR. Last version have too many commit and merge

why not use force push? There's no need to open a new PR for the same implementation.

However, it seems the Codex team hasn’t really prioritized Windows support — even though both the community and the team themselves have provided fixes #6046 .

I’m agree, but last PR have multiples problem. Fist commit update too many file, multiple change in some class. Yes the result is the same, but now is only the change and not multiple revert.

Other PR have the problem of Codex isn’t sign the CLA.

@Waxime64
Copy link
Contributor Author

image

@Waxime64 Waxime64 changed the title WSL: Paste image does not work FIX: Paste image does not work Nov 19, 2025
@Waxime64
Copy link
Contributor Author

Waxime64 commented Dec 4, 2025

I think I forget nothing

Visual Test
CodexPaste

Rust-CI
https://github.com/Waxime64/codex/actions/runs/19915423862

@dylan-hurd-oai

Copy link
Collaborator

@dylan-hurd-oai dylan-hurd-oai left a comment

Choose a reason for hiding this comment

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

Looking much better! Some final comments

clipboard_paste.rs: fallback for is_probably_wsl and remove public convert_windows_path_to_wsl
@Waxime64
Copy link
Contributor Author

Waxime64 commented Dec 4, 2025

New test with: wsl.exe --install -d Debian --no-launch
Work and WSL is detected

Test with default, Ubuntu and Debian
image

};

// normalize_pasted_path already handles Windows → WSL path conversion,
// so we can directly try to read the image dimensions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Waxime64 final clean-up, can we remove this comment?

@Waxime64
Copy link
Contributor Author

Waxime64 commented Dec 4, 2025

@dylan-hurd-oai: That can be in other ticket. But I found a problem if "Windows interop is disabled". Example on Feudora. The hint to call powershell fail.
I check if I can detect the problem and write the good answer in this case. But for clipboard can work, interop have to be activate. Is activate on Ubuntu (Default value of WSL) and Debian

@dylan-hurd-oai
Copy link
Collaborator

Good find - thanks for investigating. Based on your report, it does not appear to be a regression - i.e. calls that failed before will continue to fail. Therefore I think we can proceed with this fix. Can you open up a new github issue for that specific problem so we can track the new PR accordingly?

@Waxime64
Copy link
Contributor Author

Waxime64 commented Dec 4, 2025

Good find - thanks for investigating. Based on your report, it does not appear to be a regression - i.e. calls that failed before will continue to fail. Therefore I think we can proceed with this fix. Can you open up a new github issue for that specific problem so we can track the new PR accordingly?

I install all WSL linux possible on my computer. I can create the issue and make the correction, but for log in other Bug
image

@dylan-hurd-oai dylan-hurd-oai merged commit ce0b38c into openai:main Dec 4, 2025
26 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2025
@Waxime64 Waxime64 deleted the wsl-image-2 branch December 4, 2025 18:51
@etraut-openai
Copy link
Collaborator

Nice! I'm so happy to see this merged!

@Waxime64, thanks again for the contribution. We really appreciate your diligence and persistence on this one.

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

Labels

needs-response Additional information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants