claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Claude Code WSL2 Environment API Timeout Issue Report

Open Tim096 opened this issue 1 year ago • 6 comments

Claude Code WSL2 Environment API Timeout Issue Report

🖥️ Platform Information

Operating System:

  • Windows + WSL2 Environment
  • WSL Distribution: Ubuntu
  • User Path: /mnt/c/Users/Administrator
  • Environment: conda (base) environment

Claude Code Version:

  • Version: v1.0.60
  • Installation: Claude Max Subscription

Network Environment:

  • WSL IP: 172.26.91.225/20
  • Gateway: 172.26.80.1
  • DNS: 172.26.80.1 (WSL auto-generated)
  • Basic network connectivity: Normal (ping, curl tests pass)

🚨 Primary Issues

1. Persistent API Timeout Errors

API Error (Request timed out.) · Retrying in X seconds… (attempt Y/10)

Frequency: Frequent, especially when using tool functions

Impact Scope:

  • ✅ Basic conversations: Occasionally works (11 seconds completion)
  • ❌ Web search tools: Almost always timeout
  • ❌ Complex tool invocations: Frequently fail
  • ❌ Recently even basic conversations started timing out

📊 Detailed Error Logs

Typical Error Sequence

> Please search for TSLA stock price today
  ⎿  API Error (Request timed out.) · Retrying in 1 seconds… (attempt 1/10)
  ⎿  API Error (Request timed out.) · Retrying in 1 seconds… (attempt 2/10)
  ⎿  API Error (Request timed out.) · Retrying in 2 seconds… (attempt 3/10)
  ⎿  API Error (Request timed out.) · Retrying in 4 seconds… (attempt 4/10)
  Web Search("TSLA stock price today July 26 2025")
* Conjuring… (70s · ⚒ 12 tokens · esc to interrupt)

Network Diagnostics (Proving Basic Network is Normal)

# IPv4 connectivity normal
PING 8.8.8.8: 3-4ms latency, 0% packet loss

# Direct Anthropic API connection normal
curl https://api.anthropic.com
time_total: 0.235583s
time_connect: 0.005079s
time_namelookup: 0.001225s

Tool Invocation Comparison Test

# Local tool invocation: Normal
claude "search for test" → Successfully found local files (11.25s)

# Web search tool: Immediate timeout
claude "use web search to query test" → Immediate API timeout

🔍 Attempted Solutions

1. Network Configuration Optimization

# DNS configuration
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

# TCP optimization
sudo sysctl -w net.ipv4.tcp_window_scaling=1

Result: No improvement

2. Claude Code Configuration Adjustments

claude config set http.timeout 180000
claude config set api.timeout 180000

Result: No improvement

3. Using --no-mcp Parameter

claude --no-mcp "test"

Result: Partial improvement, but web search still timeouts

4. WSL Network Reset

# Windows PowerShell (Admin)
wsl --shutdown
netsh winsock reset
netsh int ip reset

Result: No improvement

🎯 Key Findings

  1. Network Layer Normal: Basic ping, curl, DNS resolution all working properly
  2. Local Tools Normal: grep, ls, find and other local tools work perfectly
  3. Web Tool Specific Issue: Only web search tools experience timeout
  4. WSL2 Specific Problem: Strong suspicion of WSL2 NAT network incompatibility with Claude Code's web search mechanism

📝 Reproduction Steps

  1. Install Claude Code v1.0.60 on Windows + WSL2 environment
  2. Run claude to enter interactive mode
  3. Execute any command requiring web search functionality
  4. Observe "API Error (Request timed out.)" errors

🆘 Suggested Investigation Areas

  1. WSL2 Network Compatibility: Claude Code's web search tool behavior in WSL2 NAT environment
  2. Error Retry Logic: Why retry mechanisms don't work effectively in WSL environments
  3. Network Tool Architecture: How web search tools handle network requests differently from basic API calls

💡 Requested Solutions

  1. WSL2 Environment Support: Official guidance for WSL2-specific network configurations
  2. Best Practices Documentation: Recommended setup for WSL2 environments
  3. Improved Fault Tolerance: Better error handling for web tools in WSL environments
  4. Environment Detection: Automatic optimization based on detected environment (WSL2 vs native)

🔬 Technical Analysis

Working Components:

  • Basic Claude API communication
  • Local file system tools (grep, ls, find, cat)
  • Local directory operations
  • Basic conversational responses

Failing Components:

  • Web search functionality
  • External API tool invocations
  • Long-running tool operations

Timing Analysis:

  • Local tools: 5-15 seconds (normal)
  • Web search attempts: Immediate timeout → retry loop → eventual failure

Report Date: July 26, 2025
Issue Severity: High - Significantly impacts WSL user experience with Claude Code

Tim096 avatar Jul 26 '25 04:07 Tim096

2. Progressive Session Degradation

New Finding: The issue appears to be progressive rather than immediate:

Observed Pattern:

Session Start → Local tools work normally (find, list commands succeed) ↓ After 2-3 successful tool invocations → API timeouts begin ↓ Eventually → Even basic conversations timeout

Evidence:

  • /doctor command returns "(no content)" - diagnostic tools may be affected
  • Local tools initially work: find, List(.) commands succeed
  • Mid-execution timeout: Tools start successfully but timeout during execution
  • Session degradation: Problem gets worse over time within same session

Implication: This suggests a WSL session stability issue rather than a pure network tool problem.

Tim096 avatar Jul 26 '25 05:07 Tim096

Yes, the same situation occurs, and it seems to only happen on WSL2. I rarely encounter API timeouts on Linux or macOS.

clapat-bb avatar Jul 26 '25 12:07 clapat-bb

To add to that, I tested it in the same network environment and found that Linux responded quickly, while WSL2 took much longer. In Linux, under the same environment, the GNOME Terminal responded very stably, but whenever I used the Tabby Terminal, issues arose. In summary, based on my experience, WSL2 is the worst and almost unusable.

clapat-bb avatar Jul 26 '25 12:07 clapat-bb

Was having the same issue and downgrading CC version was the only thing that helped.

WalkerHi11 avatar Jul 26 '25 20:07 WalkerHi11

I'm having the same issue from WSL2 - I have determined that it is not a DNS issue, as others have suggested. The issue started after upgrading to the most recent version of CC as of 7/26/2025. This issue significantly affects my workflow as it can get stuck in API timeout loops for multiple minutes per prompt.

NMRobert avatar Jul 27 '25 09:07 NMRobert

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.

github-actions[bot] avatar Aug 04 '25 14:08 github-actions[bot]