continuedev/continue

Command Isssues on Windows

Opened this issue · 3 comments

Before submitting your bug report

Relevant environment info

- OS: Windows
- Continue version:1.3.12
- IDE version: 1.104.1
- Model: Sonnet 4 
- config:
  

  
  OR link to agent in Continue hub:

Description

The Issues:
Mixed Command Syntax: I started with bash/Linux syntax (cd coding-agent && mkdir) which doesn't work in PowerShell. PowerShell uses different operators and syntax.

Directory Navigation Problem: When I used cd coding-agent and then pwd, the output still showed D:\Github\Coding CLI (root directory), which means the cd command didn't actually change directories properly.

Incorrect Path Handling: I was trying to use relative paths inconsistently. PowerShell is more strict about path resolution.

Move Command Execution: The Move-Item command may have appeared to succeed, but the subsequent Get-ChildItem shows we're still seeing the root directory contents, not the coding-agent directory contents.

Directory Creation Location: The original mkdir agents, mcp-servers, sdk-implementations... command created all directories in the root (D:\Github\Coding CLI) instead of inside the coding-agent folder because we weren't actually inside the coding-agent directory.

To reproduce

Log output

-

PowerShell Command Issues in Continue IDE

Root Cause Analysis

Based on analysis of the Continue IDE codebase, the directory setup command issues stem from mismatched expectations between the AI's command generation and PowerShell's actual syntax requirements.

Issues Identified

1. Mixed Command Syntax in AI Instructions

Location: core/tools/definitions/runTerminalCommand.ts

Problem: The tool definition contains generic platform detection:

const PLATFORM_INFO = `Choose terminal commands and scripts optimized for ${os.platform()} and ${os.arch()} and shell ${getPreferredShell()}.`;

Issue: The AI is told to "optimize for powershell.exe" but isn't given concrete examples of proper PowerShell syntax vs bash syntax, leading to commands like:

# AI Generated (Incorrect for PowerShell)
cd coding-agent && mkdir agents mcp-servers sdk-implementations

Instead of:

# Correct PowerShell Syntax
cd coding-agent; mkdir agents, mcp-servers, sdk-implementations

2. Misleading Tool Description

Problem: The tool parameter description states:

"The command to run. This will be passed directly into the IDE shell."

Issue: This suggests commands should be written for a generic "IDE shell" rather than explicitly stating they need to be PowerShell-compatible on Windows.

3. Implementation vs Documentation Mismatch

Implementation (Correct): core/tools/implementations/runTerminalCommand.ts

function getShellCommand(command: string): { shell: string; args: string[] } {
  if (process.platform === "win32") {
    // Windows: Use PowerShell
    return {
      shell: "powershell.exe",
      args: ["-NoLogo", "-ExecutionPolicy", "Bypass", "-Command", command],
    };
  }
  // ...
}

Problem: The AI isn't explicitly told that on Windows, commands will be executed via PowerShell with these specific arguments, causing it to generate bash-compatible syntax.

4. Missing PowerShell-Specific Guidance

The system message lacks examples showing critical syntax differences:

Operation Bash Syntax PowerShell Syntax
Multiple Commands command1 && command2 command1; command2
Directory Navigation cd folder && pwd cd folder; pwd
Path Handling ./folder .\folder or folder
Create Multiple Dirs mkdir dir1 dir2 dir3 mkdir dir1, dir2, dir3
Environment Variables $HOME $env:USERPROFILE

Specific Command Failures

Directory Navigation Issue

# What AI Generated (Bash Style)
cd coding-agent && pwd

# What PowerShell Received
cd coding-agent && pwd  # && is not recognized in PowerShell

# What Should Have Been Generated
cd coding-agent; pwd

Directory Creation Issue

# What AI Generated
mkdir agents mcp-servers sdk-implementations

# PowerShell Behavior
# Created all directories in current location instead of relative to cd

# What Should Have Been Generated
New-Item -ItemType Directory -Path agents, mcp-servers, sdk-implementations
# OR
mkdir agents, mcp-servers, sdk-implementations

Path Resolution Issue

# What AI Generated
cd coding-agent
mkdir ./agents ./mcp-servers

# PowerShell Issue
# ./ is not standard PowerShell path syntax

# What Should Have Been Generated
cd coding-agent
mkdir agents, mcp-servers

The Root Problem

The AI generated bash-style commands because:

  1. Generic Platform Info: The tool description is generic rather than prescriptive
  2. No Syntax Examples: System message lacks PowerShell-specific command examples
  3. Cross-Platform Confusion: No explicit warning about syntax differences between shells
  4. Implicit Assumptions: AI assumes POSIX-style shell behavior universally

Recommended Solution

The tool definition should include explicit PowerShell syntax guidance when running on Windows:

const POWERSHELL_GUIDANCE = `
CRITICAL: On Windows, commands are executed via PowerShell. Use PowerShell syntax:
- Multiple commands: use semicolons (;) not && or ||
- Paths: use backslashes or forward slashes, avoid ./
- Create directories: mkdir dir1, dir2, dir3 (comma-separated)
- Variables: $env:VARIABLE not $VARIABLE
`;

This would prevent the mixed syntax issues that caused the directory setup failures.

Based on the analysis, the main file that needs to be edited is:

core/tools/definitions/runTerminalCommand.ts

This file contains the tool definition that generates the system message instructions for the AI. Specifically, these sections need modification:

Current Problematic Code:

const PLATFORM_INFO = `Choose terminal commands and scripts optimized for ${os.platform()} and ${os.arch()} and shell ${getPreferredShell()}.`;

const RUN_COMMAND_NOTES = `The shell is not stateful and will not remember any previous commands.\
      When a command is run in the background ALWAYS suggest using shell commands to stop it; NEVER suggest using Ctrl+C.\
      When suggesting subsequent shell commands ALWAYS format them in shell command blocks.\
      Do NOT perform actions requiring special/admin privileges.\
      ${PLATFORM_INFO}`;

What Needs to Be Added:

  1. Platform-specific syntax guidance
  2. PowerShell-specific examples
  3. Common command translations
  4. Explicit warnings about cross-platform differences

Proposed Changes:

The PLATFORM_INFO and RUN_COMMAND_NOTES constants should be enhanced with PowerShell-specific guidance when os.platform() === "win32".

Secondary File (Optional Enhancement):

core/tools/implementations/runTerminalCommand.ts

Could potentially be enhanced to provide better error messages when commands fail due to syntax issues, but the primary fix needs to happen in the definitions file where the AI instructions are generated.

Why This File?

This is the source of truth for:

  • Tool parameter descriptions
  • System message content that instructs the AI
  • Platform detection logic
  • Examples provided to the AI

By fixing the instructions in this file, the AI will generate proper PowerShell syntax from the start, preventing the directory navigation and command chaining issues you experienced.

Ready for Implementation - Clear Fix Path

This issue has been well-analyzed and PR #7973 attempted a fix but was closed due to lack of testing. Let's get this resolved properly.

Quick Summary:

Windows users can't use basic terminal commands because the AI generates bash syntax (cd folder && mkdir) instead of PowerShell syntax (cd folder; mkdir).

Why PR #7973 was closed:

  • Had the right approach but wasn't tested
  • Couldn't verify the fix worked
  • Changes were in the correct file but needed validation

The Fix (one file, ~10 lines):

In core/tools/definitions/runTerminalCommand.ts, update the PLATFORM_INFO constant:

const PLATFORM_INFO = os.platform() === "win32" 
  ? `Use PowerShell syntax: chain commands with ; not &&, create dirs with mkdir dir1, dir2 (comma-separated), use $env:VAR for environment variables.`
  : `Choose terminal commands optimized for ${getPreferredShell()}.`;

Testing checklist for PR:

  • Build: cd core && npm run build
  • Test command chaining: cd test; ls (should work)
  • Test mkdir: mkdir dir1, dir2, dir3 (should create 3 directories)
  • Test that bash syntax && gets proper PowerShell conversion
  • Include test output/screenshots in PR

For contributors:

  1. This is a straightforward fix - don't overthink it
  2. The implementation (runTerminalCommand.ts) already executes PowerShell correctly
  3. We just need to tell the AI what syntax to use
  4. Most important: Test on Windows and document that you did

This affects every Windows user trying to use terminal commands. A tested, simple fix following the approach from #7973 would be very welcome.

Tip: If you pick this up, mention in the PR that you've tested on Windows with specific examples of commands that now work correctly.