fix: handle non-file URI schemes in runTerminalCommand for WSL2#9325
Conversation
The fileURLToPath function can throw "The URL must be of scheme file" in some WSL2/remote environments with malformed URIs. Wrap in try-catch to fall through to HOME directory fallback. Fixes continuedev#8091 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Learn moreAll Green is an AI agent that automatically: ✅ Addresses code review comments ✅ Fixes failing CI checks ✅ Resolves merge conflicts |
Parse vscode-remote://wsl+distro/path URIs to extract the actual workspace path instead of falling back to Windows HOME directory. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="core/tools/implementations/runTerminalCommand.ts">
<violation number="1" location="core/tools/implementations/runTerminalCommand.ts:58">
P2: The `url.pathname` returns URL-encoded strings (e.g., `/home/user/my%20project` instead of `/home/user/my project`). Workspace paths containing spaces or special characters will fail because the encoded path doesn't exist on the filesystem. Use `decodeURIComponent(url.pathname)` to match the decoding behavior of `fileURLToPath()` used for file:// URIs.</violation>
</file>
Reply to cubic to teach it or ask questions. Tag @cubic-dev-ai to re-run a review.
Paths with spaces or special characters (e.g., /home/user/my%20project) need decodeURIComponent() to match actual filesystem paths. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests cover: - Basic WSL URI parsing - URL-encoded spaces and special characters - Unicode path handling - Different WSL distro names - Priority of WSL URIs over file:// URIs - Fallback behavior - Edge cases (plus signs, percent signs, mixed encoding) - Comparison with fileURLToPath behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="core/tools/implementations/resolveWorkingDirectory.vitest.ts">
<violation number="1" location="core/tools/implementations/resolveWorkingDirectory.vitest.ts:133">
P2: Environment variable modification should use `afterEach` or `try/finally` to ensure cleanup runs even if assertions fail. If this test fails, `process.env.HOME` remains set to `/test/home`, potentially causing flaky behavior in subsequent tests.</violation>
</file>
Reply to cubic to teach it or ask questions. Tag @cubic-dev-ai to re-run a review.
Ensures process.env.HOME is restored even if assertions fail, preventing flaky behavior in subsequent tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Documents workarounds for: - Building VSIX from WSL2 (extension host selection) - File count issues affecting activation - Terminal command working directory resolution 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
d88cbc5 to
6b30a88
Compare
|
Before & after for reference. (With PR #9314 fix.) (gpt-oss-20b) |
RomneyDa
left a comment
There was a problem hiding this comment.
@shanevcantwell Thanks for the contribution! The only blocking change is the CLAUDE.md note
| function resolveWorkingDirectory(workspaceDirs: string[]): string { | ||
| // Handle vscode-remote://wsl+distro/path URIs (WSL2 remote workspaces) | ||
| const wslWorkspaceDir = workspaceDirs.find((dir) => | ||
| dir.startsWith("vscode-remote://wsl"), |
There was a problem hiding this comment.
Is there a way we could write this that isn't so specific to vscode-remote://wsl? I suppose the same issue applies to any non-file URIs? If not obvious this is fine for now but it feels a bit specific
There was a problem hiding this comment.
Agreed, that was overly narrow. I'll re-submit with it more widely applicable.
There was a problem hiding this comment.
We use AGENTS.md instead of CLAUDE.md, if any updates are need to AGENTS.md could you make them there?
There was a problem hiding this comment.
Oops, that was an oversight to be included at all. Removed.
- Remove WSL-specific check in favor of generic URI handling - Support all vscode-remote:// URI schemes (WSL, SSH, dev-container) - Prefer file:// URIs when available, fall back to remote URIs - Add tests for various remote URI formats - Remove CLAUDE.md per reviewer feedback (use AGENTS.md convention) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
RomneyDa
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
|
🎉 This PR is included in version 1.39.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 1.8.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |


Problem
When running
run_terminal_commandin WSL2, it crashes with:Root Cause
The
resolveWorkingDirectoryfunction inrunTerminalCommand.tscallsfileURLToPath()on workspace URIs. In WSL2/remote environments,getWorkspaceDirs()can return URIs likevscode-remote://wsl+Ubuntu/pathinstead offile:///path. ThefileURLToPathfunction throws when the scheme isn'tfile://.Fix
Wrap the
fileURLToPathcall in a try-catch so it falls through to the existing HOME directory fallback instead of crashing. This is a minimal, defensive change - 5 lines added.Fixes #8091
Test plan
🤖 Generated with Claude Code
Summary by cubic
Fixes a crash in runTerminalCommand on WSL2 and other remote environments by resolving vscode-remote URIs to working paths and safely handling non-file workspace URIs. Falls back to HOME when resolution fails.
Written for commit 8e5a7c2. Summary will update on new commits.
Continue Tasks
Powered by Continue