Windows apply_patch fails #7423

Open
opened 2026-02-16 18:07:07 -05:00 by yindo · 9 comments
Owner

Originally created by @Happy-DJ on GitHub (Jan 24, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Title: [BUG] apply_patch fails on Windows with Git Bash - path truncation

Environment:

  • OpenCode version: 1.1.34
  • OS: Windows 10/11
  • Shell: Git Bash
  • Client: Desktop

Description:
When using apply_patch tool, the file path gets truncated.

Error:

Plugins

No response

OpenCode version

1.1.34

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

windows11

Terminal

Desktop、powerShell

Image

正确路径为 D:\Root\twinUpgrade\simulationPython\frontend\src\views\ScenarioView.vue

Originally created by @Happy-DJ on GitHub (Jan 24, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description **Title**: [BUG] apply_patch fails on Windows with Git Bash - path truncation **Environment**: - OpenCode version: 1.1.34 - OS: Windows 10/11 - Shell: Git Bash - Client: Desktop **Description**: When using `apply_patch` tool, the file path gets truncated. **Error**: ### Plugins _No response_ ### OpenCode version 1.1.34 ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System windows11 ### Terminal Desktop、powerShell ![Image](https://github.com/user-attachments/assets/f3fb9aea-5d9c-4cb7-b262-9fab0a97a513) 正确路径为 D:\Root\twinUpgrade\simulationPython\frontend\src\views\ScenarioView.vue
yindo added the windowsbugweb labels 2026-02-16 18:07:07 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 24, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9754: apply_patch does not trigger formatter (Windows-specific issue with apply_patch)
  • #10121: Codex in experimental plan mode create the plan file twice (apply_patch creates files twice on Windows)
  • #8567: Enter_Plan tool cannot edit windows url pathed files (path handling issues in plan mode)
  • #9804: File paths with special characters (#) or non-ASCII characters fail to load (path truncation issues)
  • #7279: Bug: permission pathing crossplatform (path separator issues on Windows)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 24, 2026): This issue might be a duplicate of existing issues. Please check: - #9754: apply_patch does not trigger formatter (Windows-specific issue with apply_patch) - #10121: Codex in experimental plan mode create the plan file twice (apply_patch creates files twice on Windows) - #8567: Enter_Plan tool cannot edit windows url pathed files (path handling issues in plan mode) - #9804: File paths with special characters (#) or non-ASCII characters fail to load (path truncation issues) - #7279: Bug: permission pathing crossplatform (path separator issues on Windows) Feel free to ignore if none of these address your specific case.
Author
Owner

@handsomepwy commented on GitHub (Jan 25, 2026):

Yeah I also have this exact issue where the path will be truncated and end with a capitalized D. I'm on 1.1.35 win11 GUI, GPT-5 Nano.

@handsomepwy commented on GitHub (Jan 25, 2026): Yeah I also have this exact issue where the path will be truncated and end with a capitalized D. I'm on 1.1.35 win11 GUI, GPT-5 Nano.
Author
Owner

@ranqn commented on GitHub (Jan 25, 2026):

It fails on using absolute path as well, I have to instruct it to always use relative paths for apply_patch.

@ranqn commented on GitHub (Jan 25, 2026): It fails on using absolute path as well, I have to instruct it to always use relative paths for `apply_patch`.
Author
Owner

@xujinhui2015 commented on GitHub (Jan 25, 2026):

+1

@xujinhui2015 commented on GitHub (Jan 25, 2026): +1
Author
Owner

@pschiel commented on GitHub (Jan 28, 2026):

Also addressed in https://github.com/anomalyco/opencode/pull/6763/changes#diff-f705e80681760189e03a90b848f667293969d46b6ba1cf89f477f8d3eaa31717 along with a big bunch of other Windows bugs.

@pschiel commented on GitHub (Jan 28, 2026): Also addressed in https://github.com/anomalyco/opencode/pull/6763/changes#diff-f705e80681760189e03a90b848f667293969d46b6ba1cf89f477f8d3eaa31717 along with a big bunch of other Windows bugs.
Author
Owner

@ham-zax commented on GitHub (Feb 3, 2026):

+1

@ham-zax commented on GitHub (Feb 3, 2026): +1
Author
Owner

@machinekoder commented on GitHub (Feb 14, 2026):

The same problem appears here as well with Opus 4.6, Codex 5.3 and other models.

@machinekoder commented on GitHub (Feb 14, 2026): The same problem appears here as well with Opus 4.6, Codex 5.3 and other models.
Author
Owner

@machinekoder commented on GitHub (Feb 14, 2026):

Root cause: parsePatchHeader in packages/opencode/src/patch/index.ts uses line.split(':', 2) to extract file paths from patch headers. On Windows, the drive letter colon (e.g. D:) is the first colon found, so split(':', 2) returns ['*** Update File', ' D'], truncating the path to just the drive letter. This then resolves to e.g. <project_dir>\D.

Fix is straightforward — use .slice() after the known prefix length instead of splitting on :. PRs: #10808, #13582.

@machinekoder commented on GitHub (Feb 14, 2026): Root cause: `parsePatchHeader` in `packages/opencode/src/patch/index.ts` uses `line.split(':', 2)` to extract file paths from patch headers. On Windows, the drive letter colon (e.g. `D:`) is the first colon found, so `split(':', 2)` returns `['*** Update File', ' D']`, truncating the path to just the drive letter. This then resolves to e.g. `<project_dir>\D`. Fix is straightforward — use `.slice()` after the known prefix length instead of splitting on `:`. PRs: #10808, #13582.
Author
Owner

@machinekoder commented on GitHub (Feb 14, 2026):

It fails on using absolute path as well, I have to instruct it to always use relative paths for apply_patch.

An alternative workaround might be (not tested) to state using relative paths for tool use in the AGENTS.md or to solve in OpenCode, make it part of the tool description or system prompt. But the fix is so simple that it probably would do more harm than help to do this.

@machinekoder commented on GitHub (Feb 14, 2026): > It fails on using absolute path as well, I have to instruct it to always use relative paths for `apply_patch`. An alternative workaround might be (not tested) to state using relative paths for tool use in the AGENTS.md or to solve in OpenCode, make it part of the tool description or system prompt. But the fix is so simple that it probably would do more harm than help to do this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7423