[BUG] WSL2: Repeated powershell.exe calls for USERPROFILE cause ~60s startup delay

Status Fixed / completed
Maintainer reply None cached
Activity 4 comments · opened Dec 17, 2025 · closed Jan 24, 2026

Description

When running Claude Code in WSL2, the debug log shows 6+ repeated calls to powershell.exe -Command '$env:USERPROFILE', each taking approximately 10 seconds due to WSL2's slow Windows interop. This adds ~60 seconds of unnecessary startup delay.

Debug Log Evidence

From debug log (~/.claude/debug/*.txt):

2025-12-17T16:31:10.479Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (10053.8ms): powershell.exe -Command '$env:USERPROFILE'
2025-12-17T16:31:30.312Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (10069.1ms): powershell.exe -Command '$env:USERPROFILE'
2025-12-17T16:31:40.411Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (10068.6ms): powershell.exe -Command '$env:USERPROFILE'
2025-12-17T16:31:50.559Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (10099.4ms): powershell.exe -Command '$env:USERPROFILE'
2025-12-17T16:32:01.762Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (10171.6ms): powershell.exe -Command '$env:USERPROFILE'
2025-12-17T16:32:12.904Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (10092.9ms): powershell.exe -Command '$env:USERPROFILE'

Total delay: ~60 seconds just from these redundant calls.

Expected Behavior

The USERPROFILE value should be:

  1. Cached after the first lookup, OR
  2. Read from environment variable ($USERPROFILE) instead of spawning PowerShell, OR
  3. Looked up once at startup and reused

Environment

  • Platform: WSL2 on Windows 11
  • Claude Code Version: 2.0.71
  • Shell: bash
  • Linux Distro: Ubuntu (WSL2)

Workaround Attempted

Setting export USERPROFILE="/mnt/c/Users/<username>" in .bashrc does not help because Claude Code explicitly spawns PowerShell rather than reading the environment variable.

Impact

This significantly degrades the user experience for WSL2 users, making Claude Code feel sluggish at startup. WSL2 is a common development environment, especially for users who need Linux tooling on Windows.

Suggested Fix

Cache the USERPROFILE result after the first PowerShell call, or detect WSL and use an alternative method (e.g., parsing /mnt/c/Users/ or reading $USERPROFILE from environment).

View original on GitHub ↗

4 Comments

bryanm1529 · 8 months ago

Running into this too. Wanted to add some data that might help.

On my setup (Claude 2.0.76, WSL2 2.6.3.0, Win11), I'm seeing the same powershell.exe calls but with different timing - about 700-900ms each instead of 10s. The interesting thing is there are way more of them than I expected: 21 calls in the first ~37 seconds, firing roughly every 1.7 seconds.

From my debug log:

  17:31:57.831Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (871ms): powershell.exe -Command '$env:USERPROFILE'
  17:32:03.113Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (789ms): powershell.exe -Command '$env:USERPROFILE'
  17:32:03.888Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (764ms): powershell.exe -Command '$env:USERPROFILE'
  ...
  17:32:33.740Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (696ms): powershell.exe -Command '$env:USERPROFILE'

The calls stop after that initial burst, which explains why the sluggishness goes away after ~30-40 seconds. During that window though, there's noticeable typing lag in the input - feels like the sync calls are blocking the UI thread.

Guessing the per-call latency difference (700ms vs 10s) is system-dependent - maybe AV, disk speed, or WSL config. But the redundant calling pattern seems consistent.

TimonKai · 7 months ago

Adding another data point from Claude Code 2.0.76 on WSL2:

Environment:

  • Claude Code: 2.0.76
  • WSL2 on Windows (Ubuntu)
  • Shell: bash

Observations:

  • 20 PowerShell calls in a single session
  • Each call takes ~1.1-1.15 seconds
  • Total blocking time: ~22 seconds of startup latency
  • Typing is blocked during these calls (can't input text until they complete)

Important finding: I have CLAUDE_CODE_SKIP_WINDOWS_PROFILE=1 set and exported in my .bashrc, confirmed active in my environment, but the deprecated code path ignores this flag entirely.

$ echo $CLAUDE_CODE_SKIP_WINDOWS_PROFILE
1

Debug log excerpt:

2026-01-05T11:09:26.843Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (1139.6ms): powershell.exe -Command '$env:USERPROFILE'
2026-01-05T11:09:28.613Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (1145.4ms): powershell.exe -Command '$env:USERPROFILE'
2026-01-05T11:09:29.755Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (1131.1ms): powershell.exe -Command '$env:USERPROFILE'
2026-01-05T11:09:30.921Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (1148.4ms): powershell.exe -Command '$env:USERPROFILE'
2026-01-05T11:09:33.055Z [DEBUG] [SLOW OPERATION DETECTED] execSyncWithDefaults_DEPRECATED (1117.4ms): powershell.exe -Command '$env:USERPROFILE'
... (15 more calls)

Suggested fix: The execSyncWithDefaults_DEPRECATED function should check for CLAUDE_CODE_SKIP_WINDOWS_PROFILE before spawning PowerShell, or cache the result after the first call.

BigUncle · 7 months ago

Thanks to @tariq2sa, @bryanm1529, and @TimonKai for identifying this issue!

I encountered a similar problem.

Confirmed Workaround

I can confirm that the following environment variables completely resolve the startup delay in WSL2:

# Add to ~/.bashrc
export CLAUDE_CODE_SKIP_WINDOWS_PROFILE=1
export USERPROFILE="/mnt/c/Users/<your-username>"

My Environment

  • OS: Windows 11 + WSL2 (Ubuntu)
  • Terminals tested: Windows Terminal, VS Code integrated terminal
  • Claude Code version: 2.1.7

Before vs After

| Metric | Before | After |
|--------|--------|-------|
| Loading skillsLoaded plugins | ~4100ms | ~7ms |
| setup() completion | ~4400ms | ~50ms |
| /status or /doctor or other command delay | ~2700ms | ~20ms |

Key Observation

Before applying the fix, Windows Terminal was significantly slower than VS Code Terminal. After setting these environment variables, both terminals are equally fast.

This suggests that VS Code's CLAUDE_CODE_ENTRYPOINT=claude-vscode environment may have been partially bypassing this issue, but the root cause (repeated powershell.exe calls) was still present.

Hope this helps other WSL2 users!

github-actions[bot] · 7 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.