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.tsin JSON, forget one escape, or pass\t/\nas 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:
pythonfrom 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.