Skip to content

fix: stop is_wsl false-positiving in Docker on a WSL2 host#56

Merged
bushidocodes merged 1 commit into
masterfrom
fix/is-wsl-docker-false-positive
Jun 16, 2026
Merged

fix: stop is_wsl false-positiving in Docker on a WSL2 host#56
bushidocodes merged 1 commit into
masterfrom
fix/is-wsl-docker-false-positive

Conversation

@bushidocodes

Copy link
Copy Markdown
Owner

Problem

A Docker container shares the host kernel, so on a WSL2 host /proc/version inside the container also contains "microsoft" and is_wsl() returned true. On every shell start that triggered init_node -> remove_win_node_from_path -> get_win_c_path -> wslpath, which doesn't exist in the container:

/root/.dotfiles/utils.sh: line 33: wslpath: command not found

(plus bogus Explorer.exe/clip.exe aliases). Non-fatal, but noisy and wrong.

Fix

Keep the kernel check, but also require a WSL-only interop marker:

is_wsl() {
    grep -qi microsoft /proc/version || return 1
    [ -n "${WSL_DISTRO_NAME:-}" ] || [ -e /run/WSL ] || command -v wslpath >/dev/null 2>&1
}

Real WSL2 has all three markers; a container on a WSL2 host has none.

Verification (container running on a WSL2 host)

plain container (no markers)        -> is_wsl FALSE   (fixed)
WSL_DISTRO_NAME set                 -> is_wsl TRUE    (no regression)
/run/WSL exists                     -> is_wsl TRUE
wslpath on PATH                     -> is_wsl TRUE
get_win_c_path                      -> exits clean, no wslpath error

Fixes #50

🤖 Generated with Claude Code

A Docker container shares the host kernel, so on a WSL2 host
/proc/version inside the container also contains "microsoft" and is_wsl
returned true. That triggered remove_win_node_from_path -> wslpath on
every shell start, emitting "wslpath: command not found", plus bogus
Explorer.exe/clip.exe aliases.

Additionally require a WSL-only interop marker ($WSL_DISTRO_NAME,
/run/WSL, or a wslpath binary). Real WSL2 has all three; a container on
a WSL2 host has none.

Verified in a container on a WSL2 host: is_wsl is now false there (no
wslpath noise) and still true when any WSL marker is present.

Fixes #50

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bushidocodes bushidocodes merged commit 913c96b into master Jun 16, 2026
2 checks passed
@bushidocodes bushidocodes deleted the fix/is-wsl-docker-false-positive branch June 16, 2026 02:30
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.

is_wsl() false-positives inside Docker containers on a WSL2 host (wslpath: command not found noise)

1 participant