You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] write_file rewrites CRLF files with LF #1964
Nanocoder file tools either fail on files with CRLF line endings or silently replace all line endings with LF.
This regularly sends my model into a long feedback loop, where it tries to figure out the problem and writing all sorts of scripts to fix it.
Below i give examples for write_file and string_replace. I suspect there are more tools affected by the problem, it may be a general problem with file handling?
Environment
OS: Windows 11
Node version: v24.14.1
Nanocoder version: 1.32.0
Provider: OpenAI-compatible API
Model: Qwen3.6-27B
Steps to Reproduce
write_file
Have a file with CRLF line endings
Read the file content
Use write_file to write it back
string_replace
Have a file with CRLF line endings
Use string_replace with exact content of the file
Expected Behavior
write_file: Line endings are preserverd string_replace: The tool succeeds and replaces the file content
Actual Behavior
write_file: Line endings are changed to LF string_replace: The tool fails to match the file content and fails
Additional Context
I have searched existing issues to ensure this is not a duplicate
I can reproduce this issue consistently
This issue occurs with the latest version of nanocoder
@jens-diewald — this looks like it covers the same ground as #1930 (open): [Bug] stringreplace fails multi-line edits on CRLF files and writes mixed line endings.
This has already been reported as issue #1930, which is still open and covers the same underlying defect: the file tools mishandle CRLF line endings, with string_replace failing to match CRLF file content and write_file rewriting the file with LF endings. Your reproduction steps and expected behaviour match that report, so continuing it there keeps the fix in one place.
If this is wrong, reply here saying why and a maintainer will take it from there. Otherwise it will be closed in 14 days.
Automated issue triage. It flags; it never closes on first sight. A maintainer can remove the label to dismiss this.
Huh, sorry about that. I looked into this problem in detail on Monday and the other issue was not there then. But at the time, I didn't get around to actually opening my issue.
The new release, in which the problem still occurs, reminded me of it, and I just did a quick search, which apparently was too quick.
However, the existing issue does only seem to cover string_replace. I do not think that fixes all the issues with CRLF files.
Should i note that in the other issue, or do you want to keep this one open?
I'd like to pick up the write_file half of this. #1961/#1950 only touch string_replace (I checked the changed files), so write_file still turns CRLF files into LF.
Spec:
In source/tools/file-ops/write-file.tsx, when the target file already exists and mostly uses CRLF, and the incoming content has no \r\n, write the content with CRLF. New files and content that already has its own line endings stay as they are.
Add a spec in write-file.spec.tsx with a CRLF fixture, plus a changeset.
Disclosure: the fix and tests will be written with an AI coding assistant, and I'll check them before opening the PR. Could a maintainer assign this to me? I'll wait for that before opening a PR.
Update: I'm not continuing with this one, so I'm releasing my earlier claim. Anyone is welcome to take the write_file part. The finding stands: write_file rewrites a CRLF file with LF (source/tools/file-ops/write-file.tsx, the writeFile(absPath, contentStr, 'utf-8') call has no line-ending handling), and the open string_replace PRs don't touch it. No PR from me exists.
Hi @addyCooks, I'd like to take the write_file part of this, since #1961 only covers string_replace. Plan: when the target file exists and mostly uses CRLF, and the new content has no \r\n, write it with CRLF. New files and content with its own line endings stay as they are. It would reuse the line-ending helper from #1961 and add a CRLF spec in write-file.spec.tsx. Could you assign it to me? I'll wait for that before opening a PR.
Thanks @jens-diewald, confirmed on main. Both halves reproduce. string_replace is tracked in #1930 (fix in #1961), but write_file isn't, so I'm keeping this open for the write_file half and removing the duplicate flag.
@Mahdi-Hasan, assigned to you. Please reuse the line-ending helper from #1961 and add a CRLF test.
Activity
github-actions commentedon Nov 5, 2026
Issue triage: possible duplicate of #1930
@jens-diewald — this looks like it covers the same ground as #1930 (open): [Bug] stringreplace fails multi-line edits on CRLF files and writes mixed line endings.
This has already been reported as issue #1930, which is still open and covers the same underlying defect: the file tools mishandle CRLF line endings, with string_replace failing to match CRLF file content and write_file rewriting the file with LF endings. Your reproduction steps and expected behaviour match that report, so continuing it there keeps the fix in one place.
If this is wrong, reply here saying why and a maintainer will take it from there. Otherwise it will be closed in 14 days.
Automated issue triage. It flags; it never closes on first sight. A maintainer can remove the label to dismiss this.
jens-diewald commentedon Nov 5, 2026
Huh, sorry about that. I looked into this problem in detail on Monday and the other issue was not there then. But at the time, I didn't get around to actually opening my issue.
The new release, in which the problem still occurs, reminded me of it, and I just did a quick search, which apparently was too quick.
However, the existing issue does only seem to cover string_replace. I do not think that fixes all the issues with CRLF files.
Should i note that in the other issue, or do you want to keep this one open?
RealBhupesh commentedon Nov 6, 2026
I'd like to pick up the
write_filehalf of this. #1961/#1950 only touchstring_replace(I checked the changed files), sowrite_filestill turns CRLF files into LF.Spec:
source/tools/file-ops/write-file.tsx, when the target file already exists and mostly uses CRLF, and the incoming content has no\r\n, write the content with CRLF. New files and content that already has its own line endings stay as they are.write-file.spec.tsxwith a CRLF fixture, plus a changeset.Disclosure: the fix and tests will be written with an AI coding assistant, and I'll check them before opening the PR. Could a maintainer assign this to me? I'll wait for that before opening a PR.
RealBhupesh commentedon Nov 6, 2026
Update: I'm not continuing with this one, so I'm releasing my earlier claim. Anyone is welcome to take the
write_filepart. The finding stands:write_filerewrites a CRLF file with LF (source/tools/file-ops/write-file.tsx, thewriteFile(absPath, contentStr, 'utf-8')call has no line-ending handling), and the openstring_replacePRs don't touch it. No PR from me exists.Mahdi-Hasan commentedon Nov 6, 2026
Hi @addyCooks, I'd like to take the
write_filepart of this, since #1961 only coversstring_replace. Plan: when the target file exists and mostly uses CRLF, and the new content has no\r\n, write it with CRLF. New files and content with its own line endings stay as they are. It would reuse the line-ending helper from #1961 and add a CRLF spec inwrite-file.spec.tsx. Could you assign it to me? I'll wait for that before opening a PR.[-][Bug] File Tools fail with Windows Line Endings (CRLF)[/-][+][Bug] write_file rewrites CRLF files with LF[/+]addyCooks commentedon Nov 7, 2026
Thanks @jens-diewald, confirmed on main. Both halves reproduce. string_replace is tracked in #1930 (fix in #1961), but write_file isn't, so I'm keeping this open for the write_file half and removing the duplicate flag.
@Mahdi-Hasan, assigned to you. Please reuse the line-ending helper from #1961 and add a CRLF test.
fix(tools): keep CRLF line endings when write_file overwrites a CRLF …
fix(tools): keep CRLF line endings when write_file overwrites a CRLF …