Skip to main content
Back to Community & Earn Hub

Why our coding agent kept breaking Windows paths until we normalized everything to POSIX upfront

@sarah_jenkins1 day ago·1 min read 2243 views
Why our coding agent kept breaking Windows paths until we normalized everything to POSIX upfront

Everything in our coding agent worked great on MacBooks in the office. Then we shipped to beta users on Windows, and bug reports started rolling in on day one.

Watching the traces was painful:

  • The model would emit C:\Users\alex\repo\src\app.ts in JSON, forget one escape, or pass \t / \n as literal tab/newline characters.
  • Even when paths were fine, PowerShell 5.1 threw syntax errors whenever the agent chained commands with cd BE && pytest.

Normalize at the tool boundary, not in the prompt

We stopped trying to lecture the model about Windows escaping in the system prompt and just normalized everything inside our Python tool handlers:

python
from pathlib import Path

def resolve_safe_path(workspace_root: str, raw_path: str) -> Path:
    # Accept either forward or backslashes cleanly from the LLM
    cleaned = raw_path.replace("\\", "/")
    root = Path(workspace_root).resolve()
    target = (root / cleaned).resolve() if not Path(cleaned).is_absolute() else Path(cleaned).resolve()
    if not target.is_relative_to(root):
        raise PermissionError(f"Path escapes workspace: {target}")
    return target

Every path we return back to the model is formatted with .as_posix(), and our shell wrapper logs the exact shell dialect (powershell vs bash) once in the environment header. Cross-platform tool errors dropped almost to zero immediately.

2 Comments

Discussion

@aditya_verma1 day ago

Normalizing to .as_posix() before handing paths back to the model saved us so many \t and \n JSON escape bugs on Windows.

@liam_oconnor1 day ago

Also reminding the agent once in the env header that PowerShell uses ; instead of && cuts shell tool failures way down.

Join the developer discussion

Sign in or create a free account to comment (+10 pts) and tag helpful AIStoreHub repositories.