Claude Code on WSL

Claude Code WSL2 — Open Links in Windows Browser

Problem

If links from Claude Code or other CLI tools open in a browser inside WSL2, you can route them to your existing Windows browser instead.


How It Works

Set the BROWSER environment variable to the path of your Windows browser executable under /mnt/c/.... Claude Code and many Linux tools read BROWSER to decide which program to launch for URLs.

Some CLI tools ignore BROWSER and delegate to xdg-open instead. For those tools, register the same Windows browser as WSL’s HTTP/HTTPS MIME handler.


Setup

Add to ~/.bashrc:

export BROWSER="/mnt/c/Users/<YourUsername>/AppData/Local/BraveSoftware/Brave-Browser/Application/brave.exe"

Replace the path with your browser of choice. Common paths from WSL:

Browser Path
Brave /mnt/c/Users/<YourUsername>/AppData/Local/BraveSoftware/Brave-Browser/Application/brave.exe
Chrome /mnt/c/Program Files/Google/Chrome/Application/chrome.exe
Edge /mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe
Firefox /mnt/c/Program Files/Mozilla Firefox/firefox.exe

Some tools, including older xdg-open, split BROWSER on spaces, so a path under Program Files breaks them. Link the executable to a path without spaces:

mkdir -p ~/.local/bin
ln -s "/mnt/c/Program Files/Google/Chrome/Application/chrome.exe" ~/.local/bin/chrome.exe

Then set export BROWSER="$HOME/.local/bin/chrome.exe" instead.

Then reload your shell:

source ~/.bashrc

These commands target Ubuntu’s default bash; if you use zsh, use ~/.zshrc instead.

XDG fallback for OAuth and CLI tools

Newer xdg-open detects WSL and opens links in the Windows default browser, ignoring BROWSER and the desktop entry below. Check your copy:

grep -q open_wsl "$(command -v xdg-open)" && echo 'built-in WSL support'

If it prints built-in WSL support, choose the default browser in Windows Settings and skip the rest of this section. Otherwise, check whether WSL still points to another browser:

xdg-settings get default-web-browser
xdg-mime query default x-scheme-handler/https

Record the existing HTTP and HTTPS handlers so you can restore them later:

xdg-mime query default x-scheme-handler/http
xdg-mime query default x-scheme-handler/https
mkdir -p ~/.local/share/applications

Then create ~/.local/share/applications/brave-windows.desktop:

[Desktop Entry]
Name=Brave Browser (Windows)
Comment=Open web links in the Windows Brave profile
Exec=/mnt/c/Users/<YourUsername>/AppData/Local/BraveSoftware/Brave-Browser/Application/brave.exe %U
Terminal=false
Type=Application
Categories=Network;WebBrowser;
MimeType=text/html;x-scheme-handler/http;x-scheme-handler/https;
StartupNotify=false

Register it as the URL handler:

xdg-mime default brave-windows.desktop x-scheme-handler/http
xdg-mime default brave-windows.desktop x-scheme-handler/https

Replace <YourUsername> with the Windows username and adjust Exec when using a different browser. Desktop entries do not expand $BROWSER, so Exec must contain the real executable path. Put the executable path in double quotes in Exec if it contains spaces, as with Chrome under Program Files.


Result

Claude Code and tools that respect BROWSER open URLs directly in the selected Windows browser. Tools that use xdg-open, including some OAuth CLIs, use the XDG fallback and reach the same browser profile.


Troubleshooting

Browser doesn’t open

Wrong browser still opens

Verify and undo

Run "$BROWSER" "https://example.com" and xdg-open "https://example.com" separately. Both should reach the intended Windows browser.

To undo, restore your previous BROWSER assignment (or remove the added export and run unset BROWSER if it was previously unset). Restore each recorded handler using xdg-mime default <previous-handler.desktop> x-scheme-handler/http and the corresponding HTTPS command. If there was no previous handler, remove only the association you added from your user mimeapps.list. Remove the desktop entry only after restoring associations. Open a fresh shell and test again.